diff --git a/app/api/dao/mentorship_relation.py b/app/api/dao/mentorship_relation.py index 5587dce31..0be70cbd8 100644 --- a/app/api/dao/mentorship_relation.py +++ b/app/api/dao/mentorship_relation.py @@ -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 @@ -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, @@ -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, @@ -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 diff --git a/app/api/dao/task.py b/app/api/dao/task.py index e5833a062..d141355a8 100644 --- a/app/api/dao/task.py +++ b/app/api/dao/task.py @@ -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() @@ -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 diff --git a/app/api/dao/user.py b/app/api/dao/user.py index fe387e01a..c38343917 100644 --- a/app/api/dao/user.py +++ b/app/api/dao/user.py @@ -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 diff --git a/app/database/models/task_comment.py b/app/database/models/task_comment.py index d2f532496..3dfac23c7 100644 --- a/app/database/models/task_comment.py +++ b/app/database/models/task_comment.py @@ -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.""" @@ -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): diff --git a/app/schedulers/complete_mentorship_cron_job.py b/app/schedulers/complete_mentorship_cron_job.py index d4788d57b..114e959c3 100644 --- a/app/schedulers/complete_mentorship_cron_job.py +++ b/app/schedulers/complete_mentorship_cron_job.py @@ -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 diff --git a/tests/cron_job_functions/test_mentorship_completion_cron.py b/tests/cron_job_functions/test_mentorship_completion_cron.py index 1337868a9..f5366a3e7 100644 --- a/tests/cron_job_functions/test_mentorship_completion_cron.py +++ b/tests/cron_job_functions/test_mentorship_completion_cron.py @@ -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) diff --git a/tests/mentorship_relation/test_api_accept_request.py b/tests/mentorship_relation/test_api_accept_request.py index 9df623a42..c1351bce5 100644 --- a/tests/mentorship_relation/test_api_accept_request.py +++ b/tests/mentorship_relation/test_api_accept_request.py @@ -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 diff --git a/tests/mentorship_relation/test_api_cancel_relation.py b/tests/mentorship_relation/test_api_cancel_relation.py index 07241abec..d4879cf53 100644 --- a/tests/mentorship_relation/test_api_cancel_relation.py +++ b/tests/mentorship_relation/test_api_cancel_relation.py @@ -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 diff --git a/tests/mentorship_relation/test_api_delete_request.py b/tests/mentorship_relation/test_api_delete_request.py index 45c37a98f..ac5cbe800 100644 --- a/tests/mentorship_relation/test_api_delete_request.py +++ b/tests/mentorship_relation/test_api_delete_request.py @@ -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 diff --git a/tests/mentorship_relation/test_api_list_relations.py b/tests/mentorship_relation/test_api_list_relations.py index 022fd75ee..9305439f0 100644 --- a/tests/mentorship_relation/test_api_list_relations.py +++ b/tests/mentorship_relation/test_api_list_relations.py @@ -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) diff --git a/tests/mentorship_relation/test_api_reject_request.py b/tests/mentorship_relation/test_api_reject_request.py index 09f364860..89d62ce14 100644 --- a/tests/mentorship_relation/test_api_reject_request.py +++ b/tests/mentorship_relation/test_api_reject_request.py @@ -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 diff --git a/tests/mentorship_relation/test_api_send_request.py b/tests/mentorship_relation/test_api_send_request.py index d767894b2..cda0268ac 100644 --- a/tests/mentorship_relation/test_api_send_request.py +++ b/tests/mentorship_relation/test_api_send_request.py @@ -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( @@ -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( @@ -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( @@ -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( diff --git a/tests/mentorship_relation/test_dao_accept_request.py b/tests/mentorship_relation/test_dao_accept_request.py index a474c11bf..6b434b3e8 100644 --- a/tests/mentorship_relation/test_dao_accept_request.py +++ b/tests/mentorship_relation/test_dao_accept_request.py @@ -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 diff --git a/tests/mentorship_relation/test_dao_cancel_relation.py b/tests/mentorship_relation/test_dao_cancel_relation.py index 42f2cd7c0..6f6458ce4 100644 --- a/tests/mentorship_relation/test_dao_cancel_relation.py +++ b/tests/mentorship_relation/test_dao_cancel_relation.py @@ -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 diff --git a/tests/mentorship_relation/test_dao_creation.py b/tests/mentorship_relation/test_dao_creation.py index 2fd669bbb..bd665edc8 100644 --- a/tests/mentorship_relation/test_dao_creation.py +++ b/tests/mentorship_relation/test_dao_creation.py @@ -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): diff --git a/tests/mentorship_relation/test_dao_delete_request.py b/tests/mentorship_relation/test_dao_delete_request.py index 14299d66d..c7321a695 100644 --- a/tests/mentorship_relation/test_dao_delete_request.py +++ b/tests/mentorship_relation/test_dao_delete_request.py @@ -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) diff --git a/tests/mentorship_relation/test_dao_list_relations.py b/tests/mentorship_relation/test_dao_list_relations.py index f67c9606d..d21745333 100644 --- a/tests/mentorship_relation/test_dao_list_relations.py +++ b/tests/mentorship_relation/test_dao_list_relations.py @@ -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) diff --git a/tests/mentorship_relation/test_dao_listing.py b/tests/mentorship_relation/test_dao_listing.py index 09fd16543..32046d696 100644 --- a/tests/mentorship_relation/test_dao_listing.py +++ b/tests/mentorship_relation/test_dao_listing.py @@ -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 diff --git a/tests/mentorship_relation/test_dao_reject_mentorship_request.py b/tests/mentorship_relation/test_dao_reject_mentorship_request.py index 37b131a08..5a9480098 100644 --- a/tests/mentorship_relation/test_dao_reject_mentorship_request.py +++ b/tests/mentorship_relation/test_dao_reject_mentorship_request.py @@ -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 diff --git a/tests/mentorship_relation/test_database_model.py b/tests/mentorship_relation/test_database_model.py index fb0196927..654d874ed 100644 --- a/tests/mentorship_relation/test_database_model.py +++ b/tests/mentorship_relation/test_database_model.py @@ -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) diff --git a/tests/tasks/tasks_base_setup.py b/tests/tasks/tasks_base_setup.py index e25ed5775..3ea84d128 100644 --- a/tests/tasks/tasks_base_setup.py +++ b/tests/tasks/tasks_base_setup.py @@ -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() diff --git a/tests/tasks/test_tasks_list_database_model.py b/tests/tasks/test_tasks_list_database_model.py index 408f11ffe..27a2500d3 100644 --- a/tests/tasks/test_tasks_list_database_model.py +++ b/tests/tasks/test_tasks_list_database_model.py @@ -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" diff --git a/tests/user_journey/test_happy_path_1.py b/tests/user_journey/test_happy_path_1.py index 7c6e08d43..cbcc7fcdc 100644 --- a/tests/user_journey/test_happy_path_1.py +++ b/tests/user_journey/test_happy_path_1.py @@ -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( diff --git a/tests/users/test_api_home_statistics.py b/tests/users/test_api_home_statistics.py index 3983a0b97..dbae59c89 100644 --- a/tests/users/test_api_home_statistics.py +++ b/tests/users/test_api_home_statistics.py @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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", diff --git a/tests/users/test_api_list_users.py b/tests/users/test_api_list_users.py index e168a736a..7c49d08c7 100644 --- a/tests/users/test_api_list_users.py +++ b/tests/users/test_api_list_users.py @@ -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(), diff --git a/tests/users/test_dao.py b/tests/users/test_dao.py index 05e6542b2..c6595fe11 100644 --- a/tests/users/test_dao.py +++ b/tests/users/test_dao.py @@ -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() @@ -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() diff --git a/tests/users/test_dao_dashboard.py b/tests/users/test_dao_dashboard.py index fb4a28afc..6e2982497 100644 --- a/tests/users/test_dao_dashboard.py +++ b/tests/users/test_dao_dashboard.py @@ -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()