Best Python code snippet using tempest_python
test_database.py
Source:test_database.py
...339 self.assertIsNotNone(self, self.taskdb)340 @classmethod341 def tearDownClass(self):342 self.taskdb.conn.drop_database(self.taskdb.database.name)343 def test_create_project(self):344 self.assertNotIn('test_create_project', self.taskdb.projects)345 self.taskdb._create_project('test_create_project')346 self.assertIn('test_create_project', self.taskdb.projects)347@unittest.skipIf(os.environ.get('IGNORE_MONGODB') or os.environ.get('IGNORE_ALL'), 'no mongodb server for test.')348class TestMongoDBProjectDB(ProjectDBCase, unittest.TestCase):349 @classmethod350 def setUpClass(self):351 self.projectdb = database.connect_database(352 'mongodb+projectdb://localhost/pyspider_test_projectdb'353 )354 self.assertIsNotNone(self, self.projectdb)355 @classmethod356 def tearDownClass(self):357 self.projectdb.conn.drop_database(self.projectdb.database.name)358@unittest.skipIf(os.environ.get('IGNORE_MONGODB') or os.environ.get('IGNORE_ALL'), 'no mongodb server for test.')359class TestMongoDBResultDB(ResultDBCase, unittest.TestCase):360 @classmethod361 def setUpClass(self):362 self.resultdb = database.connect_database(363 'mongodb+resultdb://localhost/pyspider_test_resultdb'364 )365 self.assertIsNotNone(self, self.resultdb)366 @classmethod367 def tearDownClass(self):368 self.resultdb.conn.drop_database(self.resultdb.database.name)369 def test_create_project(self):370 self.assertNotIn('test_create_project', self.resultdb.projects)371 self.resultdb._create_project('test_create_project')372 self.assertIn('test_create_project', self.resultdb.projects)373@unittest.skipIf(os.environ.get('IGNORE_MYSQL') or os.environ.get('IGNORE_ALL'), 'no mysql server for test.')374class TestSQLAlchemyMySQLTaskDB(TaskDBCase, unittest.TestCase):375 @classmethod376 def setUpClass(self):377 self.taskdb = database.connect_database(378 'sqlalchemy+mysql+mysqlconnector+taskdb://root@localhost/pyspider_test_taskdb'379 )380 self.assertIsNotNone(self, self.taskdb)381 @classmethod382 def tearDownClass(self):383 self.taskdb.engine.execute('DROP DATABASE pyspider_test_taskdb')384@unittest.skipIf(os.environ.get('IGNORE_MYSQL') or os.environ.get('IGNORE_ALL'), 'no mysql server for test.')385class TestSQLAlchemyMySQLProjectDB(ProjectDBCase, unittest.TestCase):386 @classmethod387 def setUpClass(self):388 self.projectdb = database.connect_database(389 'sqlalchemy+mysql+mysqlconnector+projectdb://root@localhost/pyspider_test_projectdb'390 )391 self.assertIsNotNone(self, self.projectdb)392 @classmethod393 def tearDownClass(self):394 self.projectdb.engine.execute('DROP DATABASE pyspider_test_projectdb')395@unittest.skipIf(os.environ.get('IGNORE_MYSQL') or os.environ.get('IGNORE_ALL'), 'no mysql server for test.')396class TestSQLAlchemyMySQLResultDB(ResultDBCase, unittest.TestCase):397 @classmethod398 def setUpClass(self):399 self.resultdb = database.connect_database(400 'sqlalchemy+mysql+mysqlconnector+resultdb://root@localhost/pyspider_test_resultdb'401 )402 self.assertIsNotNone(self, self.resultdb)403 @classmethod404 def tearDownClass(self):405 self.resultdb.engine.execute('DROP DATABASE pyspider_test_resultdb')406class TestSQLAlchemyTaskDB(TaskDBCase, unittest.TestCase):407 @classmethod408 def setUpClass(self):409 self.taskdb = database.connect_database(410 'sqlalchemy+sqlite+taskdb://'411 )412 self.assertIsNotNone(self, self.taskdb)413 @classmethod414 def tearDownClass(self):415 del self.taskdb416class TestSQLAlchemyProjectDB(ProjectDBCase, unittest.TestCase):417 @classmethod418 def setUpClass(self):419 self.projectdb = database.connect_database(420 'sqlalchemy+sqlite+projectdb://'421 )422 self.assertIsNotNone(self, self.projectdb)423 @classmethod424 def tearDownClass(self):425 del self.projectdb426class TestSQLAlchemyResultDB(ResultDBCase, unittest.TestCase):427 @classmethod428 def setUpClass(self):429 self.resultdb = database.connect_database(430 'sqlalchemy+sqlite+resultdb://'431 )432 self.assertIsNotNone(self, self.resultdb)433 @classmethod434 def tearDownClass(self):435 del self.resultdb436@unittest.skipIf(os.environ.get('IGNORE_POSTGRESQL') or os.environ.get('IGNORE_ALL'), 'no postgresql server for test.')437class TestPGTaskDB(TaskDBCase, unittest.TestCase):438 @classmethod439 def setUpClass(self):440 self.taskdb = database.connect_database(441 'sqlalchemy+postgresql+taskdb://postgres@127.0.0.1:5432/pyspider_test_taskdb'442 )443 self.assertIsNotNone(self, self.taskdb)444 self.tearDownClass()445 @classmethod446 def tearDownClass(self):447 for project in self.taskdb.projects:448 self.taskdb.drop(project)449@unittest.skipIf(os.environ.get('IGNORE_POSTGRESQL') or os.environ.get('IGNORE_ALL'), 'no postgresql server for test.')450class TestPGProjectDB(ProjectDBCase, unittest.TestCase):451 @classmethod452 def setUpClass(self):453 self.projectdb = database.connect_database(454 'sqlalchemy+postgresql+projectdb://postgres@127.0.0.1:5432/pyspider_test_projectdb'455 )456 self.assertIsNotNone(self, self.projectdb)457 self.tearDownClass()458 @classmethod459 def tearDownClass(self):460 for project in self.projectdb.get_all(fields=['name']):461 self.projectdb.drop(project['name'])462@unittest.skipIf(os.environ.get('IGNORE_POSTGRESQL') or os.environ.get('IGNORE_ALL'), 'no postgresql server for test.')463class TestPGResultDB(ResultDBCase, unittest.TestCase):464 @classmethod465 def setUpClass(self):466 self.resultdb = database.connect_database(467 'sqlalchemy+postgresql+resultdb://postgres@127.0.0.1/pyspider_test_resultdb'468 )469 self.assertIsNotNone(self, self.resultdb)470 self.tearDownClass()471 @classmethod472 def tearDownClass(self):473 for project in self.resultdb.projects:474 self.resultdb.drop(project)475@unittest.skipIf(os.environ.get('IGNORE_REDIS') or os.environ.get('IGNORE_ALL'), 'no redis server for test.')476class TestRedisTaskDB(TaskDBCase, unittest.TestCase):477 @classmethod478 def setUpClass(self):479 self.taskdb = database.connect_database('redis+taskdb://localhost:6379/15')480 self.assertIsNotNone(self, self.taskdb)481 self.taskdb.__prefix__ = 'testtaskdb_'482 @classmethod483 def tearDownClass(self):484 for project in self.taskdb.projects:485 self.taskdb.drop(project)486@unittest.skipIf(os.environ.get('IGNORE_ELASTICSEARCH') or os.environ.get('IGNORE_ALL'), 'no elasticsearch server for test.')487class TestESProjectDB(ProjectDBCase, unittest.TestCase):488 @classmethod489 def setUpClass(self):490 self.projectdb = database.connect_database(491 'elasticsearch+projectdb://127.0.0.1:9200/?index=test_pyspider_projectdb'492 )493 self.assertIsNotNone(self, self.projectdb)494 assert self.projectdb.index == 'test_pyspider_projectdb'495 @classmethod496 def tearDownClass(self):497 self.projectdb.es.indices.delete(index='test_pyspider_projectdb', ignore=[400, 404])498@unittest.skipIf(os.environ.get('IGNORE_ELASTICSEARCH') or os.environ.get('IGNORE_ALL'), 'no elasticsearch server for test.')499class TestESResultDB(ResultDBCase, unittest.TestCase):500 @classmethod501 def setUpClass(self):502 self.resultdb = database.connect_database(503 'elasticsearch+resultdb://127.0.0.1:9200/?index=test_pyspider_resultdb'504 )505 self.assertIsNotNone(self, self.resultdb)506 assert self.resultdb.index == 'test_pyspider_resultdb'507 @classmethod508 def tearDownClass(self):509 self.resultdb.es.indices.delete(index='test_pyspider_resultdb', ignore=[400, 404])510 def test_15_save(self):511 self.resultdb.refresh()512 def test_30_select(self):513 for i in range(5):514 self.resultdb.save('test_project', 'test_taskid-%d' % i,515 'test_url', 'result-%d' % i)516 self.resultdb.refresh()517 ret = list(self.resultdb.select('test_project'))518 self.assertEqual(len(ret), 6)519 ret = list(self.resultdb.select('test_project', limit=4))520 self.assertEqual(len(ret), 4)521 for ret in self.resultdb.select('test_project', fields=('url', ), limit=1):522 self.assertIn('url', ret)523 self.assertNotIn('result', ret)524 def test_35_select_limit(self):525 pass526 def test_z20_update_projects(self):527 self.resultdb.refresh()528 self.assertIn('drop_project2', self.resultdb.projects)529 self.assertNotIn('drop_project3', self.resultdb.projects)530@unittest.skipIf(os.environ.get('IGNORE_ELASTICSEARCH') or os.environ.get('IGNORE_ALL'), 'no elasticsearch server for test.')531class TestESTaskDB(TaskDBCase, unittest.TestCase):532 @classmethod533 def setUpClass(self):534 self.taskdb = database.connect_database(535 'elasticsearch+taskdb://127.0.0.1:9200/?index=test_pyspider_taskdb'536 )537 self.assertIsNotNone(self, self.taskdb)538 assert self.taskdb.index == 'test_pyspider_taskdb'539 @classmethod540 def tearDownClass(self):541 self.taskdb.es.indices.delete(index='test_pyspider_taskdb', ignore=[400, 404])542@unittest.skipIf(os.environ.get('IGNORE_COUCHDB') or os.environ.get('IGNORE_ALL'), 'no couchdb server for test.')543class TestCouchDBProjectDB(ProjectDBCase, unittest.TestCase):544 @classmethod545 def setUpClass(self):546 # create a test admin user547 self.projectdb = database.connect_database(548 'couchdb+projectdb://localhost:5984/'549 )550 self.assertIsNotNone(self, self.projectdb)551 @classmethod552 def tearDownClass(self):553 # remove the test admin user554 self.projectdb.drop_database()555@unittest.skipIf(os.environ.get('IGNORE_COUCHDB') or os.environ.get('IGNORE_ALL'), 'no couchdb server for test.')556class TestCouchDBResultDB(ResultDBCase, unittest.TestCase):557 @classmethod558 def setUpClass(self):559 # create a test admin user560 self.resultdb = database.connect_database(561 'couchdb+resultdb://localhost:5984/'562 )563 self.assertIsNotNone(self, self.resultdb)564 @classmethod565 def tearDownClass(self):566 # remove the test admin user567 self.resultdb.drop_database()568 def test_create_project(self):569 self.assertNotIn('test_create_project', self.resultdb.projects)570 self.resultdb._create_project('test_create_project')571 self.assertIn('test_create_project', self.resultdb.projects)572@unittest.skipIf(os.environ.get('IGNORE_COUCHDB') or os.environ.get('IGNORE_ALL'), 'no couchdb server for test.')573class TestCouchDBTaskDB(TaskDBCase, unittest.TestCase):574 @classmethod575 def setUpClass(self):576 # create a test admin user577 import requests578 self.taskdb = database.connect_database(579 'couchdb+taskdb://localhost:5984/'580 )581 self.assertIsNotNone(self, self.taskdb)582 @classmethod583 def tearDownClass(self):584 # remove the test admin user585 import requests586 from requests.auth import HTTPBasicAuth587 self.taskdb.drop_database()588 def test_create_project(self):589 self.assertNotIn('test_create_project', self.taskdb.projects)590 self.taskdb._create_project('test_create_project')591 self.assertIn('test_create_project', self.taskdb.projects)592if __name__ == '__main__':...
test_project.py
Source:test_project.py
...206 metadata=(('token', self.owner_token),)207 )208 self.project_groups.append(self.project_group)209 self.assertEqual(self.project_group.name, name)210 def test_create_project(self, project_group_id=None):211 if project_group_id is None:212 self.test_create_project_group()213 name = f'project-{utils.random_string()}'214 params = {215 'name': name,216 'tags': {217 utils.random_string(4): utils.random_string(4),218 utils.random_string(4):utils.random_string(4)219 },220 'domain_id': self.domain.domain_id221 }222 if project_group_id is None:223 params['project_group_id'] = self.project_group.project_group_id224 else:225 params['project_group_id'] = project_group_id226 self.project = self.identity_v1.Project.create(227 params,228 metadata=(('token', self.owner_token),)229 )230 self.projects.append(self.project)231 self.assertEqual(self.project.name, name)232 def test_update_project_name(self):233 self.test_create_project()234 name = 'blah-blah-blah'235 params = {236 'project_id': self.project.project_id,237 'name': name,238 'domain_id': self.domain.domain_id239 }240 project = self.identity_v1.Project.update(241 params,242 metadata=(('token', self.owner_token),)243 )244 self.assertEqual(project.name, name)245 def test_update_project_tags(self):246 self.test_create_project()247 tags = {248 'update_key': 'update_value'249 }250 params = {251 'project_id': self.project.project_id,252 'tags': tags,253 'domain_id': self.domain.domain_id254 }255 project = self.identity_v1.Project.update(256 params,257 metadata=(('token', self.owner_token),)258 )259 project_info = MessageToDict(project)260 self.assertEqual(project_info['tags'], tags)261 def test_update_project_project_group(self):262 self.test_create_project()263 self.test_create_project_group()264 params = {265 'project_id': self.project.project_id,266 'project_group_id': self.project_group.project_group_id,267 'domain_id': self.domain.domain_id268 }269 project = self.identity_v1.Project.update(270 params,271 metadata=(('token', self.owner_token),)272 )273 self.assertEqual(project.project_group_info.project_group_id, self.project_group.project_group_id)274 def test_delete_project_group_exist_project(self):275 self.test_create_project()276 params = {277 'project_group_id': self.project_group.project_group_id,278 'domain_id': self.domain.domain_id279 }280 with self.assertRaises(Exception) as e:281 self.identity_v1.ProjectGroup.delete(282 params,283 metadata=(('token', self.owner_token),)284 )285 self.assertIn("ERROR_EXIST_RESOURCE", str(e.exception))286 def test_delete_project_not_exist(self):287 self.test_create_project()288 params = {289 'project_id': 'blah-blah-blah',290 'domain_id': self.domain.domain_id291 }292 with self.assertRaises(Exception):293 self.identity_v1.Project.delete(294 params,295 metadata=(('token', self.owner_token),)296 )297 def test_get_project(self):298 self.test_create_project()299 project = self.identity_v1.Project.get(300 {301 'project_id': self.project.project_id,302 'domain_id': self.domain.domain_id303 },304 metadata=(('token', self.owner_token),)305 )306 self.assertEqual(project.project_id, self.project.project_id)307 def test_get_project_not_exist(self):308 self.test_create_project()309 params = {310 'project_id': 'blah-blah',311 'domain_id': self.domain.domain_id312 }313 with self.assertRaises(Exception):314 self.identity_v1.Project.get(315 params,316 metadata=(('token', self.owner_token),)317 )318 def test_list_projects_project_group_id(self):319 self.test_create_project_group()320 num = 10321 for x in range(num):322 self.test_create_project(self.project_group.project_group_id)323 projects = self.identity_v1.Project.list(324 {325 'project_group_id': self.project_group.project_group_id,326 'domain_id': self.domain.domain_id327 },328 metadata=(('token', self.owner_token),)329 )330 self.assertEqual(projects.total_count, num)331 def test_list_projects_minimal(self):332 num = 5333 for x in range(num):334 self.test_create_project()335 query = {336 'minimal': True337 }338 projects = self.identity_v1.Project.list(339 {340 'query': query,341 'domain_id': self.domain.domain_id342 },343 metadata=(('token', self.owner_token),)344 )345 self.assertEqual(projects.total_count, num)346 def test_list_projects_name(self):347 self.test_create_project_group()348 num = 10349 for x in range(num):350 self.test_create_project(self.project_group.project_group_id)351 projects = self.identity_v1.Project.list(352 {353 'name': 'blah-blah',354 'domain_id': self.domain.domain_id355 },356 metadata=(('token', self.owner_token),)357 )358 self.assertEqual(projects.total_count, 0)359 def test_list_projects_with_query(self):360 self.test_create_project_group()361 num = 10362 for x in range(num):363 self.test_create_project(self.project_group.project_group_id)364 query = {365 'filter': [366 {367 'k': 'project_group_id',368 'v': self.project_group.project_group_id,369 'o': 'eq'370 }371 ],372 }373 projects = self.identity_v1.Project.list(374 {375 'query': query,376 'domain_id': self.domain.domain_id377 },378 metadata=(('token', self.owner_token),)379 )380 self.assertEqual(projects.total_count, num)381 def test_add_project_member(self, project=None, user=None):382 if user is None:383 user = self._test_create_user()384 self._test_create_role('PROJECT')385 if project is None:386 self.test_create_project()387 project = self.project388 params = {389 'project_id': project.project_id,390 'user_id': user.user_id,391 'role_id': self.role.role_id,392 'labels': ['aaa', 'bbb'],393 'domain_id': self.domain.domain_id394 }395 project_member = self.identity_v1.Project.add_member(396 params,397 metadata=(('token', self.owner_token),)398 )399 self._print_data(project_member, 'test_add_project_member')400 self.assertEqual(project_member.resource_type, 'identity.User')401 self.assertEqual(project_member.resource_id, user.user_id)402 self.assertEqual(project_member.role_info.role_id, self.role.role_id)403 def test_add_project_member_exist_member(self):404 self.test_add_project_member()405 params = {406 'project_id': self.project.project_id,407 'user_id': self.user.user_id,408 'role_id': self.role.role_id,409 'domain_id': self.domain.domain_id410 }411 with self.assertRaises(Exception) as cm:412 self.identity_v1.Project.add_member(413 params,414 metadata=(('token', self.owner_token),)415 )416 self.assertIn("ERROR_DUPLICATE_RESOURCE_IN_PROJECT", str(cm.exception))417 def test_modify_project_member(self):418 self.test_add_project_member()419 labels = ['developer', 'operator']420 params = {421 'project_id': self.project.project_id,422 'user_id': self.user.user_id,423 'labels': labels,424 'domain_id': self.domain.domain_id425 }426 project_member = self.identity_v1.Project.modify_member(427 params,428 metadata=(('token', self.owner_token),)429 )430 self._print_data(project_member, 'test_modify_project_member')431 self.assertEqual(sorted(project_member.labels), sorted(labels))432 def test_modify_project_member_not_exist_member(self):433 self.test_add_project_member()434 params = {435 'project_id': self.project.project_id,436 'user_id': 'blah-blah-blah-blah',437 'domain_id': self.domain.domain_id438 }439 with self.assertRaises(Exception):440 self.identity_v1.Project.modify_member(441 params,442 metadata=(('token', self.owner_token),)443 )444 def test_remove_project_member(self):445 self.test_add_project_member()446 self.identity_v1.Project.remove_member(447 {448 'project_id': self.project.project_id,449 'user_id': self.user.user_id,450 'domain_id': self.domain.domain_id451 },452 metadata=(('token', self.owner_token),)453 )454 project_members = self.identity_v1.Project.list_members(455 {456 'project_id': self.project.project_id,457 'domain_id': self.domain.domain_id458 },459 metadata=(('token', self.owner_token),)460 )461 self.assertEqual(0, project_members.total_count)462 def test_remove_project_member_not_exist_member(self):463 self.test_add_project_member()464 params = {465 'project_id': self.project.project_id,466 'user_id': 'blah-blah',467 'domain_id': self.domain.domain_id468 }469 with self.assertRaises(Exception):470 self.identity_v1.Project.remove_member(471 params,472 metadata=(('token', self.owner_token),)473 )474 def test_list_project_members_with_user_id(self):475 self.test_create_project()476 self._test_create_user()477 self._test_create_user()478 self._test_create_user()479 for user in self.users:480 self.test_add_project_member(self.project, user)481 params = {482 'project_id': self.project.project_id,483 'user_id': self.user.user_id,484 'domain_id': self.domain.domain_id485 }486 response = self.identity_v1.Project.list_members(487 params,488 metadata=(('token', self.owner_token),)489 )490 self.assertEqual(1, response.total_count)491 def test_list_project_members_not_exist_user(self):492 self.test_create_project()493 self._test_create_user()494 self._test_create_user()495 self._test_create_user()496 for user in self.users:497 self.test_add_project_member(self.project, user)498 params = {499 'project_id': self.project.project_id,500 'user_id': 'TEST',501 'domain_id': self.domain.domain_id502 }503 response = self.identity_v1.Project.list_members(504 params,505 metadata=(('token', self.owner_token),)506 )507 self.assertEqual(0, response.total_count)508 def test_stat_project(self):509 self.test_create_project()510 self.test_create_project()511 self.test_add_project_member(self.projects[0])512 self.test_add_project_member(self.projects[0])513 self.test_add_project_member(self.projects[0])514 self.test_add_project_member(self.projects[1])515 self.test_add_project_member(self.projects[1])516 params = {517 'domain_id': self.domain.domain_id,518 'query': {519 'aggregate': [{520 'group': {521 'keys': [{522 'key': 'project_id',523 'name': 'Id'524 }],525 'fields': [{526 'operator': 'count',527 'name': 'Count'528 }]529 }530 }, {531 'sort': {532 'key': 'Count',533 'desc': True534 }535 }]536 }537 }538 result = self.identity_v1.Project.stat(539 params, metadata=(('token', self.owner_token),))540 self._print_data(result, 'test_stat_project')541 def test_stat_project_count(self):542 self.test_create_project()543 self.test_create_project()544 self.test_add_project_member(self.projects[0])545 self.test_add_project_member(self.projects[0])546 self.test_add_project_member(self.projects[0])547 self.test_add_project_member(self.projects[1])548 self.test_add_project_member(self.projects[1])549 params = {550 'domain_id': self.domain.domain_id,551 'query': {552 'aggregate': [{553 "count": {554 "name": "project_count"555 }556 }]557 }...
demoCase.py
Source:demoCase.py
...3# @File : demoCase.py4# Author: tian guang yuan5# Time : 2020/7/23 22:346from day7.pages.projectManager import ProjectManagerAcctionObj7def test_create_project():8 ProjectManagerAcctionObj.to_page()...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!