Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: datetime.now() to datetime.utcnow() #556

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/api/dao/mentorship_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def create_mentorship_relation(self, user_id: int, data: Dict[str, str]):
except ValueError:
return messages.INVALID_END_DATE, HTTPStatus.BAD_REQUEST

now_datetime = datetime.now()
now_datetime = datetime.utcnow()
if end_date_datetime < now_datetime:
return messages.END_TIME_BEFORE_PRESENT, HTTPStatus.BAD_REQUEST

Expand Down Expand Up @@ -110,7 +110,7 @@ def create_mentorship_relation(self, user_id: int, data: Dict[str, str]):
action_user_id=action_user_id,
mentor_user=mentor_user,
mentee_user=mentee_user,
creation_date=datetime.now().timestamp(),
creation_date=datetime.utcnow().timestamp(),
end_date=end_date_timestamp,
state=MentorshipRelationState.PENDING,
notes=notes,
Expand Down Expand Up @@ -361,7 +361,7 @@ def list_past_mentorship_relations(user_id: int):
"""

user = UserModel.find_by_id(user_id)
now_timestamp = datetime.now().timestamp()
now_timestamp = datetime.utcnow().timestamp()
past_relations = list(
filter(
lambda relation: relation.end_date < now_timestamp,
Expand Down Expand Up @@ -409,7 +409,7 @@ def list_pending_mentorship_relations(user_id: int):
"""

user = UserModel.find_by_id(user_id)
now_timestamp = datetime.now().timestamp()
now_timestamp = datetime.utcnow().timestamp()
pending_requests = []
all_relations = user.mentor_relations + user.mentee_relations

Expand Down
6 changes: 4 additions & 2 deletions app/api/dao/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create_task(user_id: int, mentorship_relation_id: int, data: Dict[str, str])
HTTPStatus.FORBIDDEN,
)

now_timestamp = datetime.now().timestamp()
now_timestamp = datetime.utcnow().timestamp()
relation.tasks_list.add_task(description=description, created_at=now_timestamp)
relation.tasks_list.save_to_db()

Expand Down Expand Up @@ -157,7 +157,9 @@ def complete_task(user_id: int, mentorship_relation_id: int, task_id: int):
return messages.TASK_WAS_ALREADY_ACHIEVED, HTTPStatus.FORBIDDEN
else:
relation.tasks_list.update_task(
task_id=task_id, is_done=True, completed_at=datetime.now().timestamp()
task_id=task_id,
is_done=True,
completed_at=datetime.utcnow().timestamp(),
)

return messages.TASK_WAS_ACHIEVED_SUCCESSFULLY, HTTPStatus.OK
2 changes: 1 addition & 1 deletion app/api/dao/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def confirm_registration(token: str):
return messages.ACCOUNT_ALREADY_CONFIRMED, HTTPStatus.OK
else:
user.is_email_verified = True
user.email_verification_date = datetime.now()
user.email_verification_date = datetime.utcnow()
user.save_to_db()
return messages.ACCOUNT_ALREADY_CONFIRMED_AND_THANKS, HTTPStatus.OK

Expand Down
4 changes: 2 additions & 2 deletions app/database/models/task_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, user_id, task_id, relation_id, comment):
self.comment = comment

# default fields
self.creation_date = datetime.now().timestamp()
self.creation_date = datetime.utcnow().timestamp()

