コード例 #1
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)
コード例 #2
0
    def test_send(self):
        runner = MagicMock()

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

        runner.send.assert_called_with("test")
コード例 #3
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)
コード例 #4
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)
コード例 #5
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)
コード例 #6
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)
コード例 #7
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)
コード例 #8
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)
コード例 #9
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)
コード例 #10
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)
コード例 #11
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)
コード例 #12
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)
コード例 #13
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)
コード例 #14
0
    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))
            mattermost.append("---")
            mattermost.append("")

        sync = Synchronizer(config,
                            api_helper,
                            toggl,
                            mattermost,
                            raise_errors=args.errors)
        sync.start(args.days)

    if mattermost != None:
        mattermost.send()