-
Notifications
You must be signed in to change notification settings - Fork 394
/
notifications.py
58 lines (41 loc) · 1.75 KB
/
notifications.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import factory
from django.contrib.contenttypes.models import ContentType
from swapper import load_model
from notifications.tests.factories.users import (
ActorFactory,
RecipientFactory,
TargetFactory,
)
VERB_LIST_SHORT = ("reached level 60", "joined to site")
VERB_LIST_WITH_TARGET = (
"commented on",
"started follow",
"liked",
)
VERB_LIST_FULL = (
"closed",
"opened",
"liked",
)
Notification = load_model("notifications", "Notification")
class NotificationShortFactory(factory.django.DjangoModelFactory):
recipient = factory.SubFactory(RecipientFactory)
actor = factory.SubFactory(ActorFactory)
actor_object_id = factory.SelfAttribute("actor.id")
actor_content_type = factory.LazyAttribute(lambda obj: ContentType.objects.get_for_model(obj.actor))
verb = factory.Iterator(VERB_LIST_SHORT)
description = factory.Faker("catch_phrase")
class Meta:
model = Notification
class NotificationWithTargetFactory(NotificationShortFactory):
verb = factory.Iterator(VERB_LIST_WITH_TARGET)
target = factory.SubFactory(TargetFactory)
target_object_id = factory.SelfAttribute("target.id")
target_content_type = factory.LazyAttribute(lambda obj: ContentType.objects.get_for_model(obj.target))
class NotificationWithActionObjectFactory(NotificationShortFactory):
verb = factory.Iterator(VERB_LIST_WITH_TARGET)
action_object = factory.SubFactory(TargetFactory)
action_object_object_id = factory.SelfAttribute("action_object.id")
action_object_content_type = factory.LazyAttribute(lambda obj: ContentType.objects.get_for_model(obj.action_object))
class NotificationFullFactory(NotificationWithTargetFactory, NotificationWithActionObjectFactory):
verb = factory.Iterator(VERB_LIST_FULL)