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))
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))
def test_update_with_a_zero_rating(self): """ Ensure that if a rating is updated with zero, the overall rating returned is equal to zero """ overall = Rating.update(self.expedition, self.paltman, rating=0, category=self.speed) self.assertEquals(overall, Decimal("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))
def test_update_with_a_zero_rating(self): """ Ensure that if a rating is updated with zero, the overall rating returned is equal to zero """ overall = Rating.update(self.expedition, self.paltman, rating=0, category=self.speed) self.assertEquals(overall, Decimal("0"))
def create_rating(self, user, rating, obj=None, category=""): """ Helper function to post a rating for the benz object of type Car used in the tests :param user: User :param rating: int :param obj: obj :param category: str :return: http response object """ if not obj: obj = self.expedition cat_choice = category_value(obj, category) if not cat_choice: cat_choice = "" Rating.update(rating_object=obj, user=user, category=cat_choice, rating=rating)
def create_rating(self, user, rating, obj=None, category=""): """ Helper function to post a rating for the benz object of type Car used in the tests :param user: User :param rating: int :param obj: obj :param category: str :return: http response object """ if not obj: obj = self.expedition cat_choice = category_value(obj, category) if not cat_choice: cat_choice = "" Rating.update( rating_object=obj, user=user, category=cat_choice, rating=rating )
def test_rating(self): overall = Rating.update(self.bronco, self.paltman, rating=5) self.assertEquals(overall, Decimal("5")) overall = Rating.update(self.bronco, self.jtauber, rating=2) self.assertEquals(overall, Decimal("3.5"))
def test_rating(self): overall = Rating.update(self.bronco, self.paltman, rating=5) self.assertEquals(overall, Decimal("5")) overall = Rating.update(self.bronco, self.jtauber, rating=2) self.assertEquals(overall, Decimal("3.5"))