How to use create_response method in tempest

Best Python code snippet using tempest_python

test_libraries.py

Source:test_libraries.py Github

copy

Full Screen

1from base import api2from base.populators import (3 DatasetCollectionPopulator,4 DatasetPopulator,5 LibraryPopulator,6 TestsDatasets,7 wait_on_state8)9class LibrariesApiTestCase( api.ApiTestCase, TestsDatasets ):10 def setUp( self ):11 super( LibrariesApiTestCase, self ).setUp()12 self.dataset_populator = DatasetPopulator( self.galaxy_interactor )13 self.dataset_collection_populator = DatasetCollectionPopulator( self.galaxy_interactor )14 self.library_populator = LibraryPopulator( self )15 def test_create( self ):16 data = dict( name="CreateTestLibrary" )17 create_response = self._post( "libraries", data=data, admin=True )18 self._assert_status_code_is( create_response, 200 )19 library = create_response.json()20 self._assert_has_keys( library, "name" )21 assert library[ "name" ] == "CreateTestLibrary"22 def test_delete( self ):23 library = self.library_populator.new_library( "DeleteTestLibrary" )24 create_response = self._delete( "libraries/%s" % library[ "id" ], admin=True )25 self._assert_status_code_is( create_response, 200 )26 library = create_response.json()27 self._assert_has_keys( library, "deleted" )28 assert library[ "deleted" ] is True29 # Test undeleting30 data = dict( undelete='true' )31 create_response = self._delete( "libraries/%s" % library[ "id" ], data=data, admin=True )32 library = create_response.json()33 self._assert_status_code_is( create_response, 200 )34 assert library[ "deleted" ] is False35 def test_nonadmin( self ):36 # Anons can't create libs37 data = dict( name="CreateTestLibrary" )38 create_response = self._post( "libraries", data=data, admin=False, anon=True )39 self._assert_status_code_is( create_response, 403 )40 # Anons can't delete libs41 library = self.library_populator.new_library( "AnonDeleteTestLibrary" )42 create_response = self._delete( "libraries/%s" % library[ "id" ], admin=False, anon=True )43 self._assert_status_code_is( create_response, 403 )44 # Anons can't update libs45 data = dict( name="ChangedName", description="ChangedDescription", synopsis='ChangedSynopsis' )46 create_response = self._patch( "libraries/%s" % library[ "id" ], data=data, admin=False, anon=True )47 self._assert_status_code_is( create_response, 403 )48 def test_update( self ):49 library = self.library_populator.new_library( "UpdateTestLibrary" )50 data = dict( name='ChangedName', description='ChangedDescription', synopsis='ChangedSynopsis' )51 create_response = self._patch( "libraries/%s" % library[ "id" ], data=data, admin=True )52 self._assert_status_code_is( create_response, 200 )53 library = create_response.json()54 self._assert_has_keys( library, 'name', 'description', 'synopsis' )55 assert library['name'] == 'ChangedName'56 assert library['description'] == 'ChangedDescription'57 assert library['synopsis'] == 'ChangedSynopsis'58 def test_create_private_library_permissions( self ):59 library = self.library_populator.new_library( "PermissionTestLibrary" )60 library_id = library[ "id" ]61 role_id = self.library_populator.user_private_role_id()62 self.library_populator.set_permissions( library_id, role_id )63 create_response = self._create_folder( library )64 self._assert_status_code_is( create_response, 200 )65 def test_create_dataset_denied( self ):66 library = self.library_populator.new_private_library( "ForCreateDatasets" )67 folder_response = self._create_folder( library )68 self._assert_status_code_is( folder_response, 200)69 folder_id = folder_response.json()[0]['id']70 history_id = self.dataset_populator.new_history()71 hda_id = self.dataset_populator.new_dataset( history_id, content="1 2 3" )['id']72 with self._different_user():73 payload = {'from_hda_id': hda_id}74 create_response = self._post( "folders/%s/contents" % folder_id, payload )75 self._assert_status_code_is( create_response, 403 )76 def test_create_dataset( self ):77 library = self.library_populator.new_private_library( "ForCreateDatasets" )78 payload, files = self.library_populator.create_dataset_request( library, file_type="txt", contents="create_test" )79 create_response = self._post( "libraries/%s/contents" % library[ "id" ], payload, files=files )80 self._assert_status_code_is( create_response, 200 )81 library_datasets = create_response.json()82 assert len( library_datasets ) == 183 library_dataset = library_datasets[ 0 ]84 def show():85 return self._get( "libraries/%s/contents/%s" % ( library[ "id" ], library_dataset[ "id" ] ) )86 wait_on_state( show, assert_ok=True )87 library_dataset = show().json()88 self._assert_has_keys( library_dataset, "peek", "data_type" )89 assert library_dataset[ "peek" ].find("create_test") >= 090 assert library_dataset[ "file_ext" ] == "txt", library_dataset[ "file_ext" ]91 def test_create_dataset_in_folder( self ):92 library = self.library_populator.new_private_library( "ForCreateDatasets" )93 folder_response = self._create_folder( library )94 self._assert_status_code_is( folder_response, 200)95 folder_id = folder_response.json()[0]['id']96 history_id = self.dataset_populator.new_history()97 hda_id = self.dataset_populator.new_dataset( history_id, content="1 2 3" )['id']98 payload = {'from_hda_id': hda_id}99 create_response = self._post( "folders/%s/contents" % folder_id, payload )100 self._assert_status_code_is( create_response, 200 )101 library_datasets = create_response.json()102 assert len( library_datasets ) == 1103 def test_create_datasets_in_library_from_collection( self ):104 library = self.library_populator.new_private_library( "ForCreateDatasetsFromCollection" )105 folder_response = self._create_folder( library )106 self._assert_status_code_is( folder_response, 200)107 folder_id = folder_response.json()[0]['id']108 history_id = self.dataset_populator.new_history()109 hdca_id = self.dataset_collection_populator.create_list_in_history( history_id, contents=["xxx", "yyy"] ).json()["id"]110 payload = {'from_hdca_id': hdca_id, 'create_type': 'file', 'folder_id': folder_id}111 create_response = self._post( "libraries/%s/contents" % library['id'], payload )112 self._assert_status_code_is(create_response, 200)113 def test_create_datasets_in_folder_from_collection( self ):114 library = self.library_populator.new_private_library( "ForCreateDatasetsFromCollection" )115 history_id = self.dataset_populator.new_history()116 hdca_id = self.dataset_collection_populator.create_list_in_history( history_id, contents=["xxx", "yyy"] ).json()["id"]117 folder_response = self._create_folder( library )118 self._assert_status_code_is( folder_response, 200)119 folder_id = folder_response.json()[0]['id']120 payload = {'from_hdca_id': hdca_id}121 create_response = self._post( "folders/%s/contents" % folder_id, payload )122 self._assert_status_code_is( create_response, 200 )123 assert len(create_response.json()) == 2124 # Also test that anything different from a flat dataset collection list125 # is refused126 hdca_pair_id = self.dataset_collection_populator.create_list_of_pairs_in_history( history_id).json()['id']127 payload = {'from_hdca_id': hdca_pair_id}128 create_response = self._post( "folders/%s/contents" % folder_id, payload )129 self._assert_status_code_is( create_response, 501 )130 assert create_response.json()['err_msg'] == 'Cannot add nested collections to library. Please flatten your collection first.'131 def _create_folder( self, library ):132 create_data = dict(133 folder_id=library[ "root_folder_id" ],134 create_type="folder",135 name="New Folder",136 )...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...12app.session_interface.db.create_all()13@app.route("/")14def hello_world():15 return "<p>Hello, World!</p>"16def create_response(status_code: int, success: bool, additional_data: dict = None, error: str = None):17 data = {"success": success}18 if additional_data:19 data |= additional_data20 if error:21 data |= {"error": error}22 return json.dumps(data), status_code23@app.route("/sayac")24def sayac():25 if "sayac" in session:26 print(f"Eski sayaç: {session['sayac']}")27 session["sayac"] += 128 else:29 session["sayac"] = 030 print(f"Yeni sayaç: {session['sayac']}")31 return str(session["sayac"])32@app.route("/check_session")33def check_session():34 if "username" not in session:35 return create_response(401, False, error="Giriş yapılı değil!")36 return create_response(200, True, {"username": session["username"], "user_type": session["user_type"], "id": session["user_id"]})37@app.route("/logout")38def logout():39 session.clear()40 return create_response(200, True)41@app.route("/initial")42def initial():43 if "username" not in session:44 return create_response(401, False, error="Giriş yapılı değil!")45 try:46 return create_response(200, True, additional_data={47 "users": get_all_users()[1],48 "books": get_all_books()[1],49 "plan_to_read": get_all_plan_to_read()[1],50 "read_books": get_all_read_books()[1]51 })52 except Exception as e:53 return create_response(500, False, error=str(e))54@app.route("/login", methods=['POST'])55def login():56 try:57 data = request.get_json()58 username = data["username"]59 password = data["password"]60 status, user = get_user(username)61 if not status:62 return create_response(500, False, error=user)63 if not user:64 return create_response(401, False, error="Kullanıcı adı kayıtlı değil!")65 if password != user["password"]:66 return create_response(401, False, error="Şifre yanlış!")67 session["user_id"] = user["id"]68 session["username"] = user["username"]69 session["user_type"] = user["user_type"]70 return create_response(200, True,71 additional_data={"username": user["username"], "user_type": user["user_type"],72 "id": user["id"]})73 except Exception as e:74 return create_response(500, False, error=str(e))75@app.route("/register", methods=['POST'])76def register():77 try:78 data = request.get_json()79 username = data["username"]80 password = data["password"]81 status, message = create_user(username, password)82 if not status:83 return create_response(400, False, error=message)84 status, user = get_user(username)85 session["user_id"] = user["id"]86 session["username"] = user["username"]87 return create_response(200, True,88 additional_data={"username": user["username"], "user_type": user["user_type"],89 "id": user["id"]})90 except Exception as e:91 return create_response(500, False, error=str(e))92@app.route("/add_to_plan_to_read", methods=['POST'])93def add_to_plan_to_read():94 try:95 if "user_id" not in session:96 return create_response(401, False, error="Giriş yapılı değil!")97 book_id = request.get_json()["bookId"]98 status, message = create_user_plan_to_read(session["user_id"], book_id)99 if not status:100 return create_response(400, False, error=message)101 return create_response(200, True, additional_data={102 "users": get_all_users()[1],103 "books": get_all_books()[1],104 "plan_to_read": get_all_plan_to_read()[1],105 "read_books": get_all_read_books()[1]106 })107 except Exception as e:108 return create_response(500, False, error=str(e))109@app.route("/remove_from_plan_to_read", methods=['DELETE'])110def remove_from_plan_to_read():111 try:112 if "user_id" not in session:113 return create_response(401, False, error="Giriş yapılı değil!")114 record_id = request.get_json()["recordId"]115 status, message = delete_record_by_id("user_plan_to_read", record_id)116 if not status:117 return create_response(400, False, error=message)118 return create_response(200, True, additional_data={119 "users": get_all_users()[1],120 "books": get_all_books()[1],121 "plan_to_read": get_all_plan_to_read()[1],122 "read_books": get_all_read_books()[1]123 })124 except Exception as e:125 return create_response(500, False, error=str(e))126@app.route("/add_to_read_books", methods=['POST'])127def add_to_read_books():128 try:129 if "user_id" not in session:130 return create_response(401, False, error="Giriş yapılı değil!")131 book_id = request.get_json()["bookId"]132 rating = request.get_json()["rating"]133 status, message = create_user_read_book(session["user_id"], book_id, int(rating))134 if not status:135 return create_response(400, False, error=message)136 return create_response(200, True, additional_data={137 "users": get_all_users()[1],138 "books": get_all_books()[1],139 "plan_to_read": get_all_plan_to_read()[1],140 "read_books": get_all_read_books()[1]141 })142 except Exception as e:143 return create_response(500, False, error=str(e))144@app.route("/remove_from_read_books", methods=['DELETE'])145def remove_from_read_books():146 try:147 if "user_id" not in session:148 return create_response(401, False, error="Giriş yapılı değil!")149 record_id = request.get_json()["recordId"]150 status, message = delete_record_by_id("user_read_books", record_id)151 if not status:152 return create_response(400, False, error=message)153 return create_response(200, True, additional_data={154 "users": get_all_users()[1],155 "books": get_all_books()[1],156 "plan_to_read": get_all_plan_to_read()[1],157 "read_books": get_all_read_books()[1]158 })159 except Exception as e:160 return create_response(500, False, error=str(e))161@app.route('/images/<path:path>')162def send_image(path):163 return send_from_directory('images', path)164if __name__ == '__main__':...

