Esempio n. 1
0
 def test_use_increases_use_counts(self):
     user = self.get_standard_user()
     self.assertEqual(SignupCode.objects.count(), 0)
     new_code = SignupCode.create(code=self.test_code1)
     new_code.save()
     new_code.use(user)
     self.assertEqual(new_code.use_count, 1)
     new_code = SignupCode.objects.get(pk=new_code.pk)
     self.assertEqual(new_code.use_count, 1)
Esempio n. 2
0
 def test_get_not_logged_with_valid_code(self):
     random_code = self.rand_str()
     new_code = SignupCode.create(code=random_code)
     new_code.save()
     data = {
         'code': new_code.code,
     }
     view_url = self.get_view_url()
     response = self.client.get(view_url, data=data)
     self.assertContains(response, 'New? Register now')
Esempio n. 3
0
 def test_if_signup_code_result_is_created_on_code_use(self):
     user = self.get_standard_user()
     self.assertEqual(SignupCode.objects.count(), 0)
     self.assertEqual(SignupCodeResult.objects.count(), 0)
     new_code = SignupCode.create(code=self.test_code1)
     new_code.save()
     new_code.use(user)
     self.assertEqual(SignupCodeResult.objects.count(), 1)
     code_result = SignupCodeResult.objects.get()
     self.assertEqual(code_result.signup_code.pk, new_code.pk)
     self.assertEqual(code_result.user, user)
Esempio n. 4
0
 def test_send_sends_email_with_correct_code(self):
     self.assertEqual(SignupCode.objects.count(), 0)
     new_code = SignupCode.create(code=self.test_code1,
                                  email=self.test_email1)
     new_code.save()
     mail.outbox = []
     new_code.send()
     self.assertEqual(len(mail.outbox), 1)
     invite_message = mail.outbox[0]
     self.assertIn(self.test_email1, invite_message.to)
     self.assertGreater(invite_message.body.find(self.test_code1), 0)
Esempio n. 5
0
 def test_calculate_use_count_not_updaetes_if_no_usages(self):
     self.assertEqual(SignupCode.objects.count(), 0)
     new_code = SignupCode.create(code=self.test_code1)
     new_code.save()
     self.assertEqual(new_code.use_count, 0)
     # refresh and test db results
     new_code = SignupCode.objects.get(pk=new_code.pk)
     self.assertEqual(new_code.use_count, 0)
     new_code.calculate_use_count()
     self.assertEqual(new_code.use_count, 0)
     new_code = SignupCode.objects.get(pk=new_code.pk)
     self.assertEqual(new_code.use_count, 0)
Esempio n. 6
0
    def test_save_increases_signup_code_use_count(self):
        self.assertEqual(SignupCode.objects.count(), 0)
        new_code = SignupCode.create(code=self.test_code1)
        new_code.save()
        self.assertEqual(new_code.use_count, 0)

        self.assertEqual(new_code.signupcoderesult_set.count(), 0)
        user = self.get_standard_user()
        signup_result = SignupCodeResult(signup_code=new_code, user=user)
        signup_result.save()
        self.assertEqual(new_code.use_count, 1)
        new_code = SignupCode.objects.get(pk=new_code.pk)
        self.assertEqual(new_code.use_count, 1)
Esempio n. 7
0
    def test_get_with_valid_code(self):
        # ensure there is no users
        self.assertEqual(User.objects.count(), 0)

        random_code = self.rand_str()
        new_code = SignupCode.create(code=random_code)
        new_code.save()
        data = {
            'code': new_code.code,
            'email': '*****@*****.**',
        }
        view_url = self.get_view_url()
        response = self.client.post(view_url, data=data)
        self.assertEqual(User.objects.count(), 1)
Esempio n. 8
0
 def test_calculate_use_count_updates_to_correct_value(self):
     self.assertEqual(SignupCode.objects.count(), 0)
     new_code = SignupCode(code=self.test_code1, use_count=1)
     new_code.save()
     self.assertEqual(new_code.use_count, 1)
     # refresh and test db results
     new_code = SignupCode.objects.get(pk=new_code.pk)
     self.assertEqual(new_code.use_count, 1)
     new_code.calculate_use_count()
     self.assertEqual(new_code.use_count, 0)
     new_code = SignupCode.objects.get(pk=new_code.pk)
     self.assertEqual(new_code.use_count, 0)
Esempio n. 9
0
 def test_is_valid_with_valid_code(self):
     self.assertEqual(SignupCode.objects.count(), 0)
     new_code = SignupCode.create(code=self.test_code1)
     new_code.save()
     self.assertTrue(new_code.is_valid())
Esempio n. 10
0
 def test_exists_method_existing_code_and_email(self):
     self.assertEqual(SignupCode.objects.count(), 0)
     new_code = SignupCode.create(email=self.test_email1,
                                  code=self.test_code1)
     new_code.save()
     self.assertTrue(SignupCode.exists(self.test_code1, self.test_email1))
Esempio n. 11
0
 def test_exists_method_not_existing_code_and_email(self):
     self.assertEqual(SignupCode.objects.count(), 0)
     self.assertFalse(SignupCode.exists(self.test_code1, self.test_email1))
Esempio n. 12
0
 def test_exists_method_not_existing_code(self):
     self.assertEqual(SignupCode.objects.count(), 0)
     self.assertFalse(SignupCode.exists(code=self.test_code1))
Esempio n. 13
0
 def test_create_method_creates_with_code(self):
     self.assertEqual(SignupCode.objects.count(), 0)
     created_code = SignupCode.create(code=self.test_code1)
     created_code.save()
     self.assertEqual(SignupCode.objects.count(), 1)
Esempio n. 14
0
 def test_create_method_creates_no_args(self):
     self.assertEqual(SignupCode.objects.count(), 0)
     created_code = SignupCode.create()
     created_code.save()
     self.assertEqual(SignupCode.objects.count(), 1)