Ejemplo n.º 1
0
def test_auth_success(client, monkeypatch):
    with captured_templates(app) as templates:
        with client.session_transaction() as session:
            session['auto_fork_state'] = 'app_state'

        # mock out the successful response from github
        monkeypatch.setattr(requests, "post",
                            mock_post(200, {'access_token': 'test_token'}))

        # mock the callback from github
        data = {'code': 'supplied_code', 'state': 'app_state'}
        rv: Response = client.get('/auth',
                                  query_string=data,
                                  content_type='application/json')

        assert rv.status_code == 200

        _, template, context, _ = templates[0]
        assert template.name == 'authorized.html'
        assert context['fork_endpoint'] == 'http://localhost/fork'

        # make sure state is cleared
        with client.session_transaction() as session:
            assert 'auto_fork_state' not in session
            assert 'github_access_token' in session
            assert session['github_access_token'] == 'test_token'
Ejemplo n.º 2
0
def test_fork_service_service_unavailable(client, monkeypatch):
    with captured_templates(app) as templates:
        with client.session_transaction() as session:
            session['github_access_token'] = 'test_token'

        monkeypatch.setattr(requests, "post", mock_post(500, {}))

        rv: Response = client.get('/fork')
        assert rv.status_code == 503

        _, template, _, _ = templates[0]
        assert template.name == 'error.html'
Ejemplo n.º 3
0
def test_fork_success(client, monkeypatch):
    with captured_templates(app) as templates:
        with client.session_transaction() as session:
            session['github_access_token'] = 'test_token'

        # mock out the successful response from github
        monkeypatch.setattr(requests, "post", mock_post(202, {}))

        rv: Response = client.get('/fork')

        assert rv.status_code == 200

        _, template, context, _ = templates[0]
        assert template.name == 'forked.html'
        assert context['base_url'] == 'http://localhost/'
Ejemplo n.º 4
0
def test_auth_service_unavailable(client, monkeypatch):
    with captured_templates(app) as templates:
        with client.session_transaction() as session:
            session['auto_fork_state'] = 'app_state'

        # mock out the successful response from github
        monkeypatch.setattr(requests, "post", mock_post(500, {}))

        # mock the callback from github
        data = {'code': 'code', 'state': 'app_state'}
        rv: Response = client.get('/auth',
                                  query_string=data,
                                  content_type='application/json')

        assert rv.status_code == 503

        _, template, _, _ = templates[0]
        assert template.name == 'error.html'