diff --git a/tests/time_tracker_api/time_entries/time_entries_namespace_test.py b/tests/time_tracker_api/time_entries/time_entries_namespace_test.py index 30cd2fce..0d5c19ef 100644 --- a/tests/time_tracker_api/time_entries/time_entries_namespace_test.py +++ b/tests/time_tracker_api/time_entries/time_entries_namespace_test.py @@ -483,7 +483,6 @@ def test_get_running_should_call_find_running( 'find_running', return_value=fake_time_entry, ) - time_entries_dao.stop_time_entry_if_was_left_running = Mock() response = client.get( "/time-entries/running", headers=valid_header, follow_redirects=True @@ -730,16 +729,14 @@ def test_summary_is_called_with_date_range_from_worked_time_module( def test_paginated_fails_with_no_params( - client: FlaskClient, - valid_header: dict, + client: FlaskClient, valid_header: dict, ): response = client.get('/time-entries/paginated', headers=valid_header) assert HTTPStatus.BAD_REQUEST == response.status_code def test_paginated_succeeds_with_valid_params( - client: FlaskClient, - valid_header: dict, + client: FlaskClient, valid_header: dict, ): response = client.get( '/time-entries/paginated?start_date=2020-09-10T00:00:00-05:00&end_date=2020-09-10T23:59:59-05:00&timezone_offset=300&start=0&length=5', @@ -749,8 +746,7 @@ def test_paginated_succeeds_with_valid_params( def test_paginated_response_contains_expected_props( - client: FlaskClient, - valid_header: dict, + client: FlaskClient, valid_header: dict, ): response = client.get( '/time-entries/paginated?start_date=2020-09-10T00:00:00-05:00&end_date=2020-09-10T23:59:59-05:00&timezone_offset=300&start=0&length=5', diff --git a/time_tracker_api/time_entries/time_entries_model.py b/time_tracker_api/time_entries/time_entries_model.py index 636225f6..5abb71d1 100644 --- a/time_tracker_api/time_entries/time_entries_model.py +++ b/time_tracker_api/time_entries/time_entries_model.py @@ -2,7 +2,6 @@ from dataclasses import dataclass, field from typing import List, Callable from azure.cosmos import PartitionKey -from azure.cosmos.exceptions import CosmosResourceNotFoundError from flask_restplus import abort from flask_restplus._http import HTTPStatus @@ -30,7 +29,6 @@ str_to_datetime, get_current_year, get_current_month, - get_current_day, get_date_range_of_month, current_datetime_str, ) @@ -92,22 +90,6 @@ def __init__(self, data): # pragma: no cover def running(self): return self.end_date is None - @property - def was_left_running(self) -> bool: - start_date = str_to_datetime(self.start_date) - return ( - get_current_day() > start_date.day - or get_current_month() > start_date.month - or get_current_year() > start_date.year - ) - - @property - def start_date_at_midnight(self) -> str: - start_date = str_to_datetime(self.start_date) - return datetime_str( - start_date.replace(hour=23, minute=59, second=59, microsecond=0) - ) - @property def elapsed_time(self) -> timedelta: start_datetime = str_to_datetime(self.start_date) @@ -416,21 +398,6 @@ def check_time_entry_is_not_started(self, data): "The specified time entry is already running", ) - def stop_time_entry_if_was_left_running( - self, time_entry: TimeEntryCosmosDBModel - ): - - if time_entry.was_left_running: - end_date = time_entry.start_date_at_midnight - event_ctx = self.create_event_context( - "update", "Stop time-entry that was left running" - ) - - self.repository.partial_update( - time_entry.id, {'end_date': end_date}, event_ctx - ) - raise CosmosResourceNotFoundError() - def build_custom_query(self, is_admin: bool, conditions: dict = None): custom_query = [] if "user_id" in conditions: @@ -569,12 +536,6 @@ def find_running(self): time_entry = self.repository.find_running( event_ctx.tenant_id, event_ctx.user_id ) - # TODO: we need to make this work using the users time zone - # This is disabled as part of https://github.com/ioet/time-tracker-backend/issues/160 - # Remove all these comments after implementing - # https://github.com/ioet/time-tracker-backend/issues/159 - # https://github.com/ioet/time-tracker-backend/issues/162 - # self.stop_time_entry_if_was_left_running(time_entry) return time_entry def get_worked_time(self, args: dict):