def test_app_patch(self): lp_name = self.client.create_lp() data = apputils.get_sample_data(languagepack=lp_name) create_resp = self.client.create_app(data=data) self.assertEqual(create_resp.status, 201) json_update = { 'name': 'newfakeappname', 'workflow_config': { 'run_cmd': 'newruncmd', }, 'source': { 'repository': 'newrepo', }, } uri = 'v1/apps/%s' % create_resp.id resp, body = self.client.patch( uri, json.dumps(json_update), headers={'content-type': 'application/json'}) self.assertEqual(resp.status, 200) app_body = json.loads(body) self.assertEqual(app_body["name"], 'newfakeappname') self.assertEqual(app_body["workflow_config"]["run_cmd"], "newruncmd") self.assertEqual(app_body["source"]["repository"], "newrepo") self.client.delete_app(create_resp.id) time.sleep(2) self.client.delete_language_pack(lp_name)
def test_app_patch(self): lp_name = self.client.create_lp() data = apputils.get_sample_data(languagepack=lp_name) create_resp = self.client.create_app(data=data) self.assertEqual(201, create_resp.status) json_update = { 'name': 'newfakeappname', 'workflow_config': { 'run_cmd': 'newruncmd', }, 'source': { 'repository': 'newrepo', }, } uri = 'v1/apps/%s' % create_resp.id resp, body = self.client.patch( uri, json.dumps(json_update), headers={'content-type': 'application/json'}) self.assertEqual(200, resp.status) app_body = json.loads(body) self.assertEqual('newfakeappname', app_body["name"]) self.assertEqual("newruncmd", app_body["workflow_config"]["run_cmd"]) self.assertEqual("newrepo", app_body["source"]["repository"]) self.client.delete_app(create_resp.id) time.sleep(2) self.client.delete_language_pack(lp_name)
def test_trigger_post(self): lp_name = self.client.create_lp() data = apputils.get_sample_data(languagepack=lp_name) resp = self.client.create_app(data=data) bdy = json.loads(resp.body) trigger_uri = bdy['trigger_uri'] # Using requests instead of self.client to test unauthenticated request status_url = 'https://api.github.com/repos/u/r/statuses/{sha}' body_dict = { 'sender': { 'url': 'https://api.github.com' }, 'pull_request': { 'head': { 'sha': 'asdf' } }, 'repository': { 'statuses_url': status_url } } body = json.dumps(body_dict) resp = requests.post(trigger_uri, data=body) self.assertEqual(resp.status_code, 202) self.client.delete_created_apps() # since app delete is an async operation, wait few seconds for app # delete and then delete language pack (otherwise language pack # cannot be deleted) time.sleep(2) self.client.delete_created_lps()
def test_app_create_bad_port_data(self): try: bad_data = apputils.get_sample_data() bad_data["ports"][0] = -1 self.client.create_plan(data=bad_data) except tempest_exceptions.BadRequest: self.assertTrue(True)
def test_app_patch(self): data = apputils.get_sample_data() create_resp = self.client.create_app(data=data) self.assertEqual(create_resp.status, 201) json_update = { 'name': 'newfakeappname', 'workflow_config': { 'run_cmd': 'newruncmd', }, 'source': { 'repository': 'newrepo', }, } uri = 'v1/apps/%s' % create_resp.id resp, body = self.client.patch( uri, json.dumps(json_update), headers={'content-type': 'application/json'}) self.assertEqual(resp.status, 200) app_body = json.loads(body) self.assertEqual(app_body["name"], 'newfakeappname') self.assertEqual(app_body["workflow_config"]["run_cmd"], "newruncmd") self.assertEqual(app_body["source"]["repository"], "newrepo")
def test_app_delete(self): data = apputils.get_sample_data() create_resp = self.client.create_app(data) self.assertEqual(create_resp.status, 201) id = create_resp.id resp, body = self.client.delete_app(id) self.assertEqual(resp.status, 202) self.assertEqual(body, '')
def test_app_create(self): lp_name = self.client.create_lp() data = apputils.get_sample_data(languagepack=lp_name) resp = self.client.create_app(data=data) self.assertEqual(resp.status, 201) self.client.delete_app(resp.id) time.sleep(2) self.client.delete_language_pack(lp_name)
def create_app(self, data=None): app_data = copy.deepcopy(data) or apputils.get_sample_data() json_data = json.dumps(app_data) resp, body = self.post('v1/apps', json_data) app_resp = SolumResponse(resp=resp, body=body, body_type='yaml') if app_resp.id is not None: self.created_apps.append(app_resp.id) return app_resp
def test_app_delete(self): lp_name = self.client.create_lp() data = apputils.get_sample_data(languagepack=lp_name) create_resp = self.client.create_app(data) self.assertEqual(create_resp.status, 201) id = create_resp.id resp, body = self.client.delete_app(id) self.assertEqual(resp.status, 202) self.assertEqual(body, '') time.sleep(2) self.client.delete_language_pack(lp_name)
def test_apps_get_all(self): data = apputils.get_sample_data() create_resp = self.client.create_app(data) self.assertEqual(create_resp.status, 201) resp, body = self.client.get( 'v1/apps', headers={'content-type': 'application/json'}) resp_data = yaml.load(body) self.assertEqual(resp.status, 200) id = create_resp.id filtered = [app for app in resp_data if app['id'] == id] self.assertEqual(filtered[0]['id'], id)
def test_app_get(self): data = apputils.get_sample_data() create_resp = self.client.create_app(data=data) self.assertEqual(create_resp.status, 201) id = create_resp.id resp, body = self.client.get( 'v1/apps/%s' % id, headers={'content-type': 'application/json'}) self.assertEqual(resp.status, 200) yaml_data = yaml.load(body) self._assert_app_data(yaml_data, data)
def test_apps_get_all(self): lp_name = self.client.create_lp() data = apputils.get_sample_data(languagepack=lp_name) create_resp = self.client.create_app(data) self.assertEqual(create_resp.status, 201) resp, body = self.client.get( 'v1/apps', headers={'content-type': 'application/json'}) resp_data = yaml.load(body) self.assertEqual(resp.status, 200) id = create_resp.id filtered = [app for app in resp_data if app['id'] == id] self.assertEqual(filtered[0]['id'], id) self.client.delete_app(id) time.sleep(2) self.client.delete_language_pack(lp_name)
def test_app_get(self): lp_name = self.client.create_lp() data = apputils.get_sample_data(languagepack=lp_name) create_resp = self.client.create_app(data=data) self.assertEqual(create_resp.status, 201) id = create_resp.id resp, body = self.client.get( 'v1/apps/%s' % id, headers={'content-type': 'application/json'}) self.assertEqual(resp.status, 200) yaml_data = yaml.load(body) self._assert_app_data(yaml_data, data) self.client.delete_app(create_resp.id) time.sleep(2) self.client.delete_language_pack(lp_name)
def test_trigger_post_with_empty_body(self): lp_name = self.client.create_lp() data = apputils.get_sample_data(languagepack=lp_name) resp = self.client.create_app(data=data) bdy = json.loads(resp.body) trigger_uri = bdy['trigger_uri'] # Using requests instead of self.client to test unauthenticated request resp = requests.post(trigger_uri) self.assertEqual(resp.status_code, 400) self.client.delete_created_apps() # since app delete is an async operation, wait few seconds for app # delete and then delete language pack (otherwise language pack # cannot be deleted) time.sleep(2) self.client.delete_created_lps()
def test_language_packs_delete_used_by_app(self): uuid, sample_lp = self._create_language_pack() sample_app = apputils.get_sample_data() sample_app["languagepack"] = sample_lp["name"] resp = self.client.create_app(data=sample_app) self.assertRaises(tempest_exceptions.Conflict, self.client.delete, 'v1/language_packs/%s' % uuid) bdy = json.loads(resp.body) self.client.delete_app(bdy["id"]) # Sleep for a few seconds to make sure plans are deleted. time.sleep(5) self._delete_language_pack(uuid)
def test_trigger_post(self): lp_name = self.client.create_lp() data = apputils.get_sample_data(languagepack=lp_name) resp = self.client.create_app(data=data) bdy = json.loads(resp.body) trigger_uri = bdy['trigger_uri'] # Using requests instead of self.client to test unauthenticated request status_url = 'https://api.github.com/repos/u/r/statuses/{sha}' body_dict = {'sender': {'url': 'https://api.github.com'}, 'pull_request': {'head': {'sha': 'asdf'}}, 'repository': {'statuses_url': status_url}} body = json.dumps(body_dict) resp = requests.post(trigger_uri, data=body) self.assertEqual(resp.status_code, 202) self.client.delete_created_apps() # since app delete is an async operation, wait few seconds for app # delete and then delete language pack (otherwise language pack # cannot be deleted) time.sleep(2) self.client.delete_created_lps()
def _create_app(self): data = apputils.get_sample_data() resp = self.client.create_app(data=data) bdy = json.loads(resp.body) trigger_uri = bdy['trigger_uri'] return trigger_uri
def test_app_create(self): data = apputils.get_sample_data() resp = self.client.create_app(data=data) self.assertEqual(resp.status, 201)