Commit 09b69592 authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg

Merge branch 'speed_up_tests' into 'master'

Speed up tests

See merge request !390
parents 5fdba335 4f00c56c
......@@ -11,14 +11,19 @@ from members.models import Member
class CommitteeMembersTest(TestCase):
fixtures = ['members.json', 'committees.json']
@classmethod
def setUpTestData(cls):
cls.testcie = Committee.objects.get(pk=1)
cls.testuser = Member.objects.get(pk=1)
cls.m = CommitteeMembership.objects.create(
committee=cls.testcie,
member=cls.testuser,
chair=False)
def setUp(self):
# Don't use setUpTestData because delete() will cause problems
self.testcie = Committee.objects.get(pk=1)
self.testuser = Member.objects.get(pk=1)
self.m = CommitteeMembership(committee=self.testcie,
member=self.testuser,
chair=False)
self.m.save()
self.testcie.refresh_from_db()
self.testuser.refresh_from_db()
self.m.refresh_from_db()
def test_unique(self):
with self.assertRaises(IntegrityError):
......@@ -86,12 +91,16 @@ class CommitteeMembersTest(TestCase):
class CommitteeMembersChairTest(TestCase):
fixtures = ['members.json', 'committees.json']
@classmethod
def setUpTestData(cls):
cls.testcie = Committee.objects.get(pk=1)
cls.testuser = Member.objects.get(pk=1)
cls.testuser2 = Member.objects.get(pk=2)
def setUp(self):
self.testcie = Committee.objects.get(pk=1)
self.testuser = Member.objects.get(pk=1)
self.testuser2 = Member.objects.get(pk=2)
self.m1 = CommitteeMembership(committee=self.testcie,
since=timezone.now().date().replace(
day=1,
year=1900),
member=self.testuser,
chair=True)
......@@ -106,7 +115,7 @@ class CommitteeMembersChairTest(TestCase):
m.full_clean()
def test_inactive_chair(self):
self.m1.until = timezone.now().date().replace(year=1900)
self.m1.until = timezone.now().date().replace(day=1, year=1900)
self.m1.save()
m = CommitteeMembership(committee=self.testcie,
......
# Create your tests here.
......@@ -13,8 +13,9 @@ class EventTest(TestCase):
fixtures = ['members.json']
def setUp(self):
self.event = Event.objects.create(
@classmethod
def setUpTestData(cls):
cls.event = Event.objects.create(
title_nl='testevene',
title_en='testevent',
description_en='desc',
......@@ -26,11 +27,16 @@ class EventTest(TestCase):
map_location='test map location',
price=0.00,
fine=0.00)
self.member = Member.objects.all()[0]
cls.member = Member.objects.all()[0]
def test_end_after_start(self):
def setUp(self):
self.event.refresh_from_db()
self.member.refresh_from_db()
def test_clean_works(self):
self.event.clean()
def test_end_after_start(self):
self.event.start, self.event.end = self.event.end, self.event.start
with self.assertRaises(ValidationError):
self.event.clean()
......@@ -146,8 +152,7 @@ class EventTest(TestCase):
def test_not_reached_participants_limit(self):
self.event.max_participants = 1
r1 = Registration.objects.create(event=self.event, member=self.member)
r1.save()
Registration.objects.create(event=self.event, member=self.member)
self.assertTrue(self.event.reached_participants_limit())
......@@ -156,8 +161,9 @@ class RegistrationTest(TestCase):
fixtures = ['members.json']
def setUp(self):
self.event = Event.objects.create(
@classmethod
def setUpTestData(cls):
cls.event = Event.objects.create(
title_nl='testevene',
title_en='testevent',
description_en='desc',
......@@ -169,37 +175,38 @@ class RegistrationTest(TestCase):
map_location='test map location',
price=0.00,
fine=0.00)
self.member = Member.objects.all()[0]
cls.member = Member.objects.all()[0]
cls.r1 = Registration.objects.create(event=cls.event,
member=cls.member)
def setUp(self):
self.r1.refresh_from_db()
def test_is_late_registration(self):
r1 = Registration.objects.create(event=self.event, member=self.member)
self.assertFalse(r1.is_late_cancellation())
self.assertFalse(self.r1.is_late_cancellation())
r1.date_cancelled = timezone.now()
self.assertFalse(r1.is_late_cancellation())
self.r1.date_cancelled = timezone.now()
self.assertFalse(self.r1.is_late_cancellation())
self.event.cancel_deadline = (timezone.now() +
datetime.timedelta(hours=1))
self.assertFalse(r1.is_late_cancellation())
self.assertFalse(self.r1.is_late_cancellation())
self.event.cancel_deadline = (timezone.now() -
datetime.timedelta(hours=1))
self.assertTrue(r1.is_late_cancellation())
self.assertTrue(self.r1.is_late_cancellation())
def test_queue_position(self):
r1 = Registration.objects.create(event=self.event, member=self.member)
r1.save()
self.assertEqual(r1.queue_position(), 0)
self.assertEqual(self.r1.queue_position(), 0)
self.event.max_participants = 0
self.assertEqual(r1.queue_position(), 1)
self.assertEqual(self.r1.queue_position(), 1)
self.event.max_participants = 1
self.assertEqual(r1.queue_position(), 0)
self.assertEqual(self.r1.queue_position(), 0)
def test_registration_either_name_or_member(self):
r1 = Registration.objects.create(event=self.event, member=self.member)
r1.clean()
self.r1.clean()
r2 = Registration.objects.create(event=self.event, name='test name')
r2.clean()
with self.assertRaises(ValidationError):
......
......@@ -12,8 +12,9 @@ class RegistrationTest(TestCase):
fixtures = ['members.json']
def setUp(self):
self.event = Event.objects.create(
@classmethod
def setUpTestData(cls):
cls.event = Event.objects.create(
pk=1,
title_nl='testevene',
title_en='testevent',
......@@ -27,8 +28,9 @@ class RegistrationTest(TestCase):
map_location='test map location',
price=0.00,
fine=0.00)
self.event.save()
self.member = Member.objects.filter(user__last_name="Wiggers").first()
cls.member = Member.objects.filter(user__last_name="Wiggers").first()
def setUp(self):
self.client = Client()
self.client.force_login(self.member.user)
......@@ -90,8 +92,7 @@ class RegistrationTest(TestCase):
self.event.cancel_deadline = (timezone.now() +
datetime.timedelta(hours=1))
self.event.save()
r1 = Registration.objects.create(event=self.event, member=self.member)
r1.save()
Registration.objects.create(event=self.event, member=self.member)
response = self.client.post('/events/1/registration/cancel/',
follow=True)
self.assertEqual(response.status_code, 200)
......@@ -113,7 +114,6 @@ class RegistrationTest(TestCase):
name_en="test bool",
name_nl="test bool",
required=False)
field1.save()
field2 = RegistrationInformationField.objects.create(
pk=2,
......@@ -122,7 +122,6 @@ class RegistrationTest(TestCase):
name_en="test int",
name_nl="test int",
required=False)
field2.save()
field3 = RegistrationInformationField.objects.create(
pk=3,
......@@ -131,7 +130,6 @@ class RegistrationTest(TestCase):
name_en="test text",
name_nl="test text",
required=False)
field3.save()
response = self.client.post('/events/1/registration/register/',
{'info_field_1': True,
......@@ -155,13 +153,12 @@ class RegistrationTest(TestCase):
datetime.timedelta(hours=1))
self.event.save()
field = RegistrationInformationField.objects.create(
RegistrationInformationField.objects.create(
event=self.event,
type=RegistrationInformationField.TEXT_FIELD,
name_en="test",
name_nl="test",
required=True)
field.save()
response = self.client.post('/events/1/registration/register/',
follow=True)
......
......@@ -3,7 +3,7 @@
"model": "auth.user",
"pk": 1,
"fields": {
"password": "pbkdf2_sha256$30000$HIt9lBUpgkYG$T2ofXIOlAhsqfMUqzl3Vl9vyaDq50d1JJJNEYeZ9/OM=",
"password": "md5$wdVCeynupRVW$de1e35e14409c561c1b30a8d64d423d3",
"last_login": "2016-07-07T11:37:43Z",
"is_superuser": true,
"username": "thom",
......@@ -21,7 +21,7 @@
"model": "auth.user",
"pk": 2,
"fields": {
"password": "pbkdf2_sha256$30000$80KR811he3aB$W11Exs1wY0tXw9kLsyunh1dzvRDcn1a+Hc9m1lTirFY=",
"password": "md5$wdVCeynupRVW$de1e35e14409c561c1b30a8d64d423d3",
"last_login": "2016-07-07T12:01:02.638Z",
"is_superuser": false,
"username": "testuser",
......
from datetime import date, datetime, timedelta
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.test import TestCase
from django.utils import timezone
......@@ -60,32 +60,26 @@ class MemberBirthdayTest(TestCase):
class StatisticsTest(TestCase):
def setUp(self):
@classmethod
def setUpTestData(cls):
# Add 10 members with default membership
for i in range(10):
u = User(username=i)
u.save()
membership = Membership(user=u, type="member")
membership.save()
m = Member(user=u)
m.save()
users = [get_user_model()(id=i, username=i) for i in range(10)]
get_user_model().objects.bulk_create(users)
memberships = [Membership(user_id=i, type="member")
for i in range(10)]
Membership.objects.bulk_create(memberships)
members = [Member(user_id=i) for i in range(10)]
Member.objects.bulk_create(members)
def sum_members(self, members, type=None):
s = 0
for i in members:
if type is None:
for j in i.values():
s = s + j
else:
s = s + i[type]
return s
if type is None:
return sum(sum(i.values()) for i in members)
else:
return sum(map(lambda x: x[type], members))
def sum_member_types(self, members):
s = 0
for i in members.values():
s = s + i
return s
return sum(members.values())
def test_gen_stats_year_no_members(self):
member_types = ["member", "supporter", "honorary"]
......
......@@ -22,34 +22,36 @@ def load_tests(loader, tests, ignore):
class NewslettersTest(TestCase):
def setUp(self):
self.user = User.objects.create_user(username='jacob',
email='jacob@test.com',
password='top_secret',
is_staff=True)
self.user.user_permissions.set(
@classmethod
def setUpTestData(cls):
cls.user = User.objects.create_user(username='jacob',
email='jacob@test.com',
password='top_secret',
is_staff=True)
cls.user.user_permissions.set(
Permission.objects.filter(content_type__app_label="newsletters")
)
self.user.backend = 'django.contrib.auth.backends.ModelBackend'
self.user.save()
self.client.force_login(self.user)
cls.user.backend = 'django.contrib.auth.backends.ModelBackend'
cls.user.save()
self.testletter_sent = Newsletter.objects.create(
cls.testletter_sent = Newsletter.objects.create(
title_nl='testletter',
title_en='testletter',
description_nl='testdesc',
description_en='testdesc',
sent=True)
self.testletter_concept = Newsletter.objects.create(
cls.testletter_concept = Newsletter.objects.create(
title_nl='testletter',
title_en='testletter',
description_nl='testdesc',
description_en='testdesc',
sent=False)
def setUp(self):
self.client.force_login(self.user)
def test_sent_change_redirect(self):
response = self.client.get(reverse(
'admin:newsletters_newsletter_change', args=[
......
......@@ -25,19 +25,20 @@ class RaaSTestCase(SimpleTestCase):
class AppApiTestCase(TestCase):
"""Tests event registrations"""
def setUp(self):
self.user = get_user_model().objects.create_user(
@classmethod
def setUpTestData(cls):
cls.user = get_user_model().objects.create_user(
username='testuser',
first_name='first',
last_name='last_name',
email='foo@bar.com',
password='top secret')
self.member = Member.objects.create(
user=self.user,
cls.member = Member.objects.create(
user=cls.user,
birthday=datetime(1993, 3, 2)
)
self.token = Token.create_token(self.user)
cls.token = Token.create_token(cls.user)
def test_GET_denied(self):
response = self.client.get('/api/login')
......
......@@ -151,6 +151,12 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
# allow to use md5 in tests
PASSWORD_HASHERS = (
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.MD5PasswordHasher',
)
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'activemembers.backends.CommitteeBackend',
......
......@@ -4,6 +4,10 @@ Settings for CI testing
This file is loaded by __init__.py if GITLAB_CI is set in the environment
"""
import logging
from .settings import INSTALLED_APPS, MIDDLEWARE
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
......@@ -14,3 +18,26 @@ DATABASES = {
'PORT': 5432,
},
}
# This won't help anyway
DEBUG = False
logging.disable(logging.CRITICAL)
# Fasters hashing
PASSWORD_HASHERS = (
'django.contrib.auth.hashers.MD5PasswordHasher',
)
# Strip unneeded apps
[INSTALLED_APPS.remove(x) for x in (
'corsheaders',
)]
# Strip unneeded middlewares
[MIDDLEWARE.remove(x) for x in (
'corsheaders.middleware.CorsMiddleware',
'django.middleware.http.ConditionalGetMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment