Best Python code snippet using autotest_python
test_admin.py
Source:test_admin.py
...4from dohq_artifactory.admin import Project5from dohq_artifactory.admin import RepositoryLocal6from dohq_artifactory.admin import User7class TestUser:8 def test_create_delete(self, artifactory):9 user_name = "test_create_delete_user"10 # Remove if user exist11 test_user = artifactory.find_user(user_name)12 if test_user is not None:13 test_user.delete()14 test_user = User(15 artifactory=artifactory,16 name=user_name,17 email="test_user@example.com",18 password="Pa55w@rd",19 profile_updatable=True,20 )21 # CREATE22 test_user.create()23 assert artifactory.find_user(user_name) is not None24 # DELETE25 test_user.delete()26 assert artifactory.find_user(user_name) is None27 def test_create_update(self, artifactory):28 user_name = "test_create_update_user"29 # Remove if user exist30 test_user = artifactory.find_user(user_name)31 if test_user is not None:32 test_user.delete()33 test_user = User(34 artifactory=artifactory,35 name=user_name,36 email="test_user@example.com",37 password="oldPa55w@rd",38 )39 # CREATE40 test_user.create()41 assert artifactory.find_user(user_name) is not None42 # UPDATE43 test_user = artifactory.find_user(user_name) # type: User44 test_user.password = "oldPa55w@rd"45 current_pwd = test_user.encryptedPassword46 test_user.password = "newPa55w@rd"47 test_user.update()48 new_pwd = test_user.encryptedPassword49 assert new_pwd != current_pwd, "Password did not change!"50 # DELETE51 test_user.delete()52 assert artifactory.find_user(user_name) is None53 def test_add_to_group(self, group1, user1):54 # type: (Group, User) -> None55 user1.add_to_group(group1)56 user1.update()57 assert "group1" in user1.raw["groups"]58class TestGroup:59 def test_create_delete(self, artifactory):60 name = "test_create_delete_group"61 # Remove if exist62 test_group = artifactory.find_group(name)63 if test_group is not None:64 test_group.delete()65 test_group = Group(artifactory=artifactory, name=name)66 # CREATE67 test_group.create()68 assert artifactory.find_group(name) is not None69 # DELETE70 test_group.delete()71 assert artifactory.find_group(name) is None72 def test_create_delete_with_user(self, artifactory):73 name = "test_adding_user_to_group"74 users = ["admin"]75 # Remove if exist76 test_group = artifactory.find_group(name)77 if test_group is not None:78 test_group.delete()79 test_group = Group(artifactory=artifactory, name=name)80 # CREATE81 test_group.users = users82 test_group.create()83 del test_group84 test_group = artifactory.find_group(name)85 assert test_group is not None86 test_group.read()87 assert test_group.users == users88 # DELETE89 test_group.delete()90 assert artifactory.find_group(name) is None91class TestLocalRepositories:92 def test_create_delete(self, artifactory):93 name = "test-debian-repo"94 # Remove if exist95 test_repo = artifactory.find_repository_local(name)96 if test_repo is not None:97 test_repo.delete()98 test_repo = RepositoryLocal(99 artifactory=artifactory, name=name, package_type=RepositoryLocal.DEBIAN100 )101 # CREATE102 test_repo.create()103 assert artifactory.find_repository_local(name) is not None104 assert test_repo.raw["enableDebianSupport"], "Repository is not Debian"105 # DELETE106 test_repo.delete()107 assert artifactory.find_repository_local(name) is None108class TestTargetPermission:109 def test_create_delete(self, artifactory):110 name = "create_delete_permission"111 # Remove if exist112 test_permission = artifactory.find_permission_target(name)113 if test_permission is not None:114 test_permission.delete()115 test_permission = PermissionTarget(artifactory=artifactory, name=name)116 # CREATE117 test_permission.create()118 assert artifactory.find_permission_target(name) is not None119 # DELETE120 test_permission.delete()121 assert artifactory.find_permission_target(name) is None122 def test_add_repositories(self, permission, repo1, repo2):123 # type: (PermissionTarget, RepositoryLocal, RepositoryLocal) -> None124 permission.add_repository(repo1, repo2)125 permission.update()126 assert "repo1" in permission.raw["repositories"]127 assert "repo2" in permission.raw["repositories"]128 repositories = permission.repositories129 assert "repo1" in [repositories[0].name, repositories[1].name]130 def test_add_user_group(self, permission, user1, user2, group1):131 # type: (PermissionTarget, User, User, Group) -> None132 permission.add_user(user1, PermissionTarget.ROLE_DEPLOY)133 permission.update()134 assert "user1" in permission.raw["principals"]["users"]135 assert (136 PermissionTarget.ADMIN not in permission.raw["principals"]["users"]["user1"]137 )138 permission.add_user(user2, PermissionTarget.ADMIN)139 permission.update()140 assert [PermissionTarget.ADMIN] == permission.raw["principals"]["users"][141 "user2"142 ]143 permission.add_group(group1, PermissionTarget.READ)144 permission.update()145 assert "group1" in permission.raw["principals"]["groups"]146class TestProject:147 def test_create_delete(self, artifactory_token):148 # Illegal project key length; valid length: 3 <= key <= 6149 # Name must start with a lowercase letter and only contain lowercase150 # letters and digits.Name151 project_key = "t1k1"152 display_name = "test_create_delete_display_name"153 # Remove if project exist154 test_project = artifactory_token.find_project(project_key)155 if test_project is not None:156 test_project.delete()157 test_project = Project(158 artifactory=artifactory_token,159 project_key=project_key,160 display_name=display_name,161 )...
test_parallel.py
Source:test_parallel.py
...8from db_mapping import *9from dao import dao,DataException10count = 111class TestCustomer(unittest.TestCase):12 def test_create_delete(self):13 for i in range(count):14 c = Customer("Test")15 dao.customer_dao.save(c)16 id = c.customer_id17 dao.customer_dao.delete(c)18 try:19 dao.customer_dao.find_by_id(id)20 self.fail()21 except NoResultFound as ex:22 pass23class TestOperationDefinition(unittest.TestCase):24 def test_create_delete(self):25 for i in range(count):26 c = OperationDefinition()27 c.description = "Alpha"28 c.short_id = "AL"29 dao.operation_definition_dao.save(c)30 id = c.operation_definition_id31 dao.operation_definition_dao.delete(c)32 try:33 dao.operation_definition_dao.find_by_id(id)34 self.fail()35 except NoResultFound as ex:36 pass37class TestEmployee(unittest.TestCase):38 def test_create_delete(self):39 for i in range(count):40 c = Employee()41 c.fullname = "Alpha"42 dao.employee_dao.save(c)43 id = c.employee_id44 dao.employee_dao.delete(c.employee_id)45 try:46 dao.employee_dao.find_by_id(id)47 self.fail()48 except NoResultFound as ex:49 pass50class TestOrder(unittest.TestCase):51 def test_create_delete(self):52 customer = Customer("Test")53 dao.customer_dao.save(customer)54 print((customer.customer_id))55 for i in range(count):56 c = Order()57 c.description = "alpha"58 c.customer = customer59 dao.order_dao.save(c)60 id = c.order_id61 try:62 dao.customer_dao.delete(customer.customer_id)63 self.fail()64 except DataException as ex:65 pass...
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!!