1
0
Fork 0

Fix tests to meet new Django requirements

merge-requests/114/head
Nikos Roussos 2015-04-16 12:21:09 +03:00
parent 1d0fed7396
commit c27b81b770
4 changed files with 29 additions and 42 deletions

View File

@ -1,9 +1,9 @@
import factory
import random
from datetime import timedelta
from django.utils.timezone import now
import factory
from factory import fuzzy
from django.utils.timezone import now
from network.base.models import (ANTENNA_BANDS, ANTENNA_TYPES, MODE_CHOICES,
Antenna, Satellite, Station, Transponder, Observation)

View File

@ -102,6 +102,7 @@ STATION_DEFAULT_IMAGE = '/static/img/dish.png'
# App conf
ROOT_URLCONF = 'network.urls'
WSGI_APPLICATION = 'network.wsgi.application'
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
# Auth
AUTHENTICATION_BACKENDS = (

View File

@ -0,0 +1,25 @@
import datetime
import factory
from factory import fuzzy
from django.utils.timezone import utc
from network.users.models import User
class UserFactory(factory.django.DjangoModelFactory):
"""User model factory."""
username = factory.Sequence(lambda n: 'username%s' % n)
first_name = 'John'
last_name = factory.Sequence(lambda n: 'Doe %s' % n)
email = factory.LazyAttribute(lambda o: '%s@example.com' % o.username)
password = factory.PostGenerationMethodCall('set_password', 'passwd')
is_staff = False
is_active = True
is_superuser = False
last_login = datetime.datetime(2012, 1, 1, tzinfo=utc)
date_joined = datetime.datetime(2012, 1, 1, tzinfo=utc)
bio = fuzzy.FuzzyText()
class Meta:
model = User

View File

@ -1,39 +0,0 @@
import datetime
import factory
from factory import fuzzy
from network.users.models import User
def int2roman(n):
roman_map = (('M', 1000), ('CM', 900), ('D', 500), ('CD', 400),
('C', 100), ('XC', 90), ('L', 50), ('XL', 40), ('X', 10),
('IX', 9), ('V', 5), ('IV', 4), ('I', 1))
if not (0 < n < 5000):
raise Exception('Out of range error.')
result = ''
for numeral, integer in roman_map:
while n >= integer:
result += numeral
n -= integer
return result
class UserFactory(factory.django.DjangoModelFactory):
"""User model factory."""
username = factory.Sequence(lambda n: 'username%s' % n)
first_name = 'John'
last_name = factory.Sequence(lambda n: 'Doe %s' % int2roman(n))
email = factory.LazyAttribute(lambda o: '%s@example.com' % o.username)
password = factory.PostGenerationMethodCall('set_password', 'passwd')
is_staff = False
is_active = True
is_superuser = False
last_login = datetime.datetime(2012, 1, 1)
date_joined = datetime.datetime(2011, 1, 1)
bio = fuzzy.FuzzyText()
class Meta:
model = User