Exemplo n.º 1
0
    def test_propper_config_has_values(self):
        config = Config()

        with NamedTemporaryFile() as configfile:
            configfile.write(
                "\n".join(
                    (
                        "[watchlist]",
                        "github-login = foo",
                        "github-oauth-token = bar",
                        "watchlist =",
                        "  watching: foo/*",
                        "  watching: bar/bar",
                        "  not-watching: bar/*",
                    )
                )
            )
            configfile.file.flush()
            config.load(configfile.name)

        self.assertEquals("foo", config.github_login, "Wrong github login")
        self.assertEquals("bar", config.github_oauth_token, "Wrong github token")

        self.assertEquals(
            [("watching", "foo/*"), ("watching", "bar/bar"), ("not-watching", "bar/*")],
            config.watchlist,
            "Unexpected watchlist in config",
        )
Exemplo n.º 2
0
    def test_empty_lines_and_comments_in_watchlist(self):
        config = Config()

        with NamedTemporaryFile() as configfile:
            configfile.write(
                "\n".join(
                    (
                        "[watchlist]",
                        "github-login = foo",
                        "github-oauth-token = bar",
                        "watchlist =",
                        "  watching: foo/*",
                        "",
                        "  watching: bar/*",
                        "# comment",
                        "  watching: baz/*",
                        "",
                    )
                )
            )
            configfile.file.flush()
            config.load(configfile.name)

        self.assertEquals(
            [("watching", "foo/*"), ("watching", "bar/*"), ("watching", "baz/*")],
            config.watchlist,
            "Unexpected watchlist in config",
        )
Exemplo n.º 3
0
def update_command():
    parser = argparse.ArgumentParser(description='Setup github watchlist.')
    add_config_argument_to_argparser(parser)
    add_log_argument_to_argparse(parser)

    parser.add_argument(
        '-C', '--confirmed', action='store_true',
        dest='confirmed',
        help='Update the subscriptions without user confirmation.'
        ' This is useful when running as cronjob.')

    parser.add_argument(
        '-D', '--debug', action='store_true',
        dest='debug',
        help='Start post mortem debugger on python exceptions.')

    parser.add_argument(
        '-v', '--verbose', action='store_true',
        dest='verbose',
        help='Print more verbose informations about whats happening.')

    args = parser.parse_args()
    if args.debug:
        sys.excepthook = post_mortem_debugging_hook
    if args.verbose:
        os.environ['VERBOSE'] = '1'
    setup_logging(args)

    config = Config()
    config.load(args.configfile)

    UpdateCommand(config)(confirmed=args.confirmed)
Exemplo n.º 4
0
    def test_empty_lines_and_comments_in_watchlist(self):
        config = Config()

        with NamedTemporaryFile() as configfile:
            configfile.write('\n'.join(
                ('[watchlist]', 'github-login = foo',
                 'github-oauth-token = bar', 'watchlist =',
                 '  watching: foo/*', '', '  watching: bar/*', '# comment',
                 '  watching: baz/*', '')))
            configfile.file.flush()
            config.load(configfile.name)

        self.assertEquals([('watching', 'foo/*'), ('watching', 'bar/*'),
                           ('watching', 'baz/*')], config.watchlist,
                          'Unexpected watchlist in config')
Exemplo n.º 5
0
    def test_no_configuration_error_when_watchlist_empty(self):
        with NamedTemporaryFile() as configfile:
            configfile.write('\n'.join(
                ('[watchlist]', 'github-login = foo',
                 'github-oauth-token = bar', 'watchlist =', '')))
            configfile.file.flush()

            Config().load(configfile.name)
Exemplo n.º 6
0
def update_command():
    parser = argparse.ArgumentParser(description='Setup github watchlist.')
    add_config_argument_to_argparser(parser)
    add_log_argument_to_argparse(parser)

    parser.add_argument(
        '-C', '--confirmed', action='store_true',
        dest='confirmed',
        help='Update the subscriptions without user confirmation.'
        ' This is useful when running as cronjob.')

    args = parser.parse_args()
    setup_logging(args)

    config = Config()
    config.load(args.configfile)

    UpdateCommand(config)(confirmed=args.confirmed)
