Best Python code snippet using robotframework-appiumlibrary_python
test_collaboration.py
Source:test_collaboration.py
...12from server.test.seed import collaboration_ai_computing_uuid, ai_computing_name, uva_research_name, john_name, \13 ai_computing_short_name, uuc_teachers_name, read_image, collaboration_uva_researcher_uuid, service_group_wiki_name114from server.test.seed import uuc_secret, uuc_name15class TestCollaboration(AbstractTest):16 def _find_by_identifier(self, with_basic_auth=True):17 res = self.get("/api/collaborations/find_by_identifier",18 query_data={"identifier": collaboration_ai_computing_uuid},19 with_basic_auth=with_basic_auth)20 return res["collaboration"]21 def test_find_by_identifier(self):22 self.login("urn:james")23 res = self.get("/api/collaborations/find_by_identifier",24 query_data={"identifier": collaboration_ai_computing_uuid},25 with_basic_auth=False)26 collaboration = res["collaboration"]27 self.assertEqual(2, len(collaboration["services"]))28 service_emails = res["service_emails"]29 self.assertEqual(4, len(service_emails))30 def test_search(self):31 self.login("urn:john")32 res = self.get("/api/collaborations/search", query_data={"q": "ComPuti"}, with_basic_auth=False)33 self.assertEqual(1, len(res))34 def test_search_forbidden(self):35 self.login("urn:roger")36 self.get("/api/collaborations/search", query_data={"q": "ComPuti"}, response_status_code=403,37 with_basic_auth=False)38 def test_search_wildcard(self):39 self.login("urn:john")40 res = self.get("/api/collaborations/search", query_data={"q": "*"})41 self.assertTrue(len(res) > 0)42 def test_members(self):43 members = self.get("/api/collaborations/members", query_data={"identifier": collaboration_ai_computing_uuid})44 self.assertEqual(2, len(members))45 member = self.find_by_name(members, john_name)46 self.assertEqual("urn:john", member["uid"])47 self.assertEqual("John Doe", member["name"])48 self.assertFalse("email" in member)49 def test_members_forbidden(self):50 self.login("urn:mary")51 self.get("/api/collaborations/members", query_data={"identifier": collaboration_ai_computing_uuid},52 response_status_code=403, with_basic_auth=False)53 def test_collaboration_new(self):54 organisation_id = Organisation.query.filter(Organisation.name == uuc_name).one().id55 self.login("urn:john")56 mail = self.app.mail57 with mail.record_messages() as outbox:58 collaboration = self.post("/api/collaborations",59 body={60 "name": "new_collaboration",61 "description": "new_collaboration",62 "organisation_id": organisation_id,63 "administrators": ["the@ex.org", "that@ex.org"],64 "short_name": "new_short_name",65 "current_user_admin": False66 }, with_basic_auth=False)67 self.assertIsNotNone(collaboration["id"])68 self.assertIsNotNone(collaboration["identifier"])69 self.assertEqual("uuc:new_short_name", collaboration["global_urn"])70 self.assertEqual(STATUS_ACTIVE, collaboration["status"])71 self.assertEqual(2, len(outbox))72 count = self._collaboration_membership_count(collaboration)73 self.assertEqual(0, count)74 def test_collaboration_new_with_current_user_admin(self):75 wiki_service_group = self.find_entity_by_name(ServiceGroup, service_group_wiki_name1)76 wiki_service_group.auto_provision_members = True77 db.session.merge(wiki_service_group)78 db.session.commit()79 organisation = Organisation.query.filter(Organisation.name == uuc_name).one()80 self.login("urn:john")81 collaboration = self.post("/api/collaborations",82 body={83 "name": "new_collaboration",84 "description": "new_collaboration",85 "organisation_id": organisation.id,86 "administrators": ["the@ex.org", "that@ex.org"],87 "short_name": "new_short_name",88 "current_user_admin": True89 }, with_basic_auth=False)90 count = self._collaboration_membership_count(collaboration)91 self.assertEqual(1, count)92 service_groups = flatten([service.service_groups for service in organisation.services])93 collaboration_groups = self.find_entity_by_name(Collaboration, collaboration["name"]).groups94 self.assertEqual(2, len(service_groups))95 self.assertEqual(2, len(collaboration_groups))96 service_group_names = sorted([sg.name for sg in service_groups])97 co_group_names = sorted([co.name for co in collaboration_groups])98 self.assertListEqual(service_group_names, co_group_names)99 wiki_group = self.find_entity_by_name(Group, co_group_names[0])100 self.assertEqual(1, len(wiki_group.collaboration_memberships))101 self.assertEqual("urn:john", wiki_group.collaboration_memberships[0].user.uid)102 def test_collaboration_without_default_current_user_admin(self):103 organisation_id = Organisation.query.filter(Organisation.name == uuc_name).one().id104 self.login("urn:john")105 collaboration = self.post("/api/collaborations",106 body={107 "name": "new_collaboration",108 "description": "new_collaboration",109 "organisation_id": organisation_id,110 "administrators": [],111 "short_name": "new_short_name",112 "current_user_admin": False113 }, with_basic_auth=False)114 count = self._collaboration_membership_count(collaboration)115 self.assertEqual(0, count)116 def test_collaboration_with_tags(self):117 organisation_id = Organisation.query.filter(Organisation.name == uuc_name).one().id118 tags = [119 {'label': 'tag_uuc', 'value': Tag.query.filter(Tag.tag_value == "tag_uuc").one().id},120 {'label': 'new_tag_created', 'value': 'new_tag_created', '__isNew__': True}121 ]122 self.login("urn:john")123 collaboration = self.post("/api/collaborations",124 body={125 "name": "new_collaboration",126 "description": "new_collaboration",127 "organisation_id": organisation_id,128 "administrators": [],129 "tags": tags,130 "short_name": "new_short_name",131 "current_user_admin": False132 }, with_basic_auth=False)133 collaboration = Collaboration.query.get(collaboration["id"])134 self.assertEqual(2, len(collaboration.tags))135 @staticmethod136 def _collaboration_membership_count(collaboration):137 return CollaborationMembership.query \138 .join(CollaborationMembership.user) \139 .filter(CollaborationMembership.collaboration_id == collaboration["id"]) \140 .filter(User.uid == "urn:john") \141 .count()142 def test_collaboration_no_organisation_context(self):143 self.login("urn:john")144 self.post("/api/collaborations",145 body={146 "name": "new_collaboration",147 "description": "new_collaboration",148 "administrators": ["the@ex.org", "that@ex.org"],149 "short_name": "new_short_name"150 }, with_basic_auth=False,151 response_status_code=400)152 def test_collaboration_new_no_organisation_admin(self):153 organisation_id = Organisation.query.filter(Organisation.name == uuc_name).one().id154 self.login("urn:peter")155 self.post("/api/collaborations",156 body={157 "name": "new_collaboration",158 "description": "new_collaboration",159 "organisation_id": organisation_id160 },161 with_basic_auth=False,162 response_status_code=403)163 def test_collaboration_update(self):164 collaboration_id = self._find_by_identifier()["id"]165 self.login()166 collaboration = self.get(f"/api/collaborations/{collaboration_id}", with_basic_auth=False)167 collaboration["name"] = "changed"168 collaboration["tags"] = [169 {'label': 'tag_orphan', 'value': Tag.query.filter(Tag.tag_value == "tag_orphan").one().id},170 {'label': 'new_tag_created', 'value': 'new_tag_created', '__isNew__': True}171 ]172 collaboration = self.put("/api/collaborations", body=collaboration)173 self.assertEqual("changed", collaboration["name"])174 collaboration = Collaboration.query.get(collaboration["id"])175 self.assertEqual(2, len(collaboration.tags))176 def test_collaboration_update_orphan_tag(self):177 collaboration = self.find_entity_by_name(Collaboration, ai_computing_name)178 self.login("urn:john")179 collaboration = self.get(f"/api/collaborations/{collaboration.id}", with_basic_auth=False)180 collaboration["tags"] = []181 self.put("/api/collaborations", body=collaboration)182 collaboration = self.find_entity_by_name(Collaboration, ai_computing_name)183 self.assertEqual(0, len(collaboration.tags))184 self.assertIsNone(Tag.query.filter(Tag.tag_value == "tag_uuc").first())185 def test_collaboration_update_with_logo(self):186 collaboration_id = self._find_by_identifier()["id"]187 self.login()188 collaboration = self.get(f"/api/collaborations/{collaboration_id}", with_basic_auth=False)189 collaboration["name"] = "changed"190 collaboration["logo"] = "https://bogus"191 self.put("/api/collaborations", body=collaboration)192 rows = db.session.execute(text(f"SELECT logo FROM collaborations WHERE id = {collaboration_id}"))193 self.assertEqual(1, rows.rowcount)194 for row in rows:195 self.assertFalse(row["logo"].startswith("http"))196 def test_collaboration_update_short_name(self):197 collaboration_id = self._find_by_identifier()["id"]198 self.login()199 collaboration = self.get(f"/api/collaborations/{collaboration_id}", with_basic_auth=False)200 collaboration["short_name"] = "changed"201 self.put("/api/collaborations", body=collaboration)202 collaboration = self.find_entity_by_name(Collaboration, ai_computing_name)203 self.assertEqual(1, len(collaboration.tags))204 for group in collaboration.groups:205 self.assertTrue("changed" in group.global_urn)206 def test_collaboration_delete(self):207 pre_count = Collaboration.query.count()208 collaboration = self._find_by_identifier()209 self.delete("/api/collaborations", primary_key=collaboration["id"])210 self.assertEqual(pre_count - 1, Collaboration.query.count())211 def test_collaboration_delete_no_admin(self):212 collaboration = self._find_by_identifier()213 self.login("urn:peter")214 response = self.client.delete(f"/api/collaborations/{collaboration['id']}")215 self.assertEqual(403, response.status_code)216 def test_collaboration_by_id_forbidden(self):217 collaboration = self._find_by_identifier(with_basic_auth=True)218 self.login("urn:peter")219 self.get(f"/api/collaborations/{collaboration['id']}", response_status_code=403, with_basic_auth=False)220 def test_collaboration_by_id_not_found(self):221 self.login("urn:john")222 self.get(f"/api/collaborations/{-1}", response_status_code=404, with_basic_auth=False)223 def test_non_existing_collaboration_by_id_not_found(self):224 self.login("urn:james")225 self.get("/api/collaborations/99999999999", response_status_code=403, with_basic_auth=False)226 def test_collaboration_all(self):227 collaborations = self.get("/api/collaborations/all")228 self.assertEqual(4, len(collaborations))229 def test_collaboration_by_id(self):230 collaboration_id = self._find_by_identifier()["id"]231 self.login()232 collaboration = self.get(f"/api/collaborations/{collaboration_id}", with_basic_auth=False)233 self.assertEqual(collaboration_id, collaboration["id"])234 self.assertEqual("UUC", collaboration["organisation"]["name"])235 self.assertTrue(len(collaboration["collaboration_memberships"]) >= 4)236 self.assertEqual(1, len(collaboration["invitations"]))237 def test_collaboration_by_id_service_connection_requests(self):238 collaboration_id = self.find_entity_by_name(Collaboration, uva_research_name).id239 self.login()240 collaboration = self.get(f"/api/collaborations/{collaboration_id}", with_basic_auth=False)241 service_connection_requests = collaboration["service_connection_requests"]242 self.assertEqual(1, len(service_connection_requests))243 def test_collaboration_by_id_api_call(self):244 collaboration_id = self._find_by_identifier()["id"]245 collaboration = self.get(f"/api/collaborations/{collaboration_id}",246 headers=API_AUTH_HEADER,247 with_basic_auth=False)248 self.assertEqual(collaboration_id, collaboration["id"])249 self.assertEqual("UUC", collaboration["organisation"]["name"])250 self.assertTrue(len(collaboration["collaboration_memberships"]) >= 4)251 def test_my_collaborations(self):252 self.login("urn:admin")253 my_collaborations = self.get("/api/collaborations")254 self.assertEqual(1, len(my_collaborations))255 collaboration = AbstractTest.find_by_name(my_collaborations, ai_computing_name)256 self.assertTrue("collaboration_memberships_count" in collaboration)257 self.assertTrue("invitations_count" in collaboration)258 collaboration = self.get(f"/api/collaborations/{collaboration['id']}")259 researcher = list(filter(lambda cm: cm["role"] == "member", collaboration["collaboration_memberships"]))[0]260 self.assertEqual("John Doe", researcher["user"]["name"])261 def test_my_collaborations_include_services(self):262 self.login("urn:admin")263 my_collaborations = self.get("/api/collaborations", query_data={"includeServices": True})264 self.assertEqual(1, len(my_collaborations))265 services = my_collaborations[0]266 self.assertTrue(len(services) > 0)267 def test_my_collaborations_no_admin(self):268 self.login("urn:james")269 my_collaborations = self.get("/api/collaborations")270 self.assertEqual(0, len(my_collaborations))271 def test_collaboration_name_exists(self):272 organisation_id = self.find_entity_by_name(Collaboration, ai_computing_name).organisation_id273 other_organisation_id = self.find_entity_by_name(Collaboration, uva_research_name).organisation_id274 res = self.get("/api/collaborations/name_exists", query_data={"name": ai_computing_name,275 "organisation_id": organisation_id})276 self.assertEqual(True, res)277 res = self.get("/api/collaborations/name_exists", query_data={"name": ai_computing_name,278 "organisation_id": other_organisation_id})279 self.assertEqual(False, res)280 res = self.get("/api/collaborations/name_exists",281 query_data={"name": ai_computing_name, "existing_collaboration": ai_computing_name.upper(),282 "organisation_id": organisation_id})283 self.assertEqual(False, res)284 res = self.get("/api/collaborations/name_exists", query_data={"name": "xyc",285 "organisation_id": organisation_id})286 self.assertEqual(False, res)287 res = self.get("/api/collaborations/name_exists", query_data={"name": "xyc", "existing_collaboration": "xyc",288 "organisation_id": organisation_id})289 self.assertEqual(False, res)290 def test_collaboration_short_name_exists(self):291 organisation_id = self.find_entity_by_name(Collaboration, ai_computing_name).organisation_id292 other_organisation_id = self.find_entity_by_name(Collaboration, uva_research_name).organisation_id293 res = self.get("/api/collaborations/short_name_exists", query_data={"short_name": ai_computing_short_name,294 "organisation_id": organisation_id})295 self.assertEqual(True, res)296 res = self.get("/api/collaborations/short_name_exists", query_data={"short_name": ai_computing_short_name,297 "organisation_id": other_organisation_id})298 self.assertEqual(False, res)299 res = self.get("/api/collaborations/short_name_exists",300 query_data={"short_name": ai_computing_name,301 "existing_collaboration": ai_computing_short_name.upper(),302 "organisation_id": organisation_id})303 self.assertEqual(False, res)304 res = self.get("/api/collaborations/short_name_exists", query_data={"short_name": "xyc",305 "organisation_id": organisation_id})306 self.assertEqual(False, res)307 res = self.get("/api/collaborations/short_name_exists",308 query_data={"short_name": "xyc", "existing_collaboration": "xyc",309 "organisation_id": organisation_id})310 self.assertEqual(False, res)311 def test_collaboration_invites(self):312 pre_count = Invitation.query.count()313 self.login("urn:john")314 collaboration = self._find_by_identifier()315 collaboration_id = collaboration["id"]316 groups = [group["id"] for group in collaboration["groups"]]317 mail = self.app.mail318 with mail.record_messages() as outbox:319 self.put("/api/collaborations/invites", body={320 "collaboration_id": collaboration_id,321 "administrators": ["new@example.org", "pop@example.org"],322 "message": "Please join",323 "groups": groups,324 "membership_expiry_date": int(time.time()),325 "intended_role": "admin"326 })327 post_count = Invitation.query.count()328 self.assertEqual(2, len(outbox))329 self.assertEqual(pre_count + 2, post_count)330 invitation = Invitation.query.filter(Invitation.invitee_email == "new@example.org").first()331 self.assertEqual("admin", invitation.intended_role)332 self.assertEqual(2, len(invitation.groups))333 self.assertIsNotNone(invitation.membership_expiry_date)334 def test_collaboration_invites_no_intended_role(self):335 self.login("urn:john")336 collaboration_id = self._find_by_identifier()["id"]337 self.put("/api/collaborations/invites", body={338 "collaboration_id": collaboration_id,339 "administrators": ["new@example.org"],340 "intended_role": ""341 })342 invitation = Invitation.query.filter(Invitation.invitee_email == "new@example.org").first()343 self.assertEqual("member", invitation.intended_role)344 def test_collaboration_invites_preview(self):345 self.login("urn:john")346 collaboration_id = self._find_by_identifier()["id"]347 res = self.post("/api/collaborations/invites-preview", body={348 "collaboration_id": collaboration_id,349 "message": "Please join",350 "intended_role": "admin"351 })352 self.assertTrue("Please join" in res["html"])353 def test_collaboration_invites_preview_member(self):354 self.login("urn:john")355 collaboration_id = self._find_by_identifier()["id"]356 res = self.post("/api/collaborations/invites-preview", body={357 "collaboration_id": collaboration_id358 })359 self.assertFalse("administrative duties" in res["html"])360 self.assertFalse("Personal" in res["html"])361 def test_collaboration_lite_by_id(self):362 collaboration_id = self._find_by_identifier()["id"]363 self.login("urn:jane")364 collaboration = self.get(f"/api/collaborations/lite/{collaboration_id}")365 self.assertEqual(ai_computing_name, collaboration["name"])366 def test_collaboration_lite_no_member(self):367 collaboration_id = self._find_by_identifier()["id"]368 self.login("urn:roger")369 self.get(f"/api/collaborations/lite/{collaboration_id}", response_status_code=403)370 def test_collaboration_lite_not_existing_collaboration(self):371 self.login("urn:roger")372 self.get("/api/collaborations/lite/99999999999", response_status_code=403)373 def test_collaboration_lite_disclose_member_information(self):374 self.login("urn:sarah")375 collaboration_id = self.find_entity_by_name(Collaboration, ai_computing_name).id376 collaboration = self.get(f"/api/collaborations/lite/{collaboration_id}")377 memberships = collaboration["collaboration_memberships"]378 self.assertEqual(4, len(memberships))379 user = memberships[0]["user"]380 self.assertTrue("email" in user)381 def test_collaboration_lite_disclose_email_information(self):...
elementfinder.py
Source:elementfinder.py
...20 raise ValueError("Element locator with prefix '" + prefix + "' is not supported")21 (tag, constraints) = self._get_tag_and_constraints(tag)22 return strategy(browser, criteria, tag, constraints)23 # Strategy routines, private24 def _find_by_identifier(self, browser, criteria, tag, constraints):25 elements = browser.find_elements_by_id(criteria)26 elements.extend(browser.find_elements_by_name(criteria))27 return self._filter_elements(elements, tag, constraints)28 def _find_by_id(self, browser, criteria, tag, constraints):29 return self._filter_elements(30 browser.find_elements_by_id(criteria),31 tag, constraints)32 def _find_by_name(self, browser, criteria, tag, constraints):33 return self._filter_elements(34 browser.find_elements_by_name(criteria),35 tag, constraints)36 def _find_by_xpath(self, browser, criteria, tag, constraints):37 return self._filter_elements(38 browser.find_elements_by_xpath(criteria),...
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!!