def test_create_new_person_w_no_role(self, selenium): """Check newly created person is on Admin People widget""" expected_person = entities_factory.PeopleFactory().create( system_wide_role=roles.NO_ROLE) actual_person = admin_webui_service.PeopleAdminWebUiService( selenium).create_new_person(expected_person) self.general_equal_assert(expected_person, actual_person)
def add_user(url_origin): """If two processes log in as a new user at the same time, the second login may fail because of a race condition in dev code (user_generator.py). We workaround this issue by creating a user not in parallel as this issue is considered not worth to fix by developers. """ from lib.entities import entities_factory import json from lib.service.rest.template_provider import TemplateProvider from lib.service.rest import session_pool environment.app_url = url_origin environment.app_url = urlparse.urljoin(environment.app_url, "/") session = requests.Session() test_utils.wait_for( lambda: session.get(environment.app_url).status_code == OK_CODE, constants.timeouts.TWO_MIN_USER_WAIT * 4) test_utils.wait_for(lambda: session.get(url_module.Urls().gae_login( users.FAKE_SUPER_USER)).status_code == OK_CODE) test_utils.wait_for( lambda: session.get(url_module.Urls().login).status_code == OK_CODE) person_dict = entities_factory.PeopleFactory().create( is_add_rest_attrs=True, **{}).__dict__ url = environment.app_url + "api/people" body = json.dumps([ TemplateProvider.generate_template_as_dict(json_tmpl_name='person', **person_dict) ]).encode("string-escape") test_utils.wait_for(lambda: session.post( url=url, data=body, headers=session_pool.BASIC_HEADERS).status_code == OK_CODE)
def get_person(self): """Get person from people tree item.""" fields = self._root.elements(class_name="span12") filled_fields = [i.text.splitlines() for i in fields if not i.span(class_name="empty-message").exists] person_data = {k.lower(): v for (k, v) in filled_fields} return entities_factory.PeopleFactory().create( system_wide_role=person_data["system authorizations"], **person_data)
def ppl_data(self, selenium): """Create person and return test data.""" if not self.__class__.data: expected_person = entities_factory.PeopleFactory().create( system_wide_role=roles.NO_ROLE) ppl_admin_service = admin_webui_service.PeopleAdminWebUiService( selenium) self.__class__.data = { "exp_person": expected_person, "exp_ppl_count": ppl_admin_service.ppl_count + 1, "act_person": ppl_admin_service.create_new_person(expected_person), "act_ppl_count": ppl_admin_service.ppl_count } return self.__class__.data