Example #1
0
def manage():

    full_name = request.form.get('full_name', '')
    data = dict(parse_qsl(request.form.get('data', '')))

    repo_name = (
        '' if github_utils.is_user_pages(full_name)
        else full_name.split('/', 1)[-1]
    )

    github_token = current_user.github_token
    travis_token = current_user.travis_token

    # If repo not listed in travis, sync
    repo_id = travis_utils.get_repo_id(full_name, travis_token)
    if repo_id is None:
        travis_utils.sync_with_github(travis_token)
        repo_id = travis_utils.get_repo_id(full_name, travis_token)

    if repo_id is None:
        message = messages.NO_SUCH_REPO_FOUND
        return jsonify(dict(message=message))

    enabled = travis_utils.enable_hook(repo_id, travis_token)
    created = create_travis_files(full_name, github_token, data)

    response = get_display_response(enabled, created)
    response['message'] %= dict(USER=current_user.username, REPO=repo_name)
    return jsonify(response)
Example #2
0
    def test_should_handle_aborted_sync(self):
        # Given
        true = Mock(return_value=True)
        response = Mock(status_code=404)

        # When
        with patch('travis_utils.start_sync', true):
            with patch('requests.get', Mock(return_value=response)):
                synced = travis_utils.sync_with_github(TRAVIS_TOKEN)

        # Then
        self.assertFalse(synced)
Example #3
0
    def test_should_sync(self):
        # Given
        true = Mock(return_value=True)
        json = Mock(return_value={'is_syncing': False})
        response = Mock(status_code=200, json=json)

        # When
        with patch('travis_utils.start_sync', true):
            with patch('requests.get', Mock(return_value=response)):
                synced = travis_utils.sync_with_github(TRAVIS_TOKEN)

        # Then
        self.assertTrue(synced)
Example #4
0
    def test_should_handle_sync_timeout(self):
        # Given
        true = Mock(return_value=True)
        json = Mock(return_value={'is_syncing': True})
        response = Mock(status_code=200, json=json)

        # When
        with patch('travis_utils.start_sync', true):
            with patch('requests.get', Mock(return_value=response)) as get:
                with patch('time.sleep', Mock()):
                    synced = travis_utils.sync_with_github(TRAVIS_TOKEN)

        # Then
        _, kwargs = get.call_args
        self.assertDictEqual(
            kwargs['headers'], travis_utils.get_header(TRAVIS_TOKEN)
        )
        self.assertFalse(synced)
Example #5
0
 def test_should_not_start_sync_unauthenticated(self):
     self.assertFalse(travis_utils.sync_with_github(BOGUS))