예제 #1
0
    def test_filterToday(self):
        actual = MattermostNotifier.filterToday([
            TogglEntry(None, 4 * 3600, self.today, 777, "#666 Hardwork",
                       self.redmine_config),
            TogglEntry(None, 4 * 3600, None, 778, "#666 Hardwork",
                       self.redmine_config),
        ])

        self.assertEquals(1, len(actual))
        self.assertEquals(actual[0].id, 777)
예제 #2
0
    def test_append_redmine_summary_only_first_3(self):
        runner = MagicMock()

        mattermost = MattermostNotifier(runner)

        l = [
            TogglEntry(None, 3600, self.today, 777, "test #333",
                       self.redmine_config),
            TogglEntry(None, 3600, self.today, 777, "test #333",
                       self.redmine_config),
            TogglEntry(None, 3600, self.today, 777, "test #333",
                       self.redmine_config),
            TogglEntry(None, 3600, self.today, 777, "test #333",
                       self.redmine_config),
            TogglEntry(None, 0.5 * 3600, self.today, 778, "test #334",
                       self.redmine_config),
            TogglEntry(None, 2 * 3600, self.today, 778, "test #335",
                       self.redmine_config),
            TogglEntry(None, 10 * 3600, self.today, 778, "test #400",
                       self.redmine_config),
        ]

        mattermost._MattermostNotifier__append_redmine_summary(l)
        mattermost.send()

        text = """---
**Redmine summary**
You spent most time on:
- #400: 10.0 h
- #333: 4.0 h
- #335: 2.0 h
"""

        runner.send.assert_called_with(text)
예제 #3
0
    def test_send(self):
        runner = MagicMock()

        mattermost = MattermostNotifier(runner)
        mattermost.append("test")
        mattermost.send()

        runner.send.assert_called_with("test")
예제 #4
0
    def test_filterWithRedmineId(self):
        entries = [
            TogglEntry(None, 1, self.today, 1, "#666 Hardwork",
                       self.redmine_config),
            TogglEntry(None, 1, self.today, 2, "Hardwork",
                       self.redmine_config),
            TogglEntry(None, 1, self.today, 3, "#666 Hardwork",
                       self.redmine_config),
        ]

        filtered = MattermostNotifier.filterWithRedmineId(entries)

        self.assertEquals(2, len(filtered))
        self.assertEquals(1, filtered[0].id)
        self.assertEquals(3, filtered[1].id)
예제 #5
0
    def test_appendDuration_zero_days(self):
        runner = MagicMock()

        mattermost = MattermostNotifier(runner)

        mattermost.appendDuration(0)
        mattermost.send()

        text = """Sync: 0 days"""

        runner.send.assert_called_with(text)
예제 #6
0
    def test_appendDuration_one_day(self):
        runner = MagicMock()

        mattermost = MattermostNotifier(runner)

        mattermost.appendDuration(1)
        mattermost.send()

        text = """Sync: 1 day"""

        runner.send.assert_called_with(text)
예제 #7
0
    def test_append_entries(self):
        runner = MagicMock()

        mattermost = MattermostNotifier(runner)
        mattermost.appendEntries([])
        mattermost.send()

        text = """Found entries in toggl: **0** (filtered: **0**)
Altogether you did not work today at all :cry:. Hope you ok?
"""

        runner.send.assert_called_with(text)
예제 #8
0
    def test_append_entries_one(self):
        runner = MagicMock()

        mattermost = MattermostNotifier(runner)
        mattermost.appendEntries(
            [TogglEntry(None, 60, self.today, 777, "", self.redmine_config)])
        mattermost.send()

        text = """Found entries in toggl: **1** (filtered: **0**)
You worked almost less than 4 hours today (exactly 1 m), not every day is a perfect day, right? :smirk:.
Huh, not many entries. It means, you did only a couple of tasks, but did it right .. right? :open_mouth:
Ugh. Less than 25% of your work had redmine id. Not so good :cry:.
"""

        runner.send.assert_called_with(text)
예제 #9
0
    def test_append_summary_two_one_with_redmine_4_hours(self):
        runner = MagicMock()

        mattermost = MattermostNotifier(runner)
        mattermost._MattermostNotifier__append_summary([
            TogglEntry(None, 4 * 3123, self.today, 777, "#666 Hardwork",
                       self.redmine_config)
        ])
        mattermost.send()

        text = """You worked almost less than 4 hours today (exactly 3.47 h), not every day is a perfect day, right? :smirk:.
Huh, not many entries. It means, you did only a couple of tasks, but did it right .. right? :open_mouth:
It seems that more than 75% of your today work had redmine id! So .. you rock :rocket:!"""

        runner.send.assert_called_with(text)
예제 #10
0
    def test_append_redmine_summary_no_entries_no_summary(self):
        runner = MagicMock()

        mattermost = MattermostNotifier(runner)

        l = [
            TogglEntry(None, 3600, self.today, 777, "test 333",
                       self.redmine_config)
        ]

        mattermost._MattermostNotifier__append_redmine_summary(l)
        mattermost.send()

        text = ""

        runner.send.assert_called_with(text)
