Skip to content

Commit 6bd056c

Browse files
committed
slowly migrate away from using fixtures
1 parent 9e8b4c9 commit 6bd056c

File tree

5 files changed

+53
-48
lines changed

5 files changed

+53
-48
lines changed

Diff for: django_object_actions/factories.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from django.contrib.auth import get_user_model
2+
3+
import factory
4+
5+
6+
class UserFactory(factory.DjangoModelFactory):
7+
FACTORY_FOR = get_user_model()
8+
first_name = factory.Sequence(lambda i: u'John{}'.format(i))
9+
last_name = factory.Sequence(lambda i: u'Doe{}'.format(i))
10+
username = factory.LazyAttribute(lambda x: '{}{}'.format(
11+
x.first_name, x.last_name))
12+
email = factory.LazyAttribute(lambda x: '{}@{}.com'.format(
13+
x.first_name.lower(), x.last_name.lower()))
14+
password = factory.PostGenerationMethodCall('set_password', 'password')
15+
16+

Diff for: django_object_actions/tests/test_utils.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ def test_get_djoa_button_attrs_custom_attrs_get_partitioned(self):
6767

6868

6969
class QuerySetIshTest(TestCase):
70+
fixtures = ['sample_data']
71+
7072
def setUp(self):
71-
# as defined in initial_data fixture
7273
# WISHLIST don't depend on fixture
7374
self.obj = Poll.objects.get(pk=1)
7475

@@ -102,8 +103,9 @@ def test_queryset_supports_update(self):
102103

103104

104105
class DecoratorTest(TestCase):
106+
fixtures = ['sample_data']
107+
105108
def setUp(self):
106-
# as defined in initial_data fixture
107109
# WISHLIST don't depend on fixture
108110
self.obj = Poll.objects.get(pk=1)
109111
self.queryset = Poll.objects.all()

Diff for: django_object_actions/tests/tests.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
from django.test import TestCase
22

33
from example_project.polls.models import Choice
4+
from ..factories import UserFactory
45

56

67
class LoggedInTestCase(TestCase):
78
def setUp(self):
89
super(LoggedInTestCase, self).setUp()
10+
UserFactory.create(
11+
is_staff=True, username='admin', password='password')
912
self.client.login(username='admin', password='admin')
1013

1114

1215
class AppTests(LoggedInTestCase):
16+
fixtures = ['sample_data']
17+
1318
def test_bare_mixin_works(self):
1419
# hit admin that doesn't have any tools defined, just the mixin
1520
response = self.client.get('/admin/polls/poll/add/')

Diff for: example_project/polls/fixtures/initial_data.json

-46
This file was deleted.

Diff for: example_project/polls/fixtures/sample_data.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[
2+
{
3+
"pk": 1,
4+
"model": "polls.poll",
5+
"fields": {
6+
"pub_date": "2012-10-20T18:20:35Z",
7+
"question": "Do you like me?"
8+
}
9+
},
10+
{
11+
"pk": 1,
12+
"model": "polls.choice",
13+
"fields": {
14+
"choice_text": "Yes",
15+
"poll": 1,
16+
"votes": 0
17+
}
18+
},
19+
{
20+
"pk": 2,
21+
"model": "polls.choice",
22+
"fields": {
23+
"choice_text": "No",
24+
"poll": 1,
25+
"votes": 100
26+
}
27+
}
28+
]

0 commit comments

Comments
 (0)