def test_edit_account_address(self): # create a test user in the system tester = models.User() tester.email = "*****@*****.**" tester.password = "******" tester.save() # test edit name Commands.edit_account("*****@*****.**", "address", "1234 W ABC St") tester = models.User.objects.get(email="*****@*****.**") self.assertEqual(tester.address, "1234 W ABC St")
def test_edit_account_password(self): # create a test user in the system tester = models.User() tester.email = "*****@*****.**" tester.password = "******" tester.save() # test edit password Commands.edit_account("*****@*****.**", "password", "new_pass") tester = models.User.objects.get(email="*****@*****.**") self.assertEqual(tester.password, "new_pass")
def test_edit_account_name(self): # create a test user in the system tester = models.User() tester.email = "*****@*****.**" tester.password = "******" tester.save() # test edit name Commands.edit_account("*****@*****.**", "name", "Howard Stern") tester = models.User.objects.get(email="*****@*****.**") self.assertEqual(tester.name, "Howard Stern")
def test_edit_account_email(self): # create a test user in the system tester = models.User() tester.email = "*****@*****.**" tester.password = "******" tester.save() # test edit email Commands.edit_account("*****@*****.**", "email", "*****@*****.**") with self.assertRaises(models.User.DoesNotExist): models.User.objects.get(email="*****@*****.**") tester = models.User.objects.get(email="*****@*****.**") self.assertEqual(tester.email, "*****@*****.**")
def test_edit_account_bad_field(self): tester = models.User() tester.email = "*****@*****.**" tester.password = "******" tester.save() self.assertEqual( Commands.edit_account("*****@*****.**", "wrong_field", "new_pass"), "The entered data field does not exist")
def test_edit_account_dne(self): tester = models.User() tester.email = "*****@*****.**" tester.password = "******" tester.save() self.assertEqual( Commands.edit_account("*****@*****.**", "password", "new_pass"), "Entered user does not exist")
def test_edit_account_phone_too_short(self): tester = models.User() tester.email = "*****@*****.**" tester.password = "******" tester.save() self.assertEqual( Commands.edit_account("*****@*****.**", "phone", "1234"), "Phone number is not of the correct form (###.###.####)") tester = models.User.objects.get(email="*****@*****.**") self.assertEqual(tester.phone, "000.000.0000")
def test_edit_account_phone(self): # create a test user in the system tester = models.User() tester.email = "*****@*****.**" tester.password = "******" tester.save() # test edit phone self.assertTrue( Commands.edit_account("*****@*****.**", "phone", "111.111.1111")) tester = models.User.objects.get(email="*****@*****.**") self.assertEqual(tester.phone, "111.111.1111")
def test_edit_account_email_no_end(self): tester = models.User() tester.email = "*****@*****.**" tester.password = "******" tester.save() self.assertEqual( Commands.edit_account("*****@*****.**", "email", "badEmail"), "Entered email does not end in uwm.edu") with self.assertRaises(models.User.DoesNotExist): models.User.objects.get(email="badEmail") tester = models.User.objects.get(email="*****@*****.**") self.assertEqual(tester.email, "*****@*****.**")
def post(self, request): request.session.set_expiry(300) email = request.POST["email"] field = request.POST["field"] data = request.POST["data"] response = Commands.edit_account(email, field, data) if response == "Command successful.": messages.success(request, response) else: messages.error(request, response) return render(request, 'main/edit_account.html')