Exemplo n.º 1
0
 def test_slug_validation_ok(self):
     slug_list = ['a' * 6, '---a--a--a--a--a--a---']
     for slug in slug_list:
         # print(slug) # ~~~~ TODO: remove this line!
         data = self.data.copy()
         data['slug'] = slug
         form = RegistrationForm(language_code=self.language_code, data=data)
         form.full_clean()
         self.assertTrue(expr=form.is_valid())
         self.assertDictEqual(d1=form.errors, d2={})
         user = form.save()
         self.assert_models_count(
             entity_count=1,
             user_count=1,
             user_email_address_count=1,
             confirmed_email_address_count=0,
             unconfirmed_email_address_count=1,
         )
         user = User.objects.get(username=normalize_username(username=slug))
         user.delete()
         self.assert_models_count(
             entity_count=0,
             user_count=0,
             user_email_address_count=0,
             confirmed_email_address_count=0,
             unconfirmed_email_address_count=0,
         )
Exemplo n.º 2
0
 def test_cannot_register_invalid_email(self):
     data = self.data.copy()
     data['email'] = 'email'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertFalse(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2=self._enter_a_valid_email_address_errors_dict())
Exemplo n.º 3
0
 def test_slug_validation_fails_with_username_too_long(self):
     data = self.data.copy()
     data['slug'] = 'a' * 201
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertFalse(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2=self._model_slug_or_username_username_must_contain_at_most_max_length_alphanumeric_characters_errors_dict_by_value_length(model=User, slug_fail=True, username_value_length=201))
Exemplo n.º 4
0
 def test_slug_validation_ok(self):
     slug_list = ['a' * 6, '---a--a--a--a--a--a---']
     for slug in slug_list:
         data = self.data.copy()
         data['slug'] = slug
         form = RegistrationForm(language_code=self.language_code,
                                 data=data)
         form.full_clean()
         self.assertTrue(expr=form.is_valid())
         self.assertDictEqual(d1=form.errors, d2={})
         user = form.save()
         self.assert_models_count(
             entity_count=1,
             user_count=1,
             user_email_address_count=1,
             confirmed_email_address_count=0,
             unconfirmed_email_address_count=1,
         )
         user = User.objects.get(username=normalize_username(
             username=slug))
         user.delete()
         self.assert_models_count(
             entity_count=0,
             user_count=0,
             user_email_address_count=0,
             confirmed_email_address_count=0,
             unconfirmed_email_address_count=0,
         )
Exemplo n.º 5
0
 def test_slug_validation_fails_with_username_too_short(self):
     slug_list = [
         'a' * 5, 'aa-aa', 'a-a-a-a', '---a--a--a--a---',
         '---a--a--a--a--a---'
     ]
     for slug in slug_list:
         # print(slug) # ~~~~ TODO: remove this line!
         username_value_length = len(normalize_username(username=slug))
         if (slug in ['a' * 5, '---a--a--a--a--a---']):
             self.assertEqual(first=username_value_length, second=5)
         else:
             self.assertEqual(first=username_value_length, second=4)
         data = self.data.copy()
         data['slug'] = slug
         form = RegistrationForm(language_code=self.language_code,
                                 data=data)
         form.full_clean()
         self.assertFalse(expr=form.is_valid())
         self.assertDictEqual(
             d1=form.errors,
             d2=self.
             _model_slug_or_username_username_must_contain_at_least_min_length_alphanumeric_characters_errors_dict_by_value_length(
                 model=User,
                 slug_fail=True,
                 username_value_length=username_value_length))
Exemplo n.º 6
0
 def test_slug_validation_fails_with_reserved_username(self):
     data = self.data.copy()
     data['slug'] = 'webmaster'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertFalse(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2=self._this_username_is_already_taken_errors_dict(slug_fail=True))
Exemplo n.º 7
0
 def test_cannot_register_invalid_email(self):
     data = self.data.copy()
     data['email'] = 'email'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertFalse(expr=form.is_valid())
     self.assertDictEqual(
         d1=form.errors, d2=self._enter_a_valid_email_address_errors_dict())