예제 #11
0
    def test_append_summary_50_entries(self):
        runner = MagicMock()

        mattermost = MattermostNotifier(runner)

        e = TogglEntry(None, 60, self.today, 777, "#666 Hardwork",
                       self.redmine_config)
        l = []

        for i in range(50):
            l.append(e)

        mattermost._MattermostNotifier__append_summary(l)
        mattermost.send()

        text = """You worked almost less than 4 hours today (exactly 50 m), not every day is a perfect day, right? :smirk:.
You did 50 entries like a boss :smirk: :boom:!
It seems that more than 75% of your today work had redmine id! So .. you rock :rocket:!"""

        runner.send.assert_called_with(text)
예제 #12
0
    def test_append_summary_10_entries(self):
        runner = MagicMock()

        mattermost = MattermostNotifier(runner)

        e = TogglEntry(None, 4 * 3600, self.today, 777, "#666 Hardwork",
                       self.redmine_config)
        l = []

        for i in range(1, 10):
            l.append(e)

        mattermost._MattermostNotifier__append_summary(l)
        mattermost.send()

        text = """Wow you did overtime today :rocket:! Doing overtime from time to time can be good, but life after work is also important. Remember this next time taking 36.00 h in work :sunglasses:!
Average day. Not too few, not too many entries :sunglasses:.
It seems that more than 75% of your today work had redmine id! So .. you rock :rocket:!"""

        runner.send.assert_called_with(text)
예제 #13
0
    def test_append_summary_3_entries_1_redmine(self):
        runner = MagicMock()

        mattermost = MattermostNotifier(runner)

        l = [
            TogglEntry(None, 60, self.today, 777, "#666 Hardwork",
                       self.redmine_config),
            TogglEntry(None, 60, self.today, 777, "Hardwork",
                       self.redmine_config),
            TogglEntry(None, 60, self.today, 777, "Hardwork",
                       self.redmine_config),
        ]

        mattermost._MattermostNotifier__append_summary(l)
        mattermost.send()

        text = """You worked almost less than 4 hours today (exactly 3 m), not every day is a perfect day, right? :smirk:.
Huh, not many entries. It means, you did only a couple of tasks, but did it right .. right? :open_mouth:
Almost 50% of your today work had redmine id :blush:."""

        runner.send.assert_called_with(text)
예제 #14
0
    def test_append_entries_two_one_with_redmine(self):
        runner = MagicMock()

        mattermost = MattermostNotifier(runner)
        mattermost.appendEntries([
            TogglEntry(None, 60, self.today, 776, "", self.redmine_config),
            TogglEntry(None, 60, self.today, 777, "#666 Hardwork",
                       self.redmine_config),
        ])
        mattermost.send()

        text = """Found entries in toggl: **2** (filtered: **1**)
You worked almost less than 4 hours today (exactly 2 m), not every day is a perfect day, right? :smirk:.
Huh, not many entries. It means, you did only a couple of tasks, but did it right .. right? :open_mouth:
It's gooood. A lot of today work had redmine id! Congrats :sunglasses:.

---
**Redmine summary**
You spent most time on:
- #666: 0.02 h
"""

        runner.send.assert_called_with(text)
예제 #15
0
    def test_ignore_negative_duration(self):
        """
        Mattermost 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)
        """

        runner = MagicMock()

        mattermost = MattermostNotifier(runner)

        l = [
            TogglEntry(None, 3600, self.today, 777, "test #333",
                       self.redmine_config),
            TogglEntry(None, -300, self.today, 778, "test #334",
                       self.redmine_config),
        ]

        mattermost.appendEntries(l)
        mattermost.send()

        text = """Found entries in toggl: **2** (filtered: **1**)
You worked almost less than 4 hours today (exactly 1.00 h), not every day is a perfect day, right? :smirk:.
Huh, not many entries. It means, you did only a couple of tasks, but did it right .. right? :open_mouth:
It seems that more than 75% of your today work had redmine id! So .. you rock :rocket:!

---
**Redmine summary**
You spent most time on:
- #333: 1.0 h
"""

        runner.send.assert_called_with(text)
예제 #16
0
    print("Synchronizer v{}\n============================".format(
        version.VERSION))

    if args.version:
        sys.exit(0)

    config = Config.fromFile()

    # print("Found api key pairs: {}".format(len(config.entries)))

    mattermost = None

    if config.mattermost:
        runner = RequestsRunner.fromConfig(config.mattermost)
        mattermost = MattermostNotifier(runner, args.simulation)

    for config_entry in config.entries:
        print("Synchronization for {} ...".format(config_entry.label))
        print("---")
        toggl = TogglHelper(config.toggl, config_entry)
        api_helper = ApiHelperFactory(config_entry).create()
        if not api_helper:
            print(
                "Can't interpret config to destination API - entry: {}".format(
                    config_entry.label))
            continue

        if mattermost != None:
            mattermost.append("TogglSync v{} for {}".format(
                version.VERSION, config_entry.label))
예제 #17
0
 def test_formatSeconds_less_60(self):
     self.assertEquals("45 s", MattermostNotifier.formatSeconds(45))
예제 #18
0
 def test_formatSeconds_more_60_less_3600(self):
     self.assertEquals("5 m", MattermostNotifier.formatSeconds(5 * 60))
예제 #19
0
 def test_formatSeconds_hours(self):
     self.assertEquals("10.00 h", MattermostNotifier.formatSeconds(36000))
예제 #20
0
 def test_filterToday_empty(self):
     actual = MattermostNotifier.filterToday([])
     self.assertEquals(0, len(actual))
예제 #21
0
 def test_filterToday_None(self):
     actual = MattermostNotifier.filterToday(None)
     self.assertEquals(0, len(actual))