def test_build_with_shas(fixtures, app_context): client = app.test_client() data = { 'job_name': 'app_integration', 'build_number': 3, 'project_name': 'application', 'sha': 'sha1', } response = client.post('/jenkins/api/build_sha', data=data) assert response.status_code == 200 data = { 'job_name': 'app_integration', 'build_number': 3, 'project_name': 'library', 'sha': 'sha2', } response = client.post('/jenkins/api/build_sha', data=data) assert response.status_code == 200 data = make_jenkins_data('app_integration', 3) response = client.post('/jenkins/api/build_status', data=json.dumps(data)) assert response.status_code == 200 application = db.session.query(Project).filter_by(name='application').one() library = db.session.query(Project).filter_by(name='library').one() application.master_sha = 'sha1' library.master_sha = 'sha2' db.session.commit() assert build_check('application', 'sha1')
def test_requires_auth_decorator(): tester = app.test_client() response = tester.get('/pull_request/foo/bar/1') assert response.status_code == 302 # redirect assert '/login' in response.location assert '?next=' in response.location assert quote_plus('/pull_request/foo/bar/1') in response.location
def test_github_auth_redirect(): tester = app.test_client() response = tester.get('/login?next={}'.format(quote_plus('/pull_request/foo/bar/1'))) assert response.status_code == 302 # redirect assert 'github.com/login/oauth/authorize' in response.location # redirecting to github assert quote_plus('/callback') in response.location # with the callback url being the callback route assert quote_plus(urlencode({'next': '/pull_request/foo/bar/1'})) in response.location # quoting plus since its a parameter in a parameter
def test_record_sha(fixtures): client = app.test_client() data = { 'job_name': 'app_integration', 'build_number': 1, 'project_name': 'application', 'sha': 'sha1', } response = client.post('/jenkins/api/build_sha', data=data) assert response.status_code == 200
def hook_post(): client = app.test_client() def poster(data, event_type): headers = { 'Content-type': 'application/json', 'X-GitHub-Event': event_type, } serialised = json.dumps(data) return client.post(URL, data=serialised, headers=headers) return poster
def test_ping(): client = app.test_client() res = client.post(URL, headers={'X-GitHub-Event': 'ping'}) assert res.data == 'pong'
def test_record_status(fixtures): client = app.test_client() data = make_jenkins_data('app_integration', 2) response = client.post('/jenkins/api/build_status', data=json.dumps(data)) assert response.status_code == 200