Esempio n. 1
0
    def testMapsNotifications(self):
        with self.settings(EMAIL_ENABLE=True,
                           NOTIFICATION_ENABLED=True,
                           NOTIFICATIONS_BACKEND=
                           "pinax.notifications.backends.email.EmailBackend",
                           PINAX_NOTIFICATIONS_QUEUE_ALL=False):
            self.clear_notifications_queue()

            # first create a map
            url = reverse("maps-list")

            data = {
                "title": "Some created map",
                "maplayers": [{
                    "name": "base:nic_admin",
                }]
            }
            self.client.login(username='******', password='******')
            response = self.client.post(url,
                                        data=json.dumps(data),
                                        content_type="application/json")
            self.assertEqual(response.status_code, 201)

            map_id = int(response.data["map"]["pk"])
            _l = Map.objects.get(id=map_id)

            self.assertTrue(self.check_notification_out('map_created', self.u))

            self.clear_notifications_queue()
            _l.title = 'test notifications 2'
            _l.save(notify=True)
            self.assertTrue(self.check_notification_out('map_updated', self.u))

            self.clear_notifications_queue()
            from dialogos.models import Comment
            lct = ContentType.objects.get_for_model(_l)
            comment = Comment(author=self.norman,
                              name=self.u.username,
                              content_type=lct,
                              object_id=_l.id,
                              content_object=_l,
                              comment='test comment')
            comment.save()
            self.assertTrue(self.check_notification_out('map_comment', self.u))

            self.clear_notifications_queue()
            if "pinax.ratings" in settings.INSTALLED_APPS:
                self.clear_notifications_queue()
                from pinax.ratings.models import Rating
                rating = Rating(user=self.norman,
                                content_type=lct,
                                object_id=_l.id,
                                content_object=_l,
                                rating=5)
                rating.save()
                self.assertTrue(
                    self.check_notification_out('map_rated', self.u))
Esempio n. 2
0
    def testMapsNotifications(self):
        with self.settings(EMAIL_ENABLE=True,
                           NOTIFICATION_ENABLED=True,
                           NOTIFICATIONS_BACKEND=
                           "pinax.notifications.backends.email.EmailBackend",
                           PINAX_NOTIFICATIONS_QUEUE_ALL=False):
            self.clear_notifications_queue()
            self.client.login(username='******', password='******')
            new_map = reverse('new_map_json')
            response = self.client.post(new_map,
                                        data=VIEWER_CONFIG,
                                        content_type="text/json")
            self.assertEqual(response.status_code, 200)
            content = response.content
            if isinstance(content, bytes):
                content = content.decode('UTF-8')
            map_id = int(json.loads(content)['id'])
            _l = Map.objects.get(id=map_id)
            self.assertTrue(self.check_notification_out('map_created', self.u))

            self.clear_notifications_queue()
            _l.title = 'test notifications 2'
            _l.save(notify=True)
            self.assertTrue(self.check_notification_out('map_updated', self.u))

            self.clear_notifications_queue()
            from dialogos.models import Comment
            lct = ContentType.objects.get_for_model(_l)
            comment = Comment(author=self.norman,
                              name=self.u.username,
                              content_type=lct,
                              object_id=_l.id,
                              content_object=_l,
                              comment='test comment')
            comment.save()
            self.assertTrue(self.check_notification_out('map_comment', self.u))

            self.clear_notifications_queue()
            if "pinax.ratings" in settings.INSTALLED_APPS:
                self.clear_notifications_queue()
                from pinax.ratings.models import Rating
                rating = Rating(user=self.norman,
                                content_type=lct,
                                object_id=_l.id,
                                content_object=_l,
                                rating=5)
                rating.save()
                self.assertTrue(
                    self.check_notification_out('map_rated', self.u))
Esempio n. 3
0
    def testDocumentsNotifications(self):
        with self.settings(EMAIL_ENABLE=True,
                           NOTIFICATION_ENABLED=True,
                           NOTIFICATIONS_BACKEND=
                           "pinax.notifications.backends.email.EmailBackend",
                           PINAX_NOTIFICATIONS_QUEUE_ALL=False):
            self.clear_notifications_queue()
            self.client.login(username=self.user, password=self.passwd)
            _d = Document.objects.create(title='test notifications',
                                         owner=self.norman)
            self.assertTrue(
                self.check_notification_out('document_created', self.u))
            # Ensure "resource.owner" won't be notified for having created its own document
            self.assertFalse(
                self.check_notification_out('document_created', self.norman))

            self.clear_notifications_queue()
            _d.title = 'test notifications 2'
            _d.save(notify=True)
            self.assertTrue(
                self.check_notification_out('document_updated', self.u))

            self.clear_notifications_queue()
            from dialogos.models import Comment
            lct = ContentType.objects.get_for_model(_d)
            comment = Comment(author=self.norman,
                              name=self.norman.username,
                              content_type=lct,
                              object_id=_d.id,
                              content_object=_d,
                              comment='test comment')
            comment.save()
            self.assertTrue(
                self.check_notification_out('document_comment', self.u))

            if "pinax.ratings" in settings.INSTALLED_APPS:
                self.clear_notifications_queue()
                from pinax.ratings.models import Rating
                rating = Rating(user=self.norman,
                                content_type=lct,
                                object_id=_d.id,
                                content_object=_d,
                                rating=5)
                rating.save()
                self.assertTrue(
                    self.check_notification_out('document_rated', self.u))