示例#1
0
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)
示例#2
0
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)
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
 def setUp(self):
     self.user = USER(username=str(uuid4()))
     self.user.save()
示例#6
0
 def setUp(self):
     self.user = USER(username=str(uuid4()))
     self.user.save()