Exemplo n.º 8
0
 def test_slug_validation_fails_with_username_already_taken(self):
     ActiveUserFactory(slug='validslug')
     data = self.data.copy()
     data['slug'] = 'valid-slug'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertFalse(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2=self._this_username_is_already_taken_errors_dict(slug_fail=True))
Exemplo n.º 9
0
 def test_invalid_date_of_birth_list_fail(self):
     for date_of_birth in tests_settings.INVALID_DATE_OF_BIRTH_IN_FORMS_LIST:
         # print(date_of_birth) # ~~~~ TODO: remove this line!
         data = self.data.copy()
         data['date_of_birth'] = date_of_birth
         form = RegistrationForm(language_code=self.language_code, data=data)
         form.full_clean()
         self.assertFalse(expr=form.is_valid(), msg="{} is a valid date of birth.".format(date_of_birth))
         self.assertDictEqual(d1=form.errors, d2=self._date_of_birth_errors_dict_by_date_of_birth(date_of_birth=date_of_birth), msg='"{}" - Unexpected error messages.'.format(date_of_birth))
Exemplo n.º 10
0
 def test_visitor_can_register(self):
     form = RegistrationForm(language_code=self.language_code,
                             data=self.data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     self.assert_models_count(
         entity_count=1,
         user_count=1,
         user_email_address_count=1,
         confirmed_email_address_count=0,
         unconfirmed_email_address_count=1,
     )
     self.assertEqual(
         first=Entity.objects.filter(username=self.username).count(),
         second=1)
     self.assertEqual(
         first=User.objects.filter(username=self.username).count(),
         second=1)
     entity = Entity.objects.get(username=self.username)
     user = User.objects.get(username=self.username)
     self.assertEqual(first=user, second=entity.user)
     self.assertEqual(first=entity.id, second=user.id)
     self.assertEqual(first=entity.username, second=user.username)
     self.assertEqual(first=entity.slug, second=user.slug)
     self.assertEqual(first=len(entity.id), second=15)
     self.assertTrue(expr=user.check_password(
         raw_password=self.password))
     self.assertFalse(expr=user.check_password(
         raw_password=tests_settings.USER_PASSWORD))
     self.assertEqual(first=user.first_name, second=self.first_name)
     self.assertEqual(first=user.first_name_en, second=self.first_name)
     self.assertEqual(first=user.first_name_he, second=self.first_name)
     self.assertEqual(first=user.last_name, second=self.last_name)
     self.assertEqual(first=user.last_name_en, second=self.last_name)
     self.assertEqual(first=user.last_name_he, second=self.last_name)
     self.assertEqual(first=user.username, second=self.username)
     self.assertEqual(first=user.username, second='user22')
     self.assertEqual(first=user.slug, second=self.slug)
     self.assertEqual(first=user.slug, second='user-22')
     self.assert_user_email_addresses_count(
         user=user,
         user_email_addresses_count=1,
         user_primary_email_addresses_count=1,
         user_confirmed_email_addresses_count=0,
         user_unconfirmed_email_addresses_count=1,
     )
     self.assertEqual(first=user.email_addresses.first().email,
                      second='*****@*****.**')
     self.assertFalse(expr=user.email_addresses.first().is_confirmed)
     self.assertTrue(expr=user.email_addresses.first().is_primary)
     for (key, value) in self.data.items():
         if (not (key in ['new_password1', 'date_of_birth'])):
             self.assertEqual(first=getattr(user, key), second=value)
     self.assertEqual(first=user.date_of_birth,
                      second=date(year=1980, month=1, day=1))
Exemplo n.º 11
0
 def run_test_required_fields(self, data):
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertFalse(expr=form.is_valid())
     self.assertDictEqual(
         d1=form.errors,
         d2=self.
         _registration_form_all_the_required_fields_are_required_errors_dict(
         ))
Exemplo n.º 12
0
 def test_slug_gets_converted_to_lowercase(self):
     data = self.data.copy()
     data['slug'] = 'THIS-IS-A-SLUG'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     self.assertEqual(first=user.slug, second='this-is-a-slug')
     self.assertEqual(first=user.username, second='thisisaslug')
Exemplo n.º 13
0
 def test_slug_dashes_are_trimmed_and_double_dashes_are_converted_to_single_dashes(self):
     data = self.data.copy()
     data['slug'] = '--this--is---a--slug--'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     self.assertEqual(first=user.slug, second='this-is-a-slug')
     self.assertEqual(first=user.username, second='thisisaslug')
Exemplo n.º 14
0
 def test_slug_dots_and_underscores_gets_converted_to_dashes(self):
     data = self.data.copy()
     data['slug'] = 'this.is__a.slug'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     self.assertEqual(first=user.slug, second='this-is-a-slug')
     self.assertEqual(first=user.username, second='thisisaslug')
Exemplo n.º 15
0
 def test_slug_validation_fails_with_reserved_username(self):
     data = self.data.copy()
     data['slug'] = 'webmaster'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertFalse(expr=form.is_valid())
     self.assertDictEqual(
         d1=form.errors,
         d2=self._this_username_is_already_taken_errors_dict(
             slug_fail=True))
Exemplo n.º 16
0
 def test_slug_gets_converted_to_lowercase(self):
     data = self.data.copy()
     data['slug'] = 'THIS-IS-A-SLUG'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     self.assertEqual(first=user.slug, second='this-is-a-slug')
     self.assertEqual(first=user.username, second='thisisaslug')
Exemplo n.º 17
0
 def test_slug_dots_and_underscores_gets_converted_to_dashes(self):
     data = self.data.copy()
     data['slug'] = 'this.is__a.slug'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     self.assertEqual(first=user.slug, second='this-is-a-slug')
     self.assertEqual(first=user.username, second='thisisaslug')
Exemplo n.º 18
0
 def test_slug_validation_fails_with_invalid_username_regex(self):
     slug_list = ['0' * 6, '0test1', '1234567890digits', 'aaa', 'aaa 9999', 'aaa-9999', 'aaa+9999']
     for slug in slug_list:
         # print(slug) # ~~~~ TODO: remove this line!
         data = self.data.copy()
         data['slug'] = slug
         form = RegistrationForm(language_code=self.language_code, data=data)
         form.full_clean()
         self.assertFalse(expr=form.is_valid(), msg="{} is a valid slug.".format(slug))
         self.assertDictEqual(d1=form.errors, d2=self._username_must_start_with_4_or_more_letters_errors_dict(model=User, slug_fail=True), msg='"{}" - Unexpected error messages.'.format(slug))
Exemplo n.º 19
0
 def run_test_all_slugs_to_test_list(self, test_settings):
     ok_count, model_save_failures_count = 0, 0
     for slug_dict in tests_settings.SLUGS_TO_TEST_LIST:
         data = self.data.copy()
         data['slug'] = slug_dict["slug"]
         username = normalize_username(username=data['slug'])
         slug = normalize_slug(slug=data['slug'])
         data['email'] = "{username}@example.com".format(
             username=username)
         self.assertEqual(first=slug_dict["slug_length"],
                          second=len(slug))
         if (slug_dict["slug_length"] >= User.settings.MIN_SLUG_LENGTH):
             form = RegistrationForm(language_code=self.language_code,
                                     data=data)
             form.full_clean()
             self.assertTrue(expr=form.is_valid())
             self.assertDictEqual(d1=form.errors, d2={})
             user = form.save()
             self.assertEqual(
                 first=User.objects.filter(username=username).count(),
                 second=1)
             user = User.objects.get(username=username)
             self.assertEqual(first=user.username, second=username)
             self.assertEqual(first=user.slug, second=slug)
             ok_count += 1
         else:
             form = RegistrationForm(language_code=self.language_code,
                                     data=data)
             form.full_clean()
             self.assertFalse(expr=form.is_valid())
             self.assertDictEqual(
                 d1=form.errors,
                 d2=self.
                 _model_slug_or_username_username_must_contain_at_least_min_length_characters_errors_dict_by_value_length(
                     model=User,
                     slug_fail=True,
                     slug_value_length=slug_dict["slug_length"]))
             self.assertEqual(
                 first=User.objects.filter(username=username).count(),
                 second=0)
             model_save_failures_count += 1
     counts_tuple = (ok_count, model_save_failures_count)
     self.assert_models_count(
         entity_count=ok_count,
         user_count=ok_count,
         user_email_address_count=ok_count,
         confirmed_email_address_count=0,
         unconfirmed_email_address_count=ok_count,
     )
     self.assertEqual(first=sum(counts_tuple),
                      second=len(tests_settings.SLUGS_TO_TEST_LIST))
     self.assertTupleEqual(
         tuple1=counts_tuple,
         tuple2=test_settings["expected_counts_tuple"])
Exemplo n.º 20
0
 def test_slug_dashes_are_trimmed_and_double_dashes_are_converted_to_single_dashes(
         self):
     data = self.data.copy()
     data['slug'] = '--this--is---a--slug--'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     self.assertEqual(first=user.slug, second='this-is-a-slug')
     self.assertEqual(first=user.username, second='thisisaslug')
Exemplo n.º 21
0
 def test_slug_validation_fails_with_username_already_taken(self):
     ActiveUserFactory(slug='validslug')
     data = self.data.copy()
     data['slug'] = 'valid-slug'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertFalse(expr=form.is_valid())
     self.assertDictEqual(
         d1=form.errors,
         d2=self._this_username_is_already_taken_errors_dict(
             slug_fail=True))
Exemplo n.º 22
0
 def test_slug_validation_fails_with_username_too_long(self):
     data = self.data.copy()
     data['slug'] = 'a' * 201
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertFalse(expr=form.is_valid())
     self.assertDictEqual(
         d1=form.errors,
         d2=self.
         _model_slug_or_username_username_must_contain_at_most_max_length_alphanumeric_characters_errors_dict_by_value_length(
             model=User, slug_fail=True, username_value_length=201))
Exemplo n.º 23
0
 def test_email_gets_converted_to_lowercase(self):
     data = self.data.copy()
     data['email'] = '*****@*****.**'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     email_addresses = UserEmailAddress.objects.filter(user=user)
     email_addresses_set = {e.email for e in email_addresses}
     self.assertSetEqual(set1=email_addresses_set, set2={'*****@*****.**'})
Exemplo n.º 24
0
 def test_email_gets_converted_to_lowercase(self):
     data = self.data.copy()
     data['email'] = '*****@*****.**'
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     email_addresses = UserEmailAddress.objects.filter(user=user)
     email_addresses_set = {e.email for e in email_addresses}
     self.assertSetEqual(set1=email_addresses_set,
                         set2={'*****@*****.**'})
Exemplo n.º 25
0
 def test_slug_validation_fails_with_username_too_short(self):
     slug_list = ['a' * 5, 'aa-aa', 'a-a-a-a', '---a--a--a--a---', '---a--a--a--a--a---']
     for slug in slug_list:
         # print(slug) # ~~~~ TODO: remove this line!
         username_value_length = len(normalize_username(username=slug))
         if (slug in ['a' * 5, '---a--a--a--a--a---']):
             self.assertEqual(first=username_value_length, second=5)
         else:
             self.assertEqual(first=username_value_length, second=4)
         data = self.data.copy()
         data['slug'] = slug
         form = RegistrationForm(language_code=self.language_code, data=data)
         form.full_clean()
         self.assertFalse(expr=form.is_valid())
         self.assertDictEqual(d1=form.errors, d2=self._model_slug_or_username_username_must_contain_at_least_min_length_alphanumeric_characters_errors_dict_by_value_length(model=User, slug_fail=True, username_value_length=username_value_length))
Exemplo n.º 26
0
 def test_non_unique_unconfirmed_email_address(self):
     # Unconfirmed email address is deleted if another user adds it again.
     existing_user_email = UserEmailAddressFactory(email=self.data['email'],
                                                   is_confirmed=False)
     existing_user = existing_user_email.user
     self.assert_models_count(
         entity_count=1,
         user_count=1,
         user_email_address_count=1,
         confirmed_email_address_count=0,
         unconfirmed_email_address_count=1,
     )
     # existing_user = ActiveUserFactory() # ~~~~ TODO: remove this line!
     # existing_user.email_addresses.create(email='*****@*****.**', is_confirmed=False) # ~~~~ TODO: remove this line!
     self.assert_user_email_addresses_count(
         user=existing_user,
         user_email_addresses_count=1,
         user_confirmed_email_addresses_count=0,
         user_unconfirmed_email_addresses_count=1,
     )
     form = RegistrationForm(language_code=self.language_code,
                             data=self.data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     # self.assertEqual(first=form.errors['email'][0], second=self._this_email_is_already_in_use_error_message) # ~~~~ TODO: remove this line!
     self.assert_models_count(
         entity_count=2,
         user_count=2,
         user_email_address_count=1,
         confirmed_email_address_count=0,
         unconfirmed_email_address_count=1,
     )
     self.assert_user_email_addresses_count(
         user=existing_user,
         user_email_addresses_count=0,
         user_confirmed_email_addresses_count=0,
         user_unconfirmed_email_addresses_count=0,
     )
     existing_user = User.objects.get(
         pk=existing_user.pk)  # ~~~~ TODO: remove this line!
     self.assert_user_email_addresses_count(
         user=existing_user,
         user_email_addresses_count=0,
         user_confirmed_email_addresses_count=0,
         user_unconfirmed_email_addresses_count=0,
     )
Exemplo n.º 27
0
 def test_invalid_date_of_birth_list_fail(self):
     for date_of_birth in tests_settings.INVALID_DATE_OF_BIRTH_IN_FORMS_LIST:
         data = self.data.copy()
         data['date_of_birth'] = date_of_birth
         form = RegistrationForm(language_code=self.language_code,
                                 data=data)
         form.full_clean()
         self.assertFalse(
             expr=form.is_valid(),
             msg="{} is a valid date of birth.".format(date_of_birth))
         self.assertDictEqual(
             d1=form.errors,
             d2=self._date_of_birth_errors_dict_by_date_of_birth(
                 date_of_birth=date_of_birth),
             msg='"{}" - Unexpected error messages.'.format(
                 date_of_birth))
Exemplo n.º 28
0
 def test_non_unique_unconfirmed_email_address(self):
     # Unconfirmed email address is deleted if another user adds it again.
     existing_user_email = UserEmailAddressFactory(
         email=self.data['email'], is_confirmed=False)
     existing_user = existing_user_email.user
     self.assert_models_count(
         entity_count=1,
         user_count=1,
         user_email_address_count=1,
         confirmed_email_address_count=0,
         unconfirmed_email_address_count=1,
     )
     self.assert_user_email_addresses_count(
         user=existing_user,
         user_email_addresses_count=1,
         user_primary_email_addresses_count=1,
         user_confirmed_email_addresses_count=0,
         user_unconfirmed_email_addresses_count=1,
     )
     form = RegistrationForm(language_code=self.language_code,
                             data=self.data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     self.assert_models_count(
         entity_count=2,
         user_count=2,
         user_email_address_count=1,
         confirmed_email_address_count=0,
         unconfirmed_email_address_count=1,
     )
     self.assert_user_email_addresses_count(
         user=existing_user,
         user_email_addresses_count=0,
         user_primary_email_addresses_count=0,
         user_confirmed_email_addresses_count=0,
         user_unconfirmed_email_addresses_count=0,
     )
     existing_user = User.objects.get(pk=existing_user.pk)
     self.assert_user_email_addresses_count(
         user=existing_user,
         user_email_addresses_count=0,
         user_primary_email_addresses_count=0,
         user_confirmed_email_addresses_count=0,
         user_unconfirmed_email_addresses_count=0,
     )
Exemplo n.º 29
0
 def test_non_unique_confirmed_email_address(self):
     existing_user_email = UserEmailAddressFactory(
         email=self.data['email'], is_confirmed=True)
     existing_user = existing_user_email.user
     self.assert_models_count(
         entity_count=1,
         user_count=1,
         user_email_address_count=1,
         confirmed_email_address_count=1,
         unconfirmed_email_address_count=0,
     )
     self.assert_user_email_addresses_count(
         user=existing_user,
         user_email_addresses_count=1,
         user_primary_email_addresses_count=1,
         user_confirmed_email_addresses_count=1,
         user_unconfirmed_email_addresses_count=0,
     )
     form = RegistrationForm(language_code=self.language_code,
                             data=self.data)
     form.full_clean()
     self.assertFalse(expr=form.is_valid())
     self.assertDictEqual(
         d1=form.errors,
         d2=self._this_email_is_already_in_use_errors_dict())
     self.assert_models_count(
         entity_count=1,
         user_count=1,
         user_email_address_count=1,
         confirmed_email_address_count=1,
         unconfirmed_email_address_count=0,
     )
     self.assert_user_email_addresses_count(
         user=existing_user,
         user_email_addresses_count=1,
         user_primary_email_addresses_count=1,
         user_confirmed_email_addresses_count=1,
         user_unconfirmed_email_addresses_count=0,
     )
     existing_user = User.objects.get(pk=existing_user.pk)
     self.assert_user_email_addresses_count(
         user=existing_user,
         user_email_addresses_count=1,
         user_primary_email_addresses_count=1,
         user_confirmed_email_addresses_count=1,
         user_unconfirmed_email_addresses_count=0,
     )
Exemplo n.º 30
0
 def test_visitor_can_register(self):
     form = RegistrationForm(language_code=self.language_code, data=self.data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     self.assert_models_count(
         entity_count=1,
         user_count=1,
         user_email_address_count=1,
         confirmed_email_address_count=0,
         unconfirmed_email_address_count=1,
     )
     self.assertEqual(first=Entity.objects.filter(username=self.username).count(), second=1)
     self.assertEqual(first=User.objects.filter(username=self.username).count(), second=1)
     entity = Entity.objects.get(username=self.username)
     user = User.objects.get(username=self.username)
     self.assertEqual(first=user, second=entity.user)
     self.assertEqual(first=entity.id, second=user.id)
     self.assertEqual(first=entity.username, second=user.username)
     self.assertEqual(first=entity.slug, second=user.slug)
     self.assertEqual(first=len(entity.id), second=15)
     self.assertTrue(expr=user.check_password(raw_password=self.password))
     self.assertFalse(expr=user.check_password(raw_password=tests_settings.USER_PASSWORD))
     self.assertEqual(first=user.first_name, second=self.first_name)
     self.assertEqual(first=user.first_name_en, second=self.first_name)
     self.assertEqual(first=user.first_name_he, second=self.first_name)
     self.assertEqual(first=user.last_name, second=self.last_name)
     self.assertEqual(first=user.last_name_en, second=self.last_name)
     self.assertEqual(first=user.last_name_he, second=self.last_name)
     self.assertEqual(first=user.username, second=self.username)
     self.assertEqual(first=user.username, second='user22')
     self.assertEqual(first=user.slug, second=self.slug)
     self.assertEqual(first=user.slug, second='user-22')
     self.assert_user_email_addresses_count(
         user=user,
         user_email_addresses_count=1,
         user_confirmed_email_addresses_count=0,
         user_unconfirmed_email_addresses_count=1,
     )
     self.assertEqual(first=user.email_addresses.first().email, second='*****@*****.**')
     self.assertFalse(expr=user.email_addresses.first().is_confirmed)
     self.assertTrue(expr=user.email_addresses.first().is_primary)
     for (key, value) in self.data.items():
         if (not (key in ['new_password1', 'date_of_birth'])):
             self.assertEqual(first=getattr(user, key), second=value)
     self.assertEqual(first=user.date_of_birth, second=date(year=1980, month=1, day=1))
Exemplo n.º 31
0
 def test_non_unique_unconfirmed_email_address(self):
     # Unconfirmed email address is deleted if another user adds it again.
     existing_user_email = UserEmailAddressFactory(email=self.data['email'], is_confirmed=False)
     existing_user = existing_user_email.user
     self.assert_models_count(
         entity_count=1,
         user_count=1,
         user_email_address_count=1,
         confirmed_email_address_count=0,
         unconfirmed_email_address_count=1,
     )
     # existing_user = ActiveUserFactory() # ~~~~ TODO: remove this line!
     # existing_user.email_addresses.create(email='*****@*****.**', is_confirmed=False) # ~~~~ TODO: remove this line!
     self.assert_user_email_addresses_count(
         user=existing_user,
         user_email_addresses_count=1,
         user_confirmed_email_addresses_count=0,
         user_unconfirmed_email_addresses_count=1,
     )
     form = RegistrationForm(language_code=self.language_code, data=self.data)
     form.full_clean()
     self.assertTrue(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2={})
     user = form.save()
     # self.assertEqual(first=form.errors['email'][0], second=self._this_email_is_already_in_use_error_message) # ~~~~ TODO: remove this line!
     self.assert_models_count(
         entity_count=2,
         user_count=2,
         user_email_address_count=1,
         confirmed_email_address_count=0,
         unconfirmed_email_address_count=1,
     )
     self.assert_user_email_addresses_count(
         user=existing_user,
         user_email_addresses_count=0,
         user_confirmed_email_addresses_count=0,
         user_unconfirmed_email_addresses_count=0,
     )
     existing_user = User.objects.get(pk=existing_user.pk) # ~~~~ TODO: remove this line!
     self.assert_user_email_addresses_count(
         user=existing_user,
         user_email_addresses_count=0,
         user_confirmed_email_addresses_count=0,
         user_unconfirmed_email_addresses_count=0,
     )
Exemplo n.º 32
0
 def test_slug_validation_fails_with_invalid_username_regex(self):
     slug_list = [
         '0' * 6, '0test1', '1234567890digits', 'aaa', 'aaa 9999',
         'aaa-9999', 'aaa+9999'
     ]
     for slug in slug_list:
         data = self.data.copy()
         data['slug'] = slug
         form = RegistrationForm(language_code=self.language_code,
                                 data=data)
         form.full_clean()
         self.assertFalse(expr=form.is_valid(),
                          msg="{} is a valid slug.".format(slug))
         self.assertDictEqual(
             d1=form.errors,
             d2=self.
             _username_must_start_with_4_or_more_letters_errors_dict(
                 model=User, slug_fail=True),
             msg='"{}" - Unexpected error messages.'.format(slug))
Exemplo n.º 33
0
 def run_test_all_slugs_to_test_list(self, test_settings):
     ok_count, model_save_failures_count = 0, 0
     for slug_dict in tests_settings.SLUGS_TO_TEST_LIST:
         data = self.data.copy()
         data['slug'] = slug_dict["slug"]
         username = normalize_username(username=data['slug'])
         slug = normalize_slug(slug=data['slug'])
         data['email'] = "{username}@example.com".format(username=username)
         self.assertEqual(first=slug_dict["slug_length"], second=len(slug))
         if (slug_dict["slug_length"] >= User.settings.MIN_SLUG_LENGTH):
             form = RegistrationForm(language_code=self.language_code, data=data)
             form.full_clean()
             self.assertTrue(expr=form.is_valid())
             self.assertDictEqual(d1=form.errors, d2={})
             user = form.save()
             self.assertEqual(first=User.objects.filter(username=username).count(), second=1)
             user = User.objects.get(username=username)
             self.assertEqual(first=user.username, second=username)
             self.assertEqual(first=user.slug, second=slug)
             ok_count += 1
         else:
             form = RegistrationForm(language_code=self.language_code, data=data)
             form.full_clean()
             self.assertFalse(expr=form.is_valid())
             self.assertDictEqual(d1=form.errors, d2=self._model_slug_or_username_username_must_contain_at_least_min_length_characters_errors_dict_by_value_length(model=User, slug_fail=True, slug_value_length=slug_dict["slug_length"]))
             self.assertEqual(first=User.objects.filter(username=username).count(), second=0)
             model_save_failures_count += 1
     counts_tuple = (ok_count, model_save_failures_count)
     self.assert_models_count(
         entity_count=ok_count,
         user_count=ok_count,
         user_email_address_count=ok_count,
         confirmed_email_address_count=0,
         unconfirmed_email_address_count=ok_count,
     )
     self.assertEqual(first=sum(counts_tuple), second=len(tests_settings.SLUGS_TO_TEST_LIST))
     self.assertTupleEqual(tuple1=counts_tuple, tuple2=test_settings["expected_counts_tuple"])
Exemplo n.º 34
0
 def run_test_required_fields(self, data):
     form = RegistrationForm(language_code=self.language_code, data=data)
     form.full_clean()
     self.assertFalse(expr=form.is_valid())
     self.assertDictEqual(d1=form.errors, d2=self._registration_form_all_the_required_fields_are_required_errors_dict())