poulpe/communication/tests.py

59 lines
2 KiB
Python
Raw Normal View History

2017-07-18 17:18:54 +02:00
from django.contrib.auth.models import Group
from django.contrib.auth import get_user_model
from django.test import TestCase
from datetime import timedelta
from django.utils import timezone
from .models import (UserSubscription, GroupSubscription)
from event.models import Event
User = get_user_model()
class SubscriptionTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.root = User.objects.create(username='root')
cls.user_true = User.objects.create(username='usertrue')
cls.user_false = User.objects.create(username='userfalse')
cls.user_group_true = User.objects.create(username='usergrouptrue')
cls.user_group_false = User.objects.create(username='usergroupfalse')
cls.group = Group.objects.create(name="TestGroup")
cls.user_group_true.groups.add(cls.group)
cls.user_group_false.groups.add(cls.group)
cls.event = Event.objects.create(
title='TestEvent',
slug='test',
created_by=cls.root,
creation_date=timezone.now(),
description="Ceci est un test",
beginning_date=timezone.now()
+ timedelta(days=30),
ending_date=timezone.now()
+ timedelta(days=31),
)
cls.groupsub = GroupSubscription.objects.create(
content_object=cls.event,
group=cls.group
)
cls.groupunsub = UserSubscription.objects.create(
content_object=cls.event,
user=cls.user_group_false,
is_unsub=True
)
cls.userunsub = UserSubscription.objects.create(
content_object=cls.event,
user=cls.user_false,
is_unsub=True
)
cls.usersub = UserSubscription.objects.create(
content_object=cls.event,
user=cls.user_true,
is_unsub=False
)
def test_all_subs(self):
self.assertSetEqual(set(self.event.get_all_subscribers()),
{self.user_true, self.user_group_true})