Exemplo n.º 7
0
    def test_propper_config_has_values(self):
        config = Config()

        with NamedTemporaryFile() as configfile:
            configfile.write('\n'.join(
                ('[watchlist]', 'github-login = foo',
                 'github-oauth-token = bar', 'watchlist =',
                 '  watching: foo/*', '  watching: bar/bar',
                 '  not-watching: bar/*')))
            configfile.file.flush()
            config.load(configfile.name)

        self.assertEquals('foo', config.github_login, 'Wrong github login')
        self.assertEquals('bar', config.github_oauth_token,
                          'Wrong github token')

        self.assertEquals([('watching', 'foo/*'), ('watching', 'bar/bar'),
                           ('not-watching', 'bar/*')], config.watchlist,
                          'Unexpected watchlist in config')
Exemplo n.º 8
0
    def test_configuration_error_when_no_section_in_config_file(self):
        with NamedTemporaryFile() as configfile:
            # empty config file

            with self.assertRaises(ConfigurationError) as cm:
                Config().load(configfile.name)

            self.assertEquals(
                'The config file should have exactly one section called "watchlist",'
                ' got: none', str(cm.exception))
Exemplo n.º 9
0
    def test_parsing_errors_are_reported(self):
        with NamedTemporaryFile() as configfile:
            configfile.write('\n'.join(('[watchlist', )))
            configfile.file.flush()

            with self.assertRaises(ConfigurationError) as cm:
                Config().load(configfile.name)

            self.assertIn(
                'MissingSectionHeaderError: File contains no section headers.',
                str(cm.exception))
Exemplo n.º 10
0
    def test_configuration_error_when_missing_configuration_options(self):
        with NamedTemporaryFile() as configfile:
            configfile.write('\n'.join(('[watchlist]', '')))
            configfile.file.flush()

            with self.assertRaises(ConfigurationError) as cm:
                Config().load(configfile.name)

            self.assertEquals(
                'Missing configuration options: github-login, github-oauth-token,'
                ' watchlist', str(cm.exception))
Exemplo n.º 11
0
    def test_configuration_error_when_wrong_sections_in_config_file(self):
        with NamedTemporaryFile() as configfile:
            configfile.write('\n'.join(('[foo]', '[bar]')))
            configfile.file.flush()

            with self.assertRaises(ConfigurationError) as cm:
                Config().load(configfile.name)

            self.assertEquals(
                'The config file should have exactly one section called "watchlist",'
                ' got: bar, foo', str(cm.exception))
Exemplo n.º 12
0
    def test_login_and_token_value_required(self):
        with NamedTemporaryFile() as configfile:
            configfile.write('\n'.join(
                ('[watchlist]', 'github-login ='******'github-oauth-token =',
                 'watchlist =')))
            configfile.file.flush()

            with self.assertRaises(ConfigurationError) as cm:
                Config().load(configfile.name)

            self.assertEquals(
                'Values required for the options github-login and github-oauth-token.',
                str(cm.exception))
Exemplo n.º 13
0
    def test_configuration_error_on_bad_indent_in_watchlist(self):
        with NamedTemporaryFile() as configfile:
            configfile.write('\n'.join(('[watchlist]', 'github-login = foo',
                                        'github-oauth-token = bar',
                                        'watchlist =', 'watching: foo/*')))
            configfile.file.flush()

            with self.assertRaises(ConfigurationError) as cm:
                Config().load(configfile.name)

            self.assertEquals(
                'Unexpected configuration options: watching.'
                ' Is the watchlist not properly indented?', str(cm.exception))
Exemplo n.º 14
0
    def test_configuration_error_when_watchlist_item_is_invalid(self):
        with NamedTemporaryFile() as configfile:
            configfile.write('\n'.join(
                ('[watchlist]', 'github-login = foo',
                 'github-oauth-token = bar', 'watchlist =',
                 '  watching: foo/*', '  bar/bar', '  not-watching: bar/*')))
            configfile.file.flush()

            with self.assertRaises(ConfigurationError) as cm:
                Config().load(configfile.name)

            self.assertEquals('Unexpected format of watchlist item: bar/bar',
                              str(cm.exception))