How to use _test_change_password method in tempest

Best Python code snippet using tempest_python

test_servers_client.py

Source:test_servers_client.py Github

copy

Full Screen

...265 rotation='fake-rotation',266 name='fake-name'267 )268 def test_change_password_with_str_body(self):269 self._test_change_password()270 def test_change_password_with_bytes_body(self):271 self._test_change_password(True)272 def _test_change_password(self, bytes_body=False):273 self.check_service_client_function(274 self.client.change_password,275 'tempest.lib.common.rest_client.RestClient.post',276 {},277 status=202,278 server_id=self.server_id,279 adminPass='fake-admin-pass'280 )281 def test_show_password_with_str_body(self):282 self._test_show_password()283 def test_show_password_with_bytes_body(self):284 self._test_show_password(True)285 def _test_show_password(self, bytes_body=False):286 self.check_service_client_function(...

Full Screen

Full Screen

test_views.py

Source:test_views.py Github

copy

Full Screen

...89 new_operator.is_cla_superuser, post_data.get("is_cla_superuser", new_operator.is_cla_superuser)90 )91 self.assertEqual(new_operator.user.is_staff, new_operator.is_manager or new_operator.is_cla_superuser)92 return new_operator93 def _test_change_password(self, loggedin_op_user, changing_op):94 logged_in = self.client.login(username=loggedin_op_user.username, password=loggedin_op_user.username)95 self.assertTrue(logged_in)96 # go to change password form97 change_url = reverse("admin:call_centre_operator_change", args=(changing_op.pk,))98 url = "%spassword/" % change_url99 response = self.client.get(url)100 self.assertEqual(response.status_code, 200)101 # change password102 post_data = {"password1": "123456789", "password2": "123456789"}103 # check104 post_response = self.client.post(url, data=post_data)105 self.assertRedirects(post_response, change_url)106 def _test_reset_lockout(self, loggedin_op_user, changing_op):107 logged_in = self.client.login(username=loggedin_op_user.username, password=loggedin_op_user.username)108 self.assertTrue(logged_in)109 # reset lockout110 change_url = reverse("admin:call_centre_operator_change", args=(changing_op.pk,))111 url = "%sreset-lockout/" % change_url112 response = self.client.post(url, follow=True)113 # check that everythin is OK114 self.assertEqual(response.status_code, 200)115 # CHANGE116 def test_op_manager_can_change_op_managers(self):117 loggedin_op = self.operators["op_manager1"]118 changing_op = self.operators["op_manager2"]119 # go to cla op manager2 change form120 # change changing_op.is_manager to False and save121 # check everything is OK122 post_data = {123 "username": changing_op.user.username,124 "first_name": "New Name",125 "last_name": "New Last Name",126 "email": "new_email@example.com",127 "is_manager": False,128 "_save": "Save",129 }130 self._test_change_form(loggedin_op.user, changing_op, should_see_is_cla_superuser=False, post_data=post_data)131 def test_op_manager_cant_change_cla_superusers(self):132 loggedin_op = self.operators["op_manager1"]133 changing_op = self.operators["op_superuser1"]134 # go to cla superusers change form135 logged_in = self.client.login(username=loggedin_op.user.username, password=loggedin_op.user.username)136 self.assertTrue(logged_in)137 # go to changing op change form138 url = reverse("admin:call_centre_operator_change", args=(changing_op.pk,))139 response = self.client.get(url)140 # check that get 404141 self.assertEqual(response.status_code, 403)142 def test_cla_superuser_can_change_cla_superusers(self):143 loggedin_op = self.operators["op_superuser1"]144 changing_op = self.operators["op_superuser2"]145 # go to op_superuser2 change form146 # change changing_op.is_cla_superuser to False and save147 # check everything is OK148 post_data = {149 "username": changing_op.user.username,150 "first_name": "New Name",151 "last_name": "New Last Name",152 "email": "new_email@example.com",153 "is_manager": True,154 "is_cla_superuser": False,155 "_save": "Save",156 }157 self._test_change_form(loggedin_op.user, changing_op, should_see_is_cla_superuser=True, post_data=post_data)158 def test_django_superuser_can_change_everything(self):159 loggedin_user = self.django_admin160 changing_op = self.operators["op_superuser2"]161 # go to op_superuser2 change form162 # change changing_op.is_cla_superuser to False and save163 # check everything is OK164 post_data = {165 "username": changing_op.user.username,166 "first_name": "New Name",167 "last_name": "New Last Name",168 "email": "new_email@example.com",169 "is_manager": True,170 "is_cla_superuser": False,171 "_save": "Save",172 }173 self._test_change_form(loggedin_user, changing_op, should_see_is_cla_superuser=True, post_data=post_data)174 # CREATE175 def test_op_manager_can_create_op_managers(self):176 loggedin_op = self.operators["op_manager1"]177 # go to op add form178 # set is_manager to True and save179 # check everything is OK180 post_data = {181 "username": get_random_string(),182 "password": "123456789",183 "password2": "123456789",184 "first_name": "New Name",185 "last_name": "New Last Name",186 "email": "new_email@example.com",187 "is_manager": True,188 "_save": "Save",189 }190 self._test_add_form(loggedin_op.user, should_see_is_cla_superuser=False, post_data=post_data)191 def test_cla_superuser_can_create_cla_superusers(self):192 loggedin_op = self.operators["op_superuser1"]193 # go to op add form194 # set is_cla_superuser to True and save195 # check everything is OK196 post_data = {197 "username": get_random_string(),198 "password": "123456789",199 "password2": "123456789",200 "first_name": "New Name",201 "last_name": "New Last Name",202 "email": "new_email@example.com",203 "is_manager": True,204 "is_cla_superuser": True,205 "_save": "Save",206 }207 self._test_add_form(loggedin_op.user, should_see_is_cla_superuser=True, post_data=post_data)208 def test_django_superuser_can_create_cla_superusers(self):209 loggedin_op_user = self.django_admin210 # go to op add form211 # set is_cla_superuser to True and save212 # check everything is OK213 post_data = {214 "username": get_random_string(),215 "password": "123456789",216 "password2": "123456789",217 "first_name": "New Name",218 "last_name": "New Last Name",219 "email": "new_email@example.com",220 "is_manager": True,221 "is_cla_superuser": True,222 "_save": "Save",223 }224 self._test_add_form(loggedin_op_user, should_see_is_cla_superuser=True, post_data=post_data)225 # RESET PASSWORD226 def test_op_manager_can_change_op_manager_password(self):227 loggedin_op = self.operators["op_manager1"]228 changing_op = self.operators["op_manager2"]229 self._test_change_password(loggedin_op.user, changing_op)230 def test_op_manager_cant_change_cla_superuser_password(self):231 loggedin_op = self.operators["op_manager1"]232 changing_op = self.operators["op_superuser1"]233 loggedin_op_user = loggedin_op.user234 logged_in = self.client.login(username=loggedin_op_user.username, password=loggedin_op_user.username)235 self.assertTrue(logged_in)236 # go to change password form237 change_url = reverse("admin:call_centre_operator_change", args=(changing_op.pk,))238 url = "%spassword/" % change_url239 response = self.client.get(url)240 self.assertEqual(response.status_code, 200)241 # try to change password242 post_data = {"password1": "123456789", "password2": "123456789"}243 # check that it's not possible244 post_response = self.client.post(url, data=post_data, follow=True)245 self.assertEqual(post_response.status_code, 403)246 def test_cla_superuser_can_change_cla_superuser_password(self):247 loggedin_op = self.operators["op_superuser1"]248 changing_op = self.operators["op_superuser2"]249 self._test_change_password(loggedin_op.user, changing_op)250 def test_django_superuser_can_change_cla_superuser_password(self):251 loggedin_op_user = self.django_admin252 changing_op = self.operators["op_superuser2"]253 self._test_change_password(loggedin_op_user, changing_op)254 # RESET LOCKOUT255 def test_op_manager_can_reset_op_manager_lockout(self):256 loggedin_op = self.operators["op_manager1"]257 changing_op = self.operators["op_manager2"]258 self._test_reset_lockout(loggedin_op.user, changing_op)259 def test_op_manager_cant_reset_cla_superuser_lockout(self):260 loggedin_op = self.operators["op_manager1"]261 changing_op = self.operators["op_superuser1"]262 loggedin_op_user = loggedin_op.user263 logged_in = self.client.login(username=loggedin_op_user.username, password=loggedin_op_user.username)264 self.assertTrue(logged_in)265 # try to reset lockout266 change_url = reverse("admin:call_centre_operator_change", args=(changing_op.pk,))267 url = "%sreset-lockout/" % change_url268 response = self.client.post(url, follow=True)269 # check that 403270 self.assertEqual(response.status_code, 403)271 def test_cla_superuser_can_reset_cla_superuser_lockout(self):272 loggedin_op = self.operators["op_superuser1"]273 changing_op = self.operators["op_superuser2"]274 self._test_reset_lockout(loggedin_op.user, changing_op)275 def test_django_superuser_can_reset_cla_superuser_lockout(self):276 loggedin_op_user = self.django_admin277 changing_op = self.operators["op_superuser2"]278 self._test_reset_lockout(loggedin_op_user, changing_op)279 # OPERATOR ORGANISATION280 def test_operator_manager_can_list_operators_of_same_organisation(self):281 loggedin_op = self.operators["foo_org_manager"]282 loggedin_op_user = loggedin_op.user283 self.client.login(username=loggedin_op_user.username, password=loggedin_op_user.username)284 bar_org_operators = ["bar_org_manager", "bar_org_op"]285 foo_org_operators = ["foo_org_manager", "foo_org_op"]286 operators_without_organisation = ["op", "op_manager1", "op_manager2", "op_superuser1", "op_superuser2"]287 url = reverse("admin:call_centre_operator_changelist")288 response = self.client.get(url, follow=True)289 for result in response.context_data["cl"].result_list:290 self.assertNotIn(result.user.username, bar_org_operators)291 self.assertIn(result.user.username, foo_org_operators + operators_without_organisation)292 def test_cla_superuser_can_list_all_operators_of_all_organisations(self):293 loggedin_op = self.operators["op_superuser1"]294 loggedin_op_user = loggedin_op.user295 self.client.login(username=loggedin_op_user.username, password=loggedin_op_user.username)296 url = reverse("admin:call_centre_operator_changelist")297 response = self.client.get(url, follow=True)298 for result in response.context_data["cl"].result_list:299 self.assertIn(result.user.username, self.operators.keys())300 def test_operator_manager_can_create_operators_of_same_organisation(self):301 loggedin_op = self.operators["foo_org_manager"]302 loggedin_op_user = loggedin_op.user303 self.client.login(username=loggedin_op_user.username, password=loggedin_op_user.username)304 post_data = self._get_operator_post_data()305 post_data["organisation"] = self.foo_organisation.id306 new_operator = self._test_add_form(loggedin_op.user, should_see_is_cla_superuser=False, post_data=post_data)307 self.assertEqual(self.foo_organisation.id, new_operator.organisation.id)308 def test_operator_manager_cannot_create_operators_of_another_organisation(self):309 loggedin_op = self.operators["foo_org_manager"]310 loggedin_op_user = loggedin_op.user311 self.client.login(username=loggedin_op_user.username, password=loggedin_op_user.username)312 post_data = self._get_operator_post_data()313 post_data["organisation"] = self.bar_organisation.id314 with self.assertRaises(AssertionError):315 self._test_add_form(loggedin_op.user, should_see_is_cla_superuser=False, post_data=post_data)316 def test_operator_manager_cannot_create_operators_without_organisation(self):317 loggedin_op = self.operators["foo_org_manager"]318 loggedin_op_user = loggedin_op.user319 self.client.login(username=loggedin_op_user.username, password=loggedin_op_user.username)320 post_data = self._get_operator_post_data()321 with self.assertRaises(AssertionError):322 self._test_add_form(loggedin_op.user, should_see_is_cla_superuser=False, post_data=post_data)323 def test_operator_manager_can_change_operators_of_same_organisation(self):324 loggedin_op = self.operators["foo_org_manager"]325 changing_op = self.operators["foo_org_op"]326 # go to cla op foo_org_op change form327 # change changing_op.first_name to something random and save328 # check everything is OK329 post_data = self._get_operator_post_data()330 post_data["username"] = changing_op.user.username331 post_data["first_name"] = get_random_string()332 post_data["organisation"] = changing_op.organisation.id333 self._test_change_form(loggedin_op.user, changing_op, should_see_is_cla_superuser=False, post_data=post_data)334 def test_operator_manager_cannot_change_operator_organisation_to_another_organisation(self):335 loggedin_op = self.operators["foo_org_manager"]336 changing_op = self.operators["foo_org_op"]337 # go to cla op foo_org_op change form338 # change changing_op.first_name to something random339 # change changing_op.organisation to another organisation and save340 # AssertionError should be raise by self._test_change_form341 post_data = self._get_operator_post_data()342 post_data["username"] = changing_op.user.username343 post_data["first_name"] = get_random_string()344 post_data["organisation"] = self.bar_organisation.id345 with self.assertRaises(AssertionError):346 self._test_change_form(347 loggedin_op.user, changing_op, should_see_is_cla_superuser=False, post_data=post_data348 )349 def test_cla_superadmin_can_change_operator_organisation(self):350 loggedin_op = self.operators["op_superuser1"]351 changing_op = self.operators["foo_org_op"]352 # go to cla op foo_org_op change form353 # change changing_op.first_name to something random354 # change changing_op.organisation to another organisation and save355 # check everything is OK356 post_data = self._get_operator_post_data()357 post_data["username"] = changing_op.user.username358 post_data["first_name"] = get_random_string()359 post_data["organisation"] = self.bar_organisation.id360 self._test_change_form(loggedin_op.user, changing_op, should_see_is_cla_superuser=True, post_data=post_data)361class CaseworkerAdminViewTestCase(TestCase):362 def setUp(self):363 super(CaseworkerAdminViewTestCase, self).setUp()364 def make_op(username, is_manager=False, is_cla_superuser=False):365 return make_recipe(366 "call_centre.operator",367 user__username=username,368 is_manager=is_manager,369 is_cla_superuser=is_cla_superuser,370 )371 def make_cw(**kwargs):372 return make_recipe("call_centre.caseworker", **kwargs)373 self.django_admin = make_user(is_staff=True, is_superuser=True)374 self.operators = {375 "op_manager1": make_op("op_manager1", is_manager=True),376 "op_superuser1": make_op("op_superuser1", is_manager=True, is_cla_superuser=True),377 "cw_1": make_cw(),378 }379 # setting password == username380 for user in [op.user for op in self.operators.values()] + [self.django_admin]:381 user.set_password(user.username)382 user.save()383 def _reload_obj(self, obj):384 return obj.__class__.objects.get(pk=obj.pk)385 def _do_add_change_form(self, url, loggedin_op_user, post_data):386 logged_in = self.client.login(username=loggedin_op_user.username, password=loggedin_op_user.username)387 self.assertTrue(logged_in)388 # go to add / change form389 response = self.client.get(url)390 self.assertEqual(response.status_code, 200)391 # add/change details and save392 post_response = self.client.post(url, data=post_data, follow=True)393 self.assertEqual(post_response.status_code, 200)394 def _test_change_form(self, loggedin_op_user, changing_cw, post_data):395 url = reverse("admin:call_centre_caseworker_change", args=(changing_cw.pk,))396 self._do_add_change_form(url, loggedin_op_user, post_data)397 # check db record398 changing_cw = self._reload_obj(changing_cw)399 op_user = changing_cw.user400 for field in ["username", "first_name", "last_name"]:401 self.assertEqual(getattr(op_user, field), post_data[field])402 self.assertTrue(changing_cw.user.is_staff)403 def _test_add_form(self, loggedin_op_user, post_data):404 num_cw = Caseworker.objects.count()405 url = reverse("admin:call_centre_caseworker_add")406 self._do_add_change_form(url, loggedin_op_user, post_data)407 # check that new caseworker created408 self.assertEqual(Caseworker.objects.count(), num_cw + 1)409 new_cw = Caseworker.objects.order_by("-created").first()410 # check db record411 cw_user = new_cw.user412 for field in ["username", "first_name", "last_name"]:413 self.assertEqual(getattr(cw_user, field), post_data[field])414 self.assertTrue(new_cw.user.is_staff)415 def _test_change_password(self, loggedin_op_user, changing_cw):416 logged_in = self.client.login(username=loggedin_op_user.username, password=loggedin_op_user.username)417 self.assertTrue(logged_in)418 # go to change password form419 change_url = reverse("admin:call_centre_caseworker_change", args=(changing_cw.pk,))420 url = "%spassword/" % change_url421 response = self.client.get(url)422 self.assertEqual(response.status_code, 200)423 # change password424 post_data = {"password1": "123456789", "password2": "123456789"}425 # check426 post_response = self.client.post(url, data=post_data)427 self.assertRedirects(post_response, change_url)428 # CHANGE429 def test_op_manager_cant_change_laa_caseworker(self):430 loggedin_op = self.operators["op_manager1"]431 changing_cw = self.operators["cw_1"]432 # go to cla superusers change form433 logged_in = self.client.login(username=loggedin_op.user.username, password=loggedin_op.user.username)434 self.assertTrue(logged_in)435 # go to changing op change form436 url = reverse("admin:call_centre_caseworker_change", args=(changing_cw.pk,))437 response = self.client.get(url)438 # check that get 404439 self.assertEqual(response.status_code, 403)440 def test_cla_superuser_can_change_laa_caseworker(self):441 loggedin_op = self.operators["op_superuser1"]442 changing_cw = self.operators["cw_1"]443 # go to op_superuser2 change form444 # change changing_op.is_cla_superuser to False and save445 # check everything is OK446 post_data = {447 "username": changing_cw.user.username,448 "first_name": "New Name",449 "last_name": "New Last Name",450 "email": "new_email@example.com",451 "_save": "Save",452 }453 self._test_change_form(loggedin_op.user, changing_cw, post_data=post_data)454 def test_django_superuser_can_change_everything(self):455 loggedin_user = self.django_admin456 changing_cw = self.operators["cw_1"]457 post_data = {458 "username": changing_cw.user.username,459 "first_name": "New Name",460 "last_name": "New Last Name",461 "email": "new_email@example.com",462 "_save": "Save",463 }464 self._test_change_form(loggedin_user, changing_cw, post_data=post_data)465 # CREATE466 def test_cla_superuser_can_create_cla_superusers(self):467 loggedin_op = self.operators["op_superuser1"]468 # go to cw add form469 # check everything is OK470 post_data = {471 "username": get_random_string(),472 "password": "123456789",473 "password2": "123456789",474 "first_name": "New Name",475 "last_name": "New Last Name",476 "email": "new_email@example.com",477 "_save": "Save",478 }479 self._test_add_form(loggedin_op.user, post_data=post_data)480 def test_django_superuser_can_create_cla_superusers(self):481 loggedin_op_user = self.django_admin482 # go to cw add form483 # check everything is OK484 post_data = {485 "username": get_random_string(),486 "password": "123456789",487 "password2": "123456789",488 "first_name": "New Name",489 "last_name": "New Last Name",490 "email": "new_email@example.com",491 "_save": "Save",492 }493 self._test_add_form(loggedin_op_user, post_data=post_data)494 # RESET PASSWORD495 def test_op_manager_cant_change_laa_caseworker_password(self):496 loggedin_op = self.operators["op_manager1"]497 changing_op = self.operators["cw_1"]498 loggedin_op_user = loggedin_op.user499 logged_in = self.client.login(username=loggedin_op_user.username, password=loggedin_op_user.username)500 self.assertTrue(logged_in)501 # go to change password form502 change_url = reverse("admin:call_centre_caseworker_change", args=(changing_op.pk,))503 url = "%spassword/" % change_url504 response = self.client.get(url)505 self.assertEqual(response.status_code, 403)506 # try to change password507 post_data = {"password1": "123456789", "password2": "123456789"}508 # check that it's not possible509 post_response = self.client.post(url, data=post_data, follow=True)510 self.assertEqual(post_response.status_code, 403)511 def test_cla_superuser_can_change_cla_superuser_password(self):512 loggedin_op = self.operators["op_superuser1"]513 changing_cw = self.operators["cw_1"]514 self._test_change_password(loggedin_op.user, changing_cw)515 def test_django_superuser_can_change_laa_caseworker_password(self):516 loggedin_op_user = self.django_admin517 changing_cw = self.operators["cw_1"]...

