class InvitationCodeModelTest(unittest.TestCase): def setUp(self): self.user = USER(username=str(uuid4())) self.user.save() def tearDown(self): self.user.delete() def test_generate_code(self): code = InvitationCode.generate_code() self.assertIsNotNone(code) def test_add(self): code = InvitationCode.add(self.user) self.assertIsNotNone(code) self.assertEqual(code.creator, self.user) self.assertIsNone(code.acceptor) self.assertIsNotNone(code.time_created) self.assertIsNone(code.time_accepted) self.assertFalse(code.expired) def test_accept(self): code = InvitationCode.add(self.user) rows = InvitationCode.accept(code.code, self.user) self.assertEqual(rows, 1) updated_code = InvitationCode.objects.get(code=code.code) self.assertEqual(updated_code.acceptor, self.user) self.assertIsNotNone(updated_code.time_accepted) self.assertTrue(updated_code.expired)
def test_verify_email(self): request = RequestFactory().get('/') code = 42 result = verify_email(request, code) self.assertEqual(result._headers['location'][1], '/') self.assertTrue(MESSAGE_ERROR) user = USER(username=str(uuid4())) user.save() code = EmailConfirmation.add(user) result = verify_email(request, code, redirect_to='/here/') self.assertEqual(result._headers['location'][1], '/here/') self.assertTrue(MESSAGE_SUCCESS)
def test_verify_email(self): request = RequestFactory().get("/") code = 42 result = verify_email(request, code) self.assertEqual(result._headers["location"][1], "/") self.assertTrue(MESSAGE_ERROR) user = USER(username=str(uuid4())) user.save() code = EmailConfirmation.add(user) result = verify_email(request, code, redirect_to="/here/") self.assertEqual(result._headers["location"][1], "/here/") self.assertTrue(MESSAGE_SUCCESS)
def setUp(self): self.user = USER(username=str(uuid4())) self.user.save()