def test_resultset_create(sample_resultset, jm, initial_data, mock_post_json): """ test posting data to the resultset endpoint via webtest. extected result are: - return code 200 - return message successful - 1 resultset stored in the jobs schema """ trsc = TreeherderResultSetCollection() for rs in sample_resultset: rs.update({'author': 'John Doe'}) result_set = trsc.get_resultset(rs) trsc.add(result_set) test_utils.post_collection(jm.project, trsc) stored_objs = jm.get_dhub().execute( proc="jobs_test.selects.resultset_by_rev_hash", placeholders=[sample_resultset[0]['revision_hash']] ) assert len(stored_objs) == 1 assert stored_objs[0]['revision_hash'] == sample_resultset[0]['revision_hash'] jm.disconnect()
def test_resultset_create(jm, test_repository, sample_resultset, mock_post_json): """ test posting data to the resultset endpoint via webtest. extected result are: - return code 200 - return message successful - 1 resultset stored in the jobs schema """ assert Push.objects.count() == 0 # store the first two, so we submit all, but should properly not re- # add the others. jm.store_result_set_data(sample_resultset[:2]) assert Push.objects.count() == 2 trsc = TreeherderResultSetCollection() exp_revision_hashes = set() for rs in sample_resultset: rs.update({'author': 'John Doe'}) result_set = trsc.get_resultset(rs) trsc.add(result_set) exp_revision_hashes.add(rs["revision"]) test_utils.post_collection(jm.project, trsc) assert Push.objects.count() == len(sample_resultset) assert set(Push.objects.values_list('revision', flat=True)) == set( [rs['revision'] for rs in sample_resultset])
def test_resultset_create(jm, test_repository, sample_resultset, mock_post_json): """ test posting data to the resultset endpoint via webtest. extected result are: - return code 200 - return message successful - 1 resultset stored in the jobs schema """ # store the first two, so we submit all, but should properly not re- # add the others. jm.store_result_set_data(sample_resultset[:2]) trsc = TreeherderResultSetCollection() exp_revision_hashes = set() for rs in sample_resultset: rs.update({'author': 'John Doe'}) result_set = trsc.get_resultset(rs) trsc.add(result_set) exp_revision_hashes.add(rs["revision"]) resp = test_utils.post_collection(jm.project, trsc) act_revision_hashes = {x["long_revision"] for x in resp.json["resultsets"]} assert exp_revision_hashes == act_revision_hashes stored_objs = jm.get_dhub().execute( proc="jobs_test.selects.resultset_by_long_revision", placeholders=[sample_resultset[0]['revision']]) assert len(stored_objs) == 1 assert stored_objs[0]['long_revision'] == sample_resultset[0]['revision']
def test_resultset_create(test_repository, sample_resultset, mock_post_json): """ test posting data to the resultset endpoint via webtest. extected result are: - return code 200 - return message successful - 1 resultset stored in the jobs schema """ assert Push.objects.count() == 0 # store the first two, so we submit all, but should properly not re- # add the others. store_result_set_data(test_repository, sample_resultset[:2]) assert Push.objects.count() == 2 trsc = TreeherderResultSetCollection() exp_revision_hashes = set() for rs in sample_resultset: rs.update({'author': 'John Doe'}) result_set = trsc.get_resultset(rs) trsc.add(result_set) exp_revision_hashes.add(rs["revision"]) test_utils.post_collection(test_repository.name, trsc) assert Push.objects.count() == len(sample_resultset) assert set(Push.objects.values_list('revision', flat=True)) == set( [rs['revision'] for rs in sample_resultset])
def test_send_result_collection(self, mock_post): """Can add a treeherder collections to a TreeherderRequest.""" mock_post.return_value = self._expected_response_return_object() trc = TreeherderResultSetCollection() for resultset in self.resultset_data: trc.add(trc.get_resultset(resultset)) client = TreeherderClient( protocol='http', host='host', client_id='client-abc', secret='secret123', ) client.post_collection('project', trc) path, resp = mock_post.call_args self.assertEqual(mock_post.call_count, 1) self.assertEqual( trc.get_collection_data(), resp['json'] )
def test_send_result_collection(self): """Can add a treeherder collections to a TreeherderRequest.""" trc = TreeherderResultSetCollection() for resultset in self.resultset_data: trc.add(trc.get_resultset(resultset)) client = TreeherderClient( server_url='http://host', client_id='client-abc', secret='secret123', ) def request_callback(request): # Check that the expected content was POSTed. posted_json = json.loads(request.body) self.assertEqual(posted_json, trc.get_collection_data()) return ( 200, {}, '{"message": "well-formed JSON stored", "resultsets": [123, 456]}' ) url = client._get_endpoint_url(trc.endpoint_base, project='project') responses.add_callback(responses.POST, url, match_querystring=True, callback=request_callback, content_type='application/json') client.post_collection('project', trc)
def test_resultset_create(sample_resultset, jm, initial_data): """ test posting data to the resultset endpoint via webtest. extected result are: - return code 200 - return message successful - 1 resultset stored in the jobs schema """ trsc = TreeherderResultSetCollection() for rs in sample_resultset: rs = trsc.get_resultset(rs) trsc.add(rs) resp = test_utils.post_collection(jm.project, trsc) assert resp.status_int == 200 assert resp.json['message'] == 'well-formed JSON stored' stored_objs = jm.get_dhub().execute( proc="jobs_test.selects.resultset_by_rev_hash", placeholders=[sample_resultset[0]['revision_hash']] ) assert len(stored_objs) == 1 assert stored_objs[0]['revision_hash'] == sample_resultset[0]['revision_hash'] jm.disconnect()
def test_resultset_create(jm, test_repository, sample_resultset, mock_post_json): """ test posting data to the resultset endpoint via webtest. extected result are: - return code 200 - return message successful - 1 resultset stored in the jobs schema """ # store the first two, so we submit all, but should properly not re- # add the others. jm.store_result_set_data(sample_resultset[:2]) trsc = TreeherderResultSetCollection() exp_revision_hashes = set() for rs in sample_resultset: rs.update({'author': 'John Doe'}) result_set = trsc.get_resultset(rs) trsc.add(result_set) exp_revision_hashes.add(rs["revision"]) resp = test_utils.post_collection(jm.project, trsc) act_revision_hashes = {x["long_revision"] for x in resp.json["resultsets"]} assert exp_revision_hashes == act_revision_hashes stored_objs = jm.get_dhub().execute( proc="jobs_test.selects.resultset_by_long_revision", placeholders=[sample_resultset[0]['revision']] ) assert len(stored_objs) == 1 assert stored_objs[0]['long_revision'] == sample_resultset[0]['revision']
def test_resultset_create(sample_resultset, jm, initial_data): """ test posting data to the resultset endpoint via webtest. extected result are: - return code 200 - return message successful - 1 resultset stored in the jobs schema """ trsc = TreeherderResultSetCollection() for rs in sample_resultset: rs = trsc.get_resultset(rs) trsc.add(rs) resp = test_utils.post_collection(jm.project, trsc) assert resp.status_int == 200 assert resp.json['message'] == 'well-formed JSON stored' stored_objs = jm.get_jobs_dhub().execute( proc="jobs_test.selects.resultset_by_rev_hash", placeholders=[sample_resultset[0]['revision_hash']]) assert len(stored_objs) == 1 assert stored_objs[0]['revision_hash'] == sample_resultset[0][ 'revision_hash'] jm.disconnect()
def test_resultset_with_bad_key(sample_resultset, jm, initial_data): trsc = TreeherderResultSetCollection() for rs in sample_resultset: rs = trsc.get_resultset(rs) trsc.add(rs) resp = test_utils.post_collection( jm.project, trsc, status=403, consumer_key="horrible-key" ) assert resp.status_int == 403 assert resp.json['detail'] == 'oauth_consumer_key does not match credentials for project {0}'.format(jm.project)
def test_resultset_with_bad_secret(sample_resultset, jm, initial_data): trsc = TreeherderResultSetCollection() for rs in sample_resultset: rs = trsc.get_resultset(rs) trsc.add(rs) resp = test_utils.post_collection( jm.project, trsc, status=403, consumer_secret="horrible secret" ) assert resp.status_int == 403 assert resp.json['detail'] == "Client authentication failed for project {0}".format(jm.project)
def test_resultset_with_bad_key(sample_resultset, jm, initial_data): trsc = TreeherderResultSetCollection() for rs in sample_resultset: rs = trsc.get_resultset(rs) trsc.add(rs) resp = test_utils.post_collection(jm.project, trsc, status=403, consumer_key="horrible-key") assert resp.status_int == 403 assert resp.json[ 'detail'] == 'oauth_consumer_key does not match credentials for project {0}'.format( jm.project)
def test_resultset_with_bad_secret(sample_resultset, jm, initial_data): trsc = TreeherderResultSetCollection() for rs in sample_resultset: rs = trsc.get_resultset(rs) trsc.add(rs) resp = test_utils.post_collection(jm.project, trsc, status=403, consumer_secret="horrible secret") assert resp.status_int == 403 assert resp.json[ 'detail'] == "Client authentication failed for project {0}".format( jm.project)
def test_send_result_collection(self, mock_post): """Can add a treeherder collections to a TreeherderRequest.""" mock_post.return_value = self._expected_response_return_object() trc = TreeherderResultSetCollection() for resultset in self.resultset_data: trc.add(trc.get_resultset(resultset)) client = TreeherderClient(protocol="http", host="host") auth = TreeherderAuth("key", "secret", "project") client.post_collection("project", trc, auth=auth) path, resp = mock_post.call_args self.assertEqual(mock_post.call_count, 1) self.assertEqual(trc.get_collection_data(), resp["json"])
def test_send_result_collection(self, mock_post): """Can add a treeherder collections to a TreeherderRequest.""" mock_post.return_value = self._expected_response_return_object() trc = TreeherderResultSetCollection() for resultset in self.resultset_data: trc.add(trc.get_resultset(resultset)) client = TreeherderClient( protocol='http', host='host', ) client.post_collection('project', 'key', 'secret', trc) path, resp = mock_post.call_args self.assertEqual(mock_post.call_count, 1) self.assertEqual(trc.to_json(), resp['data'])
def test_send_result_collection(self): """Can add a treeherder collections to a TreeherderRequest.""" trc = TreeherderResultSetCollection() for resultset in self.resultset_data: trc.add(trc.get_resultset(resultset)) client = TreeherderClient(protocol="http", host="host", client_id="client-abc", secret="secret123") def request_callback(request): # Check that the expected content was POSTed. posted_json = json.loads(request.body) self.assertEqual(posted_json, trc.get_collection_data()) return (200, {}, '{"message": "well-formed JSON stored", "resultsets": [123, 456]}') url = client._get_project_uri("project", trc.endpoint_base) responses.add_callback( responses.POST, url, match_querystring=True, callback=request_callback, content_type="application/json" ) client.post_collection("project", trc)
def test_send_result_collection(self, mock_send): """Can add a treeherder collections to a TreeherderRequest.""" trc = TreeherderResultSetCollection() for resultset in self.resultset_data: trc.add(trc.get_resultset(resultset)) req = TreeherderRequest( protocol='http', host='host', project='project', oauth_key='key', oauth_secret='secret', ) req.post(trc) self.assertEqual(mock_send.call_count, 1) self.assertEqual( trc.to_json(), mock_send.call_args_list[0][1]['data'] )