def test_sync_skipping_entries_under_1min(self):
        config = MagicMock()
        jira = JiraHelper(None, None, None, False)
        jira.get = Mock()
        jira.jira_api = Mock()
        # jira.put = Mock()
        jira.jira_api.add_worklog = Mock()
        toggl = TogglHelper("url", None)
        toggl.get = Mock()

        toggl.get.return_value = [
            TogglEntry(
                None,
                29,  # time rounds to under 60 sec
                "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.jira_api.add_worklog.assert_not_called()
    def test_sync_single_toggl_update_to_under_1min_clears_worklog(self):
        jira = JiraHelper(None, None, None, False)
        jira.get = Mock()
        jira.delete = Mock()
        toggl = TogglHelper("url", None)
        toggl.get = Mock()

        toggl.get.return_value = [
            TogglEntry(
                None,
                29,  # time rounds to under 60 sec
                "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",
                1000,
                "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.delete.assert_called_once_with(222, "SLUG-987")
    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_start_one_day_single(self):
        jira = JiraHelper(None, None, None, False)
        toggl = TogglHelper("url", None)
        toggl.get = Mock()

        toggl.get.return_value = [
            TogglEntry(None, 3600, "2016-03-02T01:01:01", 777, "test SLUG-333",
                       self.jira_config)
        ]

        jira.get = Mock()
        jira.get.return_value = [
            JiraTimeEntry(
                777,
                "2016-01-01T01:02:03",
                "john doe",
                3600,
                "2016-03-02T01:01:01",
                "SLUG-333",
                "test SLUG-333 [toggl#777]",
            )
        ]
        jira.update = MagicMock()

        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.update.assert_not_called()
Ejemplo n.º 6
0
 def test_round_to_minutes(self):
     self.assertEquals(0, JiraHelper.round_to_minutes(0))
     self.assertEquals(0, JiraHelper.round_to_minutes(29))
     self.assertEquals(0, JiraHelper.round_to_minutes(30))
     self.assertEquals(60, JiraHelper.round_to_minutes(31))
     self.assertEquals(60, JiraHelper.round_to_minutes(59))
     self.assertEquals(60, JiraHelper.round_to_minutes(60))
     self.assertEquals(60, JiraHelper.round_to_minutes(89))
     self.assertEquals(120, JiraHelper.round_to_minutes(
         90))  # seems strange, but that how default python rounding works
     self.assertEquals(120, JiraHelper.round_to_minutes(91))
     self.assertEquals(120, JiraHelper.round_to_minutes(120))
    def test_equal_diff_time(self):
        toggl, jira = self.create_test_entries_pair()
        toggl.seconds = 120

        helper = JiraHelper(None, None, None, False)
        sync = Synchronizer(None, helper, None, None)
        self.assertFalse(sync._equal(toggl, jira))
    def test_equal_rounding_to_min(self):
        toggl, jira = self.create_test_entries_pair()
        toggl.seconds += 30

        helper = JiraHelper(None, None, None, False)
        sync = Synchronizer(None, helper, None, None)
        self.assertTrue(sync._equal(toggl, jira))
    def test_equal_diff_comment(self):
        toggl, jira = self.create_test_entries_pair()
        toggl.description = "changed SLUG-333"

        helper = JiraHelper(None, None, None, False)
        sync = Synchronizer(None, helper, None, None)
        self.assertFalse(sync._equal(toggl, jira))
    def test_equal_diff_started(self):
        toggl, jira = self.create_test_entries_pair()
        toggl.start = "2016-12-25T01:01:01"

        helper = JiraHelper(None, None, None, False)
        sync = Synchronizer(None, helper, None, None)
        self.assertFalse(sync._equal(toggl, jira))
Ejemplo n.º 11
0
 def testDictFromTogglEntry(self):
     input = TogglEntry(None, 120, "2016-03-02T01:01:01", 777,
                        "test SLUG-333", self.jira_config)
     result = JiraHelper.dictFromTogglEntry(input)
     self.assertEquals("SLUG-333", result["issueId"])
     self.assertEquals("2016-03-02T01:01:01", result["started"])
     self.assertEquals(120, result["seconds"])
     self.assertEquals("test SLUG-333 [toggl#777]", result["comment"])
    def test_start_one_day_empty(self):
        jira = JiraHelper(None, None, None, False)
        toggl = TogglHelper("url", None)
        toggl.get = MagicMock()

        s = Synchronizer(Mock(), jira, toggl, None, raise_errors=True)
        s.start(1)

        toggl.get.assert_called_once_with(1)
    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]",
        )
    def test_sync_single_toggl_modified_entry(self):
        jira = JiraHelper(None, None, None, False)
        jira.get = Mock()
        jira.update = Mock()
        toggl = TogglHelper("url", None)
        toggl.get = Mock()

        toggl.get.return_value = [
            TogglEntry(
                None,
                2 * 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",
                1,
                "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_called_once_with(
            id=222,
            issueId="SLUG-987",
            started="2016-01-01T01:01:01",
            seconds=2 * 3600,
            comment="SLUG-987 hard work [toggl#17]",
        )
Ejemplo n.º 15
0
 def create(self):
     if self.config_entry.redmine_api_key:
         return RedmineHelper(config.redmine, config_entry.redmine_api_key,
                              args.simulation)
     elif config_entry.jira_url:
         return JiraHelper(
             config_entry.jira_url,
             config_entry.jira_username,
             self.jira_pass,
             args.simulation,
         )
     else:
         return None
Ejemplo n.º 16
0
 def testDictFromTogglEntry_time_is_rounded(self):
     input = TogglEntry(None, 151, "2016-03-02T01:01:01", 777,
                        "test SLUG-333", self.jira_config)
     result = JiraHelper.dictFromTogglEntry(input)
     self.assertEquals(180, result["seconds"])
    def test_equal_exact(self):
        toggl, jira = self.create_test_entries_pair()

        helper = JiraHelper(None, None, None, False)
        sync = Synchronizer(None, helper, None, None)
        self.assertTrue(sync._equal(toggl, jira))