def test_sync_single_toggl_already_inserted_in_jira(self): jira = JiraHelper(None, None, None, False) jira.get = Mock() jira.put = Mock() jira.update = Mock() toggl = TogglHelper("url", None) toggl.get = Mock() toggl.get.return_value = [ TogglEntry( None, 3600, "2016-01-01T01:01:01", 17, "SLUG-987 hard work", self.jira_config, ) ] jira.get.return_value = [ JiraTimeEntry( 222, "2016-05-01T04:02:22", "john doe", 3600, "2016-01-01T01:01:01", "SLUG-987", "SLUG-987 hard work [toggl#17]", ) ] s = Synchronizer(MagicMock(), jira, toggl, None, raise_errors=True) s.start(1) jira.update.assert_not_called() jira.put.assert_not_called()
def test_sync_single_toggl_no_jira(self): config = MagicMock() jira = JiraHelper(None, None, None, False) jira.get = Mock() jira.put = Mock() toggl = TogglHelper("url", None) toggl.get = Mock() toggl.get.return_value = [ TogglEntry( None, 3600, "2016-01-01T01:01:01", 17, "SLUG-987 hard work", self.jira_config, ) ] jira.get.return_value = [] s = Synchronizer(config, jira, toggl, None, raise_errors=True) s.start(1) toggl.get.assert_called_once_with(1) jira.put.assert_called_once_with( issueId="SLUG-987", started="2016-01-01T01:01:01", seconds=3600, comment="SLUG-987 hard work [toggl#17]", )
def test_ignore_negative_duration(self): """ Synchronizer should ignore entries with negative durations (pending entries). From toggl docs: duration: time entry duration in seconds. If the time entry is currently running, the duration attribute contains a negative value, denoting the start of the time entry in seconds since epoch (Jan 1 1970). The correct duration can be calculated as current_time + duration, where current_time is the current time in seconds since epoch. (integer, required) """ jira = JiraHelper(None, None, None, False) jira.get = Mock() jira.put = Mock() toggl = TogglHelper("url", None) toggl.get = Mock() toggl.get.return_value = [ TogglEntry(None, 3600, "2016-01-01T01:01:01", 777, "test SLUG-333", self.jira_config), TogglEntry( None, -3600, "2016-01-01T01:01:01", 778, "test SLUG-334", self.jira_config, ), ] jira.get.return_value = [] s = Synchronizer(Mock(), jira, toggl, None, raise_errors=True) s.start(1) toggl.get.assert_called_once_with(1) jira.get.assert_called_once_with("SLUG-333") jira.put.assert_called_once_with( issueId="SLUG-333", started="2016-01-01T01:01:01", seconds=3600, comment="test SLUG-333 [toggl#777]", )