Exemple #1
0
    def test_integration_create_watchlist_configuration(self):
        with self.mocker.order():
            self.type_when_asked('john.doe', prompt='Your GitHub username: '******'wrong-password',
                                 prompt='Your GitHub password: '******'john.doe', password='******')

            self.type_when_asked('correct-password',
                                 prompt='Your GitHub password: '******'john.doe',
                password='******',
                token='123asdf')

        self.mocker.replay()

        path = os.path.join(tempfile.gettempdir(), 'watchlist-config.ini')
        try:
            InitializeWatchlistConfiguration()(path)

            configfile = open(path).read()

            self.assertIn('github-oauth-token = 123asdf', configfile,
                          'Missing github-oauth-token in config file')

        finally:
            if os.path.exists(path):
                os.unlink(path)
Exemple #2
0
    def test_generate_config_file(self):
        self.mocker.replay()

        path = os.path.join(tempfile.gettempdir(), 'watchlist-config.ini')
        try:
            login = '******'
            token = '345231jkasd'

            InitializeWatchlistConfiguration().generate_config_file(
                path, login, token)

            with open(path) as file_:
                data = file_.read().split('\n')

            self.assertIn('[watchlist]', data,
                          'Missing [watchlist] section header in config file')

            self.assertIn('github-login = john.doe', data,
                          'Missing github-login in config file')

            self.assertIn('github-oauth-token = 345231jkasd', data,
                          'Missing github-oauth-token in config file')

            self.assertIn('watchlist =', data,
                          'Missing watchlist boilerplate in config file')

        finally:
            if os.path.exists(path):
                os.unlink(path)
Exemple #3
0
    def test_ask_for_oauth_token(self):
        self.type_when_asked('098765ertfgi')
        self.mocker.replay()

        self.assertEquals(
            '098765ertfgi',
            InitializeWatchlistConfiguration().ask_for_oauth_token('john.doe'))
Exemple #4
0
    def test_ask_for_github_password(self):
        self.type_when_asked('secret!!', hidden=True)
        self.mocker.replay()

        self.assertEquals(
            'secret!!',
            InitializeWatchlistConfiguration().ask_for_github_password())
Exemple #5
0
    def test_ask_for_login(self):
        self.type_when_asked('jone')
        self.mocker.replay()

        self.assertEquals(
            'jone',
            InitializeWatchlistConfiguration().ask_for_github_login())
Exemple #6
0
    def test_integration_asked_for_oauth_token_on_empty_password(self):
        with self.mocker.order():
            self.type_when_asked('john.doe', prompt='Your GitHub username: '******'',
                                 prompt='Your GitHub password: '******'94a08da1fecbb6e8b46990538c7b50b2',
                                 prompt='GitHub OAuth token: ')

        self.mocker.replay()

        path = os.path.join(tempfile.gettempdir(), 'watchlist-config.ini')
        try:
            InitializeWatchlistConfiguration()(path)

            configfile = open(path).read()

            self.assertIn(
                'github-oauth-token = 94a08da1fecbb6e8b46990538c7b50b2',
                configfile,
                'Missing or wrong github-oauth-token in config file')

        finally:
            if os.path.exists(path):
                os.unlink(path)
Exemple #7
0
    def test_retry_when_github_login_invalid(self):
        with self.mocker.order():
            self.type_when_asked('wrong user')
            self.type_when_asked('-other-wrong-user')
            self.type_when_asked('foo$')
            self.type_when_asked('val-id.user')
        self.mocker.replay()

        self.assertEquals(
            'val-id.user',
            InitializeWatchlistConfiguration().ask_for_github_login())
Exemple #8
0
    def test_generate_config_file_asks_when_file_exists(self):
        path = os.path.join(tempfile.gettempdir(), 'watchlist-config.ini')
        try:
            open(path, 'w+').close()
            login = '******'
            token = '345231jkasd'

            self.type_when_asked('',
                                 prompt='Confirm replacing file with ENTER'
                                 ' or abort with Ctrl-C: ')

            self.mocker.replay()

            InitializeWatchlistConfiguration().generate_config_file(
                path, login, token)

        finally:
            if os.path.exists(path):
                os.unlink(path)