def json(self):
"""Returns information of task comment as a JSON object."""
Expand Down Expand Up @@ -89,7 +89,7 @@ def modify_comment(self, comment):
comment: New comment.
"""
self.comment = comment
self.modification_date = datetime.now().timestamp()
self.modification_date = datetime.utcnow().timestamp()

@classmethod
def is_empty(cls):
Expand Down
2 changes: 1 addition & 1 deletion app/schedulers/complete_mentorship_cron_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def complete_overdue_mentorship_relations_job():
MentorshipRelationModel.query.all(),
)

current_date_timestamp = datetime.now().timestamp()
current_date_timestamp = datetime.utcnow().timestamp()

for relation in all_relations:
relation.state = MentorshipRelationState.COMPLETED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def setUp(self):

self.notes_example = "description of a good mentorship relation"

self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.past_end_date_example = self.now_datetime - timedelta(weeks=5)
self.future_end_date_example = self.now_datetime + timedelta(weeks=5)

Expand Down
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_api_accept_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setUp(self):

self.notes_example = "description of a good mentorship relation"

self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

# create new mentorship relation
Expand Down
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_api_cancel_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):

self.notes_example = "description of a good mentorship relation"

self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

# create new mentorship relation
Expand Down
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_api_delete_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setUp(self):
super().setUp()

self.notes_example = "description of a good mentorship relation"
self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

# create new mentorship relation
Expand Down
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_api_list_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
super().setUp()

self.notes_example = "description of a good mentorship relation"
self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.past_end_date_example = self.now_datetime - timedelta(weeks=5)
self.future_end_date_example = self.now_datetime + timedelta(weeks=5)

Expand Down
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_api_reject_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setUp(self):
super().setUp()

self.notes_example = "description of a good mentorship relation"
self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

# create new mentorship relation
Expand Down
8 changes: 4 additions & 4 deletions tests/mentorship_relation/test_api_send_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_created_error_code_for_send_request(self):
test_payload = {
"mentor_id": self.first_user.id,
"mentee_id": self.second_user.id,
"end_date": int((datetime.now() + timedelta(days=40)).timestamp()),
"end_date": int((datetime.utcnow() + timedelta(days=40)).timestamp()),
"notes": "some notes",
}
actual_response = self.client.post(
Expand All @@ -40,7 +40,7 @@ def test_fail_send_request_bad_mentee_id(self):
test_payload = {
"mentor_id": self.first_user.id,
"mentee_id": 1234,
"end_date": int((datetime.now() + timedelta(days=40)).timestamp()),
"end_date": int((datetime.utcnow() + timedelta(days=40)).timestamp()),
"notes": "some notes",
}
actual_response = self.client.post(
Expand All @@ -58,7 +58,7 @@ def test_fail_send_request_bad_mentor_id(self):
test_payload = {
"mentor_id": 1234,
"mentee_id": self.first_user.id,
"end_date": int((datetime.now() + timedelta(days=40)).timestamp()),
"end_date": int((datetime.utcnow() + timedelta(days=40)).timestamp()),
"notes": "some notes",
}
actual_response = self.client.post(
Expand All @@ -77,7 +77,7 @@ def test_fail_send_request_bad_user_id(self):
test_payload = {
"mentor_id": self.second_user.id,
"mentee_id": 4321,
"end_date": int((datetime.now() + timedelta(days=40)).timestamp()),
"end_date": int((datetime.utcnow() + timedelta(days=40)).timestamp()),
"notes": "some notes",
}
actual_response = self.client.post(
Expand Down
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_dao_accept_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
super().setUp()

self.notes_example = "description of a good mentorship relation"
self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

# create new mentorship relation
Expand Down
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_dao_cancel_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setUp(self):
super().setUp()

self.notes_example = "description of a good mentorship relation"
self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

# create new mentorship relation
Expand Down
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_dao_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setUp(self):

self.notes_example = "description of a good mentorship relation"

self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

def test_dao_create_mentorship_relation_with_good_args_mentor_is_sender(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_dao_delete_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def setUp(self):

self.notes_example = "description of a good mentorship relation"

self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

db.session.add(self.first_user)
Expand Down
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_dao_list_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self):
super().setUp()

self.notes_example = "description of a good mentorship relation"
self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.past_end_date_example = self.now_datetime - timedelta(weeks=5)
self.future_end_date_example = self.now_datetime + timedelta(weeks=5)

Expand Down
2 changes: 1 addition & 1 deletion tests/mentorship_relation/test_dao_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def setUp(self):
super().setUp()

self.notes_example = "description of a good mentorship relation"
self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

# create new mentorship relation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setUp(self):
super().setUp()

self.notes_example = "description of a good mentorship relation"
self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

# create new mentorship relation
Expand Down
4 changes: 2 additions & 2 deletions tests/mentorship_relation/test_database_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ def setUp(self):

self.notes_example = "description of a good mentorship relation"

now_datetime = datetime.now()
now_datetime = datetime.utcnow()
self.start_date_example = datetime(
year=now_datetime.year + 1, month=3, day=1
).timestamp()
self.end_date_example = datetime(
year=now_datetime.year + 1, month=5, day=1
).timestamp()
self.now_datetime = datetime.now().timestamp()
self.now_datetime = datetime.utcnow().timestamp()

db.session.add(self.first_user)
db.session.add(self.second_user)
Expand Down
2 changes: 1 addition & 1 deletion tests/tasks/tasks_base_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def setUp(self):

self.notes_example = "description of a good mentorship relation"

self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

self.tasks_list_1 = TasksListModel()
Expand Down
2 changes: 1 addition & 1 deletion tests/tasks/test_tasks_list_database_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setUp(self):
db.session.add(self.tasks_list_1)
db.session.commit()

self.now_timestamp = datetime.now().timestamp()
self.now_timestamp = datetime.utcnow().timestamp()
self.test_description_1 = "test description number one"
self.test_description_2 = "test description number two"

Expand Down
2 changes: 1 addition & 1 deletion tests/user_journey/test_happy_path_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_happy_path_1(self):
request_body = {
"mentor_id": self.mentor.id,
"mentee_id": self.mentee.id,
"end_date": int((datetime.now() + timedelta(days=40)).timestamp()),
"end_date": int((datetime.utcnow() + timedelta(days=40)).timestamp()),
"notes": "some notes",
}
send_request_response = self.client.post(
Expand Down
14 changes: 7 additions & 7 deletions tests/users/test_api_home_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_relations_invalid_id(self):
self.assertEqual(messages.USER_NOT_FOUND, json.loads(actual_response.data))

def test_pending_requests_auth(self):
start_date = datetime.now()
start_date = datetime.utcnow()
end_date = start_date + timedelta(weeks=4)
start_date = start_date.timestamp()
end_date = end_date.timestamp()
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_pending_requests_auth(self):
self.assertEqual(expected_response, json.loads(actual_response.data))

def test_accepted_requests_auth(self):
start_date = datetime.now()
start_date = datetime.utcnow()
end_date = start_date + timedelta(weeks=4)
start_date = start_date.timestamp()
end_date = end_date.timestamp()
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_accepted_requests_auth(self):
self.assertEqual(expected_response, json.loads(actual_response.data))

def test_rejected_requests(self):
start_date = datetime.now()
start_date = datetime.utcnow()
end_date = start_date + timedelta(weeks=4)
start_date = start_date.timestamp()
end_date = end_date.timestamp()
Expand Down Expand Up @@ -151,7 +151,7 @@ def test_rejected_requests(self):
self.assertEqual(expected_response, json.loads(actual_response.data))

def test_completed_relations(self):
start_date = datetime.now()
start_date = datetime.utcnow()
end_date = start_date + timedelta(weeks=4)
start_date = start_date.timestamp()
end_date = end_date.timestamp()
Expand Down Expand Up @@ -187,7 +187,7 @@ def test_completed_relations(self):
self.assertEqual(expected_response, json.loads(actual_response.data))

def test_cancelled_relations(self):
start_date = datetime.now()
start_date = datetime.utcnow()
end_date = start_date + timedelta(weeks=4)
start_date = start_date.timestamp()
end_date = end_date.timestamp()
Expand Down Expand Up @@ -222,13 +222,13 @@ def test_cancelled_relations(self):
self.assertEqual(expected_response, json.loads(actual_response.data))

def test_achievements(self):
start_date = datetime.now()
start_date = datetime.utcnow()
end_date = start_date + timedelta(weeks=4)
start_date = start_date.timestamp()
end_date = end_date.timestamp()

tasks_list = TasksListModel()
task_created_time = datetime.now().timestamp()
task_created_time = datetime.utcnow().timestamp()
task_completed_time = task_created_time + 100
tasks_list.add_task(
description="Test task",
Expand Down
4 changes: 2 additions & 2 deletions tests/users/test_api_list_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def create_relationship(self):
self.other_user.id,
self.other_user,
self.verified_user,
datetime.now().timestamp(),
(datetime.now() + timedelta(weeks=5)).timestamp(),
datetime.utcnow().timestamp(),
(datetime.utcnow() + timedelta(weeks=5)).timestamp(),
MentorshipRelationState.ACCEPTED,
"notes",
TasksListModel(),
Expand Down
4 changes: 2 additions & 2 deletions tests/users/test_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def test_get_achievements(self):
db.session.add(mentee)
db.session.commit()

start_date = datetime.datetime.now()
start_date = datetime.datetime.utcnow()
end_date = start_date + datetime.timedelta(weeks=4)

tasks_list = TasksListModel()
Expand Down Expand Up @@ -227,7 +227,7 @@ def test_get_user_statistics(self):
db.session.add(mentee)
db.session.commit()

start_date = datetime.datetime.now()
start_date = datetime.datetime.utcnow()
end_date = start_date + datetime.timedelta(weeks=4)

tasks_list = TasksListModel()
Expand Down
2 changes: 1 addition & 1 deletion tests/users/test_dao_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def setUp(self):

self.notes_example = "description of a good mentorship relation"

self.now_datetime = datetime.now()
self.now_datetime = datetime.utcnow()
self.end_date_example = self.now_datetime + timedelta(weeks=5)

self.tasks_list_1 = TasksListModel()
Expand Down