How to use create_user_role method in tempest

Best Python code snippet using tempest_python

test_users_api.py

Source:test_users_api.py Github

copy

Full Screen

...102 request_data, create_resp = create_valid_user(client)103 user_id = create_resp.json['user']["user_id"]104 get_resp = client.get(f"/users/{user_id+1}")105 assert get_resp.status_code == 404106def create_user_role(client, user_role="Admin"):107 request_data = dict(role_name=user_role)108 resp = client.post("/users/roles", json=request_data)109 assert resp.status_code == 200110 return request_data, resp111def test_create_and_get_user_role(client):112 request_data, create_resp = create_user_role(client)113 role_id = create_resp.json['user_role']['role_id']114 assert role_id >= 0115 resp = client.get(f"/users/roles/{role_id}")116 assert resp.status_code == 200117 assert resp.json['user_role']['role_name'] == request_data['role_name']118 assert resp.json['user_role']['role_id'] == role_id119def test_update_user_role(client):120 request_data, create_resp = create_user_role(client)121 role_id = create_resp.json['user_role']['role_id']122 assert role_id >= 0123 request_data['role_name'] = "Administrator"124 resp = client.post(f"/users/roles/{role_id}", json=request_data)125 assert resp.status_code == 200126 assert resp.json['user_role']['role_name'] == request_data['role_name']127 assert resp.json['user_role']['role_id'] == role_id128 resp = client.get(f"/users/roles/{role_id}")129 assert resp.json['user_role']['role_name'] == request_data['role_name']130def test_update_roles_for_user(client):131 _, admin_resp = create_user_role(client, user_role="Admin")132 _, patient_resp = create_user_role(client, user_role="Patient")133 admin_id = admin_resp.json['user_role']['role_id']134 patient_id = patient_resp.json['user_role']['role_id']135 request_data = dict(136 first_name="Jack",137 last_name="Karowac",138 dob="1997-03-17",139 role_ids=[admin_id, patient_id],140 email="username",141 password="1234"142 )143 resp = client.post("/users", json=request_data)144 assert resp.status_code == 200145 roles = resp.json['user']['roles']146 assert len(roles) == len(request_data['role_ids'])147 role_ids = set([r['role_id'] for r in roles])148 expected_ids = set(request_data['role_ids'])149 assert role_ids == expected_ids150 user_id = resp.json['user']['user_id']151 # Removing patient role152 request_data['role_ids'] = [admin_id]153 resp = client.post(f"/users/{user_id}", json=request_data)154 assert resp.status_code == 200155 roles = resp.json['user']['roles']156 assert len(roles) == len(request_data['role_ids'])157 role_ids = set([r['role_id'] for r in roles])158 expected_ids = set(request_data['role_ids'])159 assert role_ids == expected_ids160 # # Remove admin role, add patient role161 request_data['role_ids'] = [patient_id]162 resp = client.post(f"/users/{user_id}", json=request_data)163 assert resp.status_code == 200164 roles = resp.json['user']['roles']165 assert len(roles) == len(request_data['role_ids'])166 role_ids = set([r['role_id'] for r in roles])167 expected_ids = set(request_data['role_ids'])168 assert role_ids == expected_ids169 # # Remove all roles170 request_data['role_ids'] = []171 resp = client.post(f"/users/{user_id}", json=request_data)172 assert resp.status_code == 200173 roles = resp.json['user']['roles']174 assert len(roles) == len(request_data['role_ids'])175 role_ids = set([r['role_id'] for r in roles])176 expected_ids = set(request_data['role_ids'])177 assert role_ids == expected_ids178 # # Add back both roles179 request_data['role_ids'] = [admin_id, patient_id]180 resp = client.post(f"/users/{user_id}", json=request_data)181 assert resp.status_code == 200182 roles = resp.json['user']['roles']183 assert len(roles) == len(request_data['role_ids'])184 role_ids = set([r['role_id'] for r in roles])185 expected_ids = set(request_data['role_ids'])186 assert role_ids == expected_ids187def test_create_patient_with_relationship(client):188 _, create_resp = create_user_role(client, user_role="Doctor")189 assert create_resp.status_code == 200190 doctor_role = create_resp.json['user_role']['role_id']191 _, create_resp = create_user_role(client, user_role="Patient")192 assert create_resp.status_code == 200193 patient_role = create_resp.json['user_role']['role_id']194 _, resp = create_valid_user(client, username="Doctor", role_ids=[doctor_role])195 assert resp.status_code == 200196 doctor = resp.json['user']197 request_data = dict(198 first_name="Jack",199 last_name="Karowac",200 dob="1997-03-17",201 email="Patient",202 password="1234",203 role_ids=[patient_role],204 medical_staff_ids=[doctor['user_id']]205 )206 resp = client.post("/users", json=request_data)207 assert resp.status_code == 200208 assert 'medical_staff' in resp.json['user']209 assert len(resp.json['user']['medical_staff']) == 1210 assert resp.json['user']['medical_staff'][0]['user_id'] == doctor['user_id']211def test_no_duplicate_usernames(client):212 _, create_resp = create_user_role(client, user_role="Doctor")213 assert create_resp.status_code == 200214 doctor_role = create_resp.json['user_role']['role_id']215 _, resp = create_user(client, username="Doctor", role_ids=[doctor_role])216 assert resp.status_code == 200217 _, resp = create_user(client, username="Doctor", role_ids=[doctor_role])218 assert resp.status_code == 409219 _, resp = create_user(client, username="Doctor2", role_ids=[doctor_role])220 assert resp.status_code == 200221def test_update_patient_with_relationship(client):222 _, create_resp = create_user_role(client, user_role="Doctor")223 assert create_resp.status_code == 200224 doctor_role = create_resp.json['user_role']['role_id']225 _, create_resp = create_user_role(client, user_role="Patient")226 assert create_resp.status_code == 200227 patient_role = create_resp.json['user_role']['role_id']228 _, resp = create_valid_user(client, username="Doctor", role_ids=[doctor_role])229 assert resp.status_code == 200230 doctor = resp.json['user']231 request_data = dict(232 first_name="Jack",233 last_name="Karowac",234 dob="1997-03-17",235 email="Patient",236 password="1234",237 role_ids=[patient_role]238 )239 resp = client.post("/users", json=request_data)...