Full Screen

Full Screen

command_tests.py

Source:command_tests.py Github

copy

Full Screen

...35 self.assertSystemExit(*range(self.arglen + 1))36class TestChangePassword(BaseCommandTestCase, TestCase):37 cmd = 'vmail-chpasswd'38 arglen = 339 def _test_change_password(self, pk_):40 old_pw = 'password'41 new_pw = 'new_password'42 user = MailUser.objects.get(pk=pk_)43 user.set_password(old_pw)44 user.save()45 self.assertTrue(user.check_password(old_pw))46 call_command(self.cmd, str(user), old_pw, new_pw)47 user = MailUser.objects.get(pk=pk_)48 self.assertTrue(user.check_password(new_pw))49 def test_change_password(self):50 """Validate change password works as expected."""51 self._test_change_password(1)52 self._test_change_password(7)53 self._test_change_password(8)54 def test_bad_old_password(self):55 user = 'john@example.org'56 self.assertSystemExit(user, 'old pw', 'new pw')57 def test_bad_email(self):58 """Test a proper email is required."""59 self.assertSystemExit('', None, None)60 self.assertSystemExit('@', None, None)61 self.assertSystemExit('a@b.c', None, None)62 self.assertSystemExit(' a@b.c ', None, None)63 def test_bad_domain(self):64 """Test a valid domain is required."""65 user = 'john@bad.domain.com'66 self.assertSystemExit(user, 'old pw', 'new pw')67 def test_bad_mailuser(self):68 """Test a valid user is required."""69 user = 'bad_mailuser@example.org'70 self.assertSystemExit(user, 'old pw', 'new pw')71class TestSetPassword(BaseCommandTestCase, TestCase):72 cmd = 'vmail-setpasswd'73 arglen = 274 def test_bad_email(self):75 """Test a proper email is required."""76 self.assertSystemExit('', None)77 self.assertSystemExit('@', None)78 self.assertSystemExit('a@b.c', None)79 self.assertSystemExit(' a@b.c ', None)80 def test_bad_domain(self):81 """Test a valid domain is required."""82 user = 'john@bad.domain.com'83 self.assertSystemExit(user, 'new pw')84 def test_bad_mailuser(self):85 """Test a valid user is required."""86 user = 'bad_mailuser@example.org'87 self.assertSystemExit(user, 'new pw')88 def _test_change_password(self, pk_):89 old_pw = 'password'90 new_pw = 'new_password'91 user = MailUser.objects.get(pk=pk_)92 user.set_password(old_pw)93 user.save()94 self.assertTrue(user.check_password(old_pw))95 call_command(self.cmd, str(user), new_pw)96 user = MailUser.objects.get(pk=pk_)97 self.assertTrue(user.check_password(new_pw))98 def test_change_password(self):99 """Validate change password works as expected."""100 self._test_change_password(1)101 self._test_change_password(7)102 self._test_change_password(8)103class TestAddMBoxPassword(BaseCommandTestCase, TestCase):104 cmd = 'vmail-addmbox'105 arglen = 1106 def test_bad_email(self):107 """Test a proper email is required."""108 self.assertSystemExit('')109 self.assertSystemExit('@')110 self.assertSystemExit('a@b.c')111 self.assertSystemExit(' a@b.c ')112 def test_user_already_exests(self):113 user = MailUser.objects.get(pk=1)114 self.assertSystemExit(str(user))115 def test_create_user(self):116 domain = Domain.objects.get(pk=1)...

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