Project for the UPV to develop an app like BlaBlaCar but only for UPV people.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

added tests for notifications

+96
+13
upvcarshare/notifications/tests/factories.py
··· 1 + # -*- coding: utf-8 -*- 2 + from __future__ import unicode_literals, print_function, absolute_import 3 + 4 + import factory 5 + 6 + from users.tests.factories import UserFactory 7 + 8 + 9 + class NotificationFactory(factory.django.DjangoModelFactory): 10 + user = factory.SubFactory(UserFactory) 11 + 12 + class Meta: 13 + model = "notifications.Notification"
+47
upvcarshare/notifications/tests/test_api.py
··· 1 1 # -*- coding: utf-8 -*- 2 2 from __future__ import unicode_literals, print_function, absolute_import 3 + 4 + import json 5 + import random 6 + 7 + from rest_framework import status 8 + from rest_framework.test import APITestCase 9 + 10 + from journeys import GOING 11 + from journeys.tests.factories import CampusFactory, JourneyFactory 12 + from journeys.tests.factories import ResidenceFactory 13 + from notifications import JOIN 14 + from notifications import LEAVE 15 + from notifications.tests.factories import NotificationFactory 16 + from users.tests.factories import UserFactory 17 + 18 + 19 + class NotificationAPITests(APITestCase): 20 + 21 + def setUp(self): 22 + self.user = UserFactory() 23 + 24 + @staticmethod 25 + def _make_journey(user=None, kind=GOING): 26 + user = UserFactory() if user is None else user 27 + origin = ResidenceFactory(user=user) 28 + destination = CampusFactory() 29 + return JourneyFactory(user=user, residence=origin, campus=destination, kind=kind) 30 + 31 + def test_get_notifications(self): 32 + [NotificationFactory( 33 + user=self.user, 34 + verb=random.choice([JOIN, LEAVE]), 35 + actor=UserFactory(), 36 + target=self._make_journey(self.user) 37 + ) for _ in range(5)] 38 + [NotificationFactory( 39 + user=UserFactory(), 40 + verb=random.choice([JOIN, LEAVE]), 41 + actor=UserFactory(), 42 + target=self._make_journey(self.user) 43 + ) for _ in range(5)] 44 + url = "/api/v1/notifications/" 45 + self.client.force_authenticate(user=self.user) 46 + response = self.client.get(url) 47 + self.assertEqual(response.status_code, status.HTTP_200_OK) 48 + response_data = json.loads(response.content.decode('utf-8')) 49 + self.assertEquals(5, len(response_data['results']))
+36
upvcarshare/notifications/tests/test_models.py
··· 1 1 # -*- coding: utf-8 -*- 2 2 from __future__ import unicode_literals, print_function, absolute_import 3 + 4 + from test_plus import TestCase 5 + 6 + from journeys import GOING 7 + from journeys.tests.factories import CampusFactory 8 + from journeys.tests.factories import ResidenceFactory, JourneyFactory 9 + from notifications import JOIN, LEAVE 10 + from notifications.models import Notification 11 + from users.tests.factories import UserFactory 12 + 13 + 14 + class NotificationTests(TestCase): 15 + 16 + def setUp(self): 17 + self.user = UserFactory() 18 + 19 + @staticmethod 20 + def _make_journey(user=None, kind=GOING): 21 + user = UserFactory() if user is None else user 22 + origin = ResidenceFactory(user=user) 23 + destination = CampusFactory() 24 + return JourneyFactory(user=user, residence=origin, campus=destination, kind=kind) 25 + 26 + def test_join_generation(self): 27 + user = UserFactory() 28 + journey = self._make_journey(self.user) 29 + journey.join_passenger(user) 30 + self.assertEquals(1, Notification.objects.filter(user=self.user, verb=JOIN).count()) 31 + 32 + def test_leave_generation(self): 33 + user = UserFactory() 34 + journey = self._make_journey(self.user) 35 + journey.join_passenger(user) 36 + journey.leave_passenger(user) 37 + self.assertEquals(1, Notification.objects.filter(user=self.user, verb=JOIN).count()) 38 + self.assertEquals(1, Notification.objects.filter(user=self.user, verb=LEAVE).count())