Full Screen

Full Screen

test_resolvers.py

Source:test_resolvers.py Github

copy

Full Screen

1"""Integration tests for conda dependency resolution."""2import os3import shutil4from tempfile import mkdtemp5from base import integration_util6from base.populators import (7 DatasetPopulator,8)9GNUPLOT = {u'version': u'4.6', u'type': u'package', u'name': u'gnuplot'}10class CondaResolutionIntegrationTestCase(integration_util.IntegrationTestCase):11 """Test conda dependency resolution through API."""12 framework_tool_and_types = True13 @classmethod14 def handle_galaxy_config_kwds(cls, config):15 cls.conda_tmp_prefix = mkdtemp()16 config["use_cached_dependency_manager"] = True17 config["conda_auto_init"] = True18 config["conda_prefix"] = os.path.join(cls.conda_tmp_prefix, 'conda')19 @classmethod20 def tearDownClass(cls):21 """Shutdown Galaxy server and cleanup temp directory."""22 shutil.rmtree(cls.conda_tmp_prefix)23 cls._test_driver.tear_down()24 cls._app_available = False25 def test_dependency_before_install( self ):26 """27 Test that dependency is not installed (response['dependency_type'] == 'null').28 """29 data = GNUPLOT30 create_response = self._get( "dependency_resolvers/dependency", data=data, admin=True )31 self._assert_status_code_is( create_response, 200 )32 response = create_response.json()33 assert response['dependency_type'] is None and response['exact']34 def test_dependency_install( self ):35 """36 Test installation of GNUPLOT dependency.37 """38 data = GNUPLOT39 create_response = self._post( "dependency_resolvers/dependency", data=data, admin=True )40 self._assert_status_code_is( create_response, 200 )41 response = create_response.json()42 self._assert_dependency_type(response)43 def test_dependency_install_not_exact(self):44 """45 Test installation of gnuplot with a version that does not exist.46 Sh47 """48 data = GNUPLOT.copy()49 data['version'] = '4.9999'50 create_response = self._post("dependency_resolvers/dependency", data=data, admin=True)51 self._assert_status_code_is(create_response, 200)52 response = create_response.json()53 self._assert_dependency_type(response, exact=False)54 def test_dependency_status_installed_exact( self ):55 """56 GET request to dependency_resolvers/dependency with GNUPLOT dependency.57 Should be installed through conda (response['dependency_type'] == 'conda').58 """59 data = GNUPLOT60 create_response = self._get( "dependency_resolvers/dependency", data=data, admin=True )61 self._assert_status_code_is( create_response, 200 )62 response = create_response.json()63 self._assert_dependency_type(response)64 def test_legacy_r_mapping( self ):65 """66 """67 tool_id = "legacy_R"68 dataset_populator = DatasetPopulator(self.galaxy_interactor)69 history_id = dataset_populator.new_history()70 endpoint = "tools/%s/install_dependencies" % tool_id71 data = {'id': tool_id}72 create_response = self._post(endpoint, data=data, admin=True)73 self._assert_status_code_is( create_response, 200 )74 payload = dataset_populator.run_tool_payload(75 tool_id=tool_id,76 inputs={},77 history_id=history_id,78 )79 create_response = self._post( "tools", data=payload )80 self._assert_status_code_is( create_response, 200 )81 dataset_populator.wait_for_history( history_id, assert_ok=True )82 def test_dependency_status_installed_not_exact( self ):83 """84 GET request to dependency_resolvers/dependency with GNUPLOT dependency.85 Should be installed through conda (response['dependency_type'] == 'conda'),86 but version 4.9999 does not exist.87 """88 data = GNUPLOT.copy()89 data['version'] = '4.9999'90 create_response = self._get( "dependency_resolvers/dependency", data=data, admin=True )91 self._assert_status_code_is( create_response, 200 )92 response = create_response.json()93 self._assert_dependency_type(response, exact=False)94 def test_conda_install_through_tools_api( self ):95 tool_id = 'mulled_example_multi_1'96 endpoint = "tools/%s/install_dependencies" % tool_id97 data = {'id': tool_id}98 create_response = self._post(endpoint, data=data, admin=True)99 self._assert_status_code_is( create_response, 200 )100 response = create_response.json()101 assert any([True for d in response if d['dependency_type'] == 'conda'])102 endpoint = "tools/%s/build_dependency_cache" % tool_id103 create_response = self._post(endpoint, data=data, admin=True)104 self._assert_status_code_is( create_response, 200 )105 def test_uninstall_through_tools_api(self):106 tool_id = 'mulled_example_multi_1'107 endpoint = "tools/%s/dependencies" % tool_id108 data = {'id': tool_id}109 create_response = self._post(endpoint, data=data, admin=True)110 self._assert_status_code_is( create_response, 200 )111 response = create_response.json()112 assert any([True for d in response if d['dependency_type'] == 'conda'])113 endpoint = "tools/%s/dependencies" % tool_id114 create_response = self._delete(endpoint, data=data, admin=True)115 self._assert_status_code_is(create_response, 200)116 response = create_response.json()117 assert not [True for d in response if d['dependency_type'] == 'conda']118 def test_conda_clean( self ):119 endpoint = 'dependency_resolvers/clean'120 create_response = self._post(endpoint, data={}, admin=True)121 self._assert_status_code_is(create_response, 200)122 response = create_response.json()123 assert response == "OK"124 def _assert_dependency_type(self, response, type='conda', exact=True):125 if 'dependency_type' not in response:126 raise Exception("Response [%s] did not contain key 'dependency_type'" % response)127 dependency_type = response['dependency_type']128 assert dependency_type == type, "Dependency type [%s] not the expected value [%s]" % (dependency_type, type)129 if 'exact' not in response:130 raise Exception("Response [%s] did not contain key 'exact'" % response)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful