SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 879bdec0 authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Fix UserFactory bug

Passwords generated by factoryboy were directly
 put into the table as a string, unhashed! However,
 if the testclient tried to login, it used all
 auth methods a normal user uses as well. This caused
 the test user to never be able to login with the
 generated password.
parent 1943c209
No related branches found
No related tags found
No related merge requests found
...@@ -52,22 +52,17 @@ class VetCommentaryRequestsTest(TestCase): ...@@ -52,22 +52,17 @@ class VetCommentaryRequestsTest(TestCase):
"""Test http response on GET requests""" """Test http response on GET requests"""
# Registered Contributor should get 200 # Registered Contributor should get 200
self.client.login(username=self.contributor.user.username, self.client.login(username=self.contributor.user.username,
password=self.contributor.user.password) password='adm1n')
# Wrong permissions group! # Wrong permissions group!
reponse = self.client.get(self.view_url) response = self.client.get(self.view_url)
self.assertEquals(reponse.status_code, 403) self.assertEquals(response.status_code, 403)
# Right permissions group! # Right permissions group!
# self.client.logout()
group = Group.objects.get(name="Vetting Editors") group = Group.objects.get(name="Vetting Editors")
self.contributor.user.groups.add(group) self.contributor.user.groups.add(group)
# Permission group is still empty!?!? These fixtures just don't seem to work properly. response = self.client.get(self.view_url)
self.assertEquals(response.status_code, 200)
# self.client.login(username=self.contributor.user.username,
# password=self.contributor.user.password)
reponse = self.client.get(self.view_url)
self.assertEquals(reponse.status_code, 200)
# def test_get_valid_unvetted_commentaries(self): # def test_get_valid_unvetted_commentaries(self):
# """Test if valid commentaries are sent back to user.""" # """Test if valid commentaries are sent back to user."""
......
...@@ -21,10 +21,11 @@ class UserFactory(factory.django.DjangoModelFactory): ...@@ -21,10 +21,11 @@ class UserFactory(factory.django.DjangoModelFactory):
model = get_user_model() model = get_user_model()
username = factory.Faker('user_name') username = factory.Faker('user_name')
password = factory.Faker('password') password = factory.PostGenerationMethodCall('set_password', 'adm1n')
email = factory.Faker('safe_email') email = factory.Faker('safe_email')
first_name = factory.Faker('first_name') first_name = factory.Faker('first_name')
last_name = factory.Faker('last_name') last_name = factory.Faker('last_name')
is_active = True
# When user object is created, associate new Contributor object to it. # When user object is created, associate new Contributor object to it.
contributor = factory.RelatedFactory(ContributorFactory, 'user') contributor = factory.RelatedFactory(ContributorFactory, 'user')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment