예제 #1
0
    def test_send_success_multiple_channels(self, post_function):
        runner = RequestsRunner("http://test.com", ["#chan", "#chan2"])
        runner.send("y")

        post_function.assert_has_calls([
            call("http://test.com", data='{"channel": "#chan", "text": "y"}'),
            call("http://test.com", data='{"channel": "#chan2", "text": "y"}'),
        ])
예제 #2
0
    def test_send_to_default_and_particular(self, post_function):
        runner = RequestsRunner("http://test.com", ["", "#chan2"])
        runner.send("y")

        post_function.assert_has_calls([
            call("http://test.com", data='{"text": "y"}'),
            call("http://test.com", data='{"channel": "#chan2", "text": "y"}'),
        ])
예제 #3
0
    def test_send_error_no_json(self, post_function):
        runner = RequestsRunner("http://test.com")

        try:
            runner.send("x")
            self.fail("expected exception")
        except Exception as exc:
            self.assertEquals(
                """Error sending to mattermost:
Something went wrong...""",
                str(exc),
            )

        post_function.assert_called_with("http://test.com",
                                         data='{"text": "x"}')
예제 #4
0
    def test_fromConfig_with_channels(self):
        runner = RequestsRunner.fromConfig({
            "url": "https://xxx",
            "channel": ["#chan", "#chan2"]
        })

        self.assertEquals("https://xxx", runner.url)
        self.assertEquals("toggl2redmine", runner.username)
        self.assertEquals(["#chan", "#chan2"], runner.channel)
예제 #5
0
    def test_send_success_one_channel(self, post_function):
        runner = RequestsRunner("http://test.com", "#chan")
        runner.send("y")

        post_function.assert_called_with(
            "http://test.com", data='{"channel": "#chan", "text": "y"}')
예제 #6
0
 def test_fromConfig(self):
     runner = RequestsRunner.fromConfig({"url": "https://xxx"})
     self.assertEquals("https://xxx", runner.url)
     self.assertIsNone(runner.channel)
     self.assertEquals("toggl2redmine", runner.username)
예제 #7
0
    args = parser.parse_args()

    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(