Full Screen

Full Screen

roles_test.py

Source:roles_test.py Github

copy

Full Screen

...37 def test_get_all_user_roles_nousers(self):38 get_roles = roles.get_all_user_roles(self.datastore_client)39 self.assertEqual(get_roles, {})40 def test_get_all_user_roles(self):41 result = roles.create_user_role(self.datastore_client, self.USER_HASH)42 self.assertTrue(result)43 get_roles = roles.get_all_user_roles(self.datastore_client)44 self.assertEqual(get_roles, {self.USER_HASH:['user']})45 def test_get_user_role_nouser(self):46 with self.assertRaises(MissingUserError):47 roles.get_user_role(self.datastore_client, self.USER_HASH)48 def test_get_user_role(self):49 result = roles.create_user_role(self.datastore_client, self.USER_HASH)50 self.assertTrue(result)51 get_roles = roles.get_user_role(self.datastore_client, self.USER_HASH)52 self.assertEqual(get_roles, ['user'])53 def test_create_user_role_exists(self):54 result = roles.create_user_role(self.datastore_client, self.USER_HASH)55 self.assertTrue(result)56 result = roles.create_user_role(self.datastore_client, self.USER_HASH)57 self.assertFalse(result)58 def test_update_user_role_nouser(self):59 result = roles.update_user_role(self.datastore_client, self.USER_HASH, {})60 self.assertFalse(result)61 def test_update_user_role(self):62 result = roles.create_user_role(self.datastore_client, self.USER_HASH)63 self.assertTrue(result)64 result = roles.update_user_role(self.datastore_client, self.USER_HASH, ['admin'])65 self.assertTrue(result)66 get_roles = roles.get_user_role(self.datastore_client, self.USER_HASH)67 self.assertEqual(get_roles, ['admin'])68 def test_delete_user_role_nouser(self):69 result = roles.delete_user_role(self.datastore_client, self.USER_HASH)70 self.assertFalse(result)71 def test_delete_user_role(self):72 result = roles.create_user_role(self.datastore_client, self.USER_HASH)73 self.assertTrue(result)74 result = roles.delete_user_role(self.datastore_client, self.USER_HASH)75 self.assertTrue(result)76 get_roles = roles.get_all_user_roles(self.datastore_client)...

Full Screen

Full Screen

user_role_router.py

Source:user_role_router.py Github

copy

Full Screen

...10 prefix='/role',11 tags=["Web/user_role"]12)13@router.post('/')14def create_user_role(request_user_role: user_role_schema.UserRole, db: Session = Depends(get_db)):15 return user_role_repo.create_user_role(request_user_role, db)16@router.get('/')17def get_user_role(18 db: Session = Depends(get_db),19 current_user: power_user_schema.ShowPowerUser = Security(20 get_current_user,21 scopes=[Role.ADMIN["name"], Role.SUPER_ADMIN["name"]],22 ),23):...

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