def testMapsNotifications(self): with self.settings(PINAX_NOTIFICATIONS_QUEUE_ALL=True): self.clear_notifications_queue() self.client.login(username=self.user, password=self.passwd) 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)) _l.title = 'test notifications 2' _l.save() self.assertTrue(self.check_notification_out('map_updated', self.u)) from dialogos.models import Comment lct = ContentType.objects.get_for_model(_l) comment = Comment(author=self.u, 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))
def testLayerNotifications(self): with self.settings(PINAX_NOTIFICATIONS_QUEUE_ALL=True): self.clear_notifications_queue() _l = Layer.objects.create(name='test notifications', bbox_x0=-180, bbox_x1=180, bbox_y0=-90, bbox_y1=90, srid='EPSG:4326') _l.name = 'test notifications 2' _l.save() self.assertTrue( self.check_notification_out('layer_updated', self.u)) from dialogos.models import Comment lct = ContentType.objects.get_for_model(_l) comment = Comment(author=self.u, 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('layer_comment', 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() # 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 testLayerNotifications(self): with self.settings(NOTIFICATION_QUEUE_ALL=True): self.clear_notifications_queue() l = Layer.objects.create(name='test notifications') l.name = 'test notifications 2' l.save() self.assertTrue(self.check_notification_out('layer_updated', self.u)) from dialogos.models import Comment lct = ContentType.objects.get_for_model(l) comment = Comment(author=self.u, 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('layer_comment', self.u))
def testDocumentNotifications(self): with self.settings(PINAX_NOTIFICATIONS_QUEUE_ALL=True): self.clear_notifications_queue() _d = Document.objects.create(title='test notifications', owner=self.u) self.assertTrue(self.check_notification_out('document_created', self.u)) _d.title = 'test notifications 2' _d.save() self.assertTrue(self.check_notification_out('document_updated', self.u)) from dialogos.models import Comment lct = ContentType.objects.get_for_model(_d) comment = Comment(author=self.u, name=self.u.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))
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 testLayerNotifications(self): with self.settings(PINAX_NOTIFICATIONS_QUEUE_ALL=True): self.clear_notifications_queue() _l = Layer.objects.create( name='test notifications', bbox_x0=-180, bbox_x1=180, bbox_y0=-90, bbox_y1=90, srid='EPSG:4326') _l.name = 'test notifications 2' _l.save() self.assertTrue(self.check_notification_out('layer_updated', self.u)) from dialogos.models import Comment lct = ContentType.objects.get_for_model(_l) comment = Comment(author=self.u, 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('layer_comment', self.u))
def testMapsNotifications(self): with self.settings(PINAX_NOTIFICATIONS_QUEUE_ALL=True): self.clear_notifications_queue() self.client.login(username=self.user, password=self.passwd) new_map = reverse('new_map_json') response = self.client.post(new_map, data=VIEWER_CONFIG, content_type="text/json") self.assertEquals(response.status_code, 200) map_id = int(json.loads(response.content)['id']) l = Map.objects.get(id=map_id) self.assertTrue(self.check_notification_out('map_created', self.u)) l.title = 'test notifications 2' l.save() self.assertTrue(self.check_notification_out('map_updated', self.u)) from dialogos.models import Comment lct = ContentType.objects.get_for_model(l) comment = Comment(author=self.u, 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))
def test_layer_activity(self): """ Tests the activity functionality when a layer is saved. """ # A new activity should be created for each Layer. self.assertEqual(Action.objects.all().count(), Layer.objects.all().count()) action = Action.objects.all()[0] layer = action.action_object # The activity should read: # layer.owner (actor) 'uploaded' (verb) layer (object) self.assertEqual(action.actor, action.action_object.owner) self.assertEqual(action.data.get('raw_action'), 'created') self.assertEqual(action.data.get('object_name'), layer.name) self.assertTrue(isinstance(action.action_object, Layer)) self.assertIsNone(action.target) # Test the activity_item template tag template_tag = activity_item(Action.objects.all()[0]) self.assertEqual(template_tag.get('username'), action.actor.username) self.assertEqual(template_tag.get('object_name'), layer.name) self.assertEqual(template_tag.get('actor'), action.actor) self.assertEqual(template_tag.get('verb'), _('uploaded')) self.assertEqual(template_tag.get('action'), action) self.assertEqual(template_tag.get('activity_class'), 'upload') layer_name = layer.name layer.delete() # <user> deleted <object_name> action = Action.objects.all()[0] self.assertEqual(action.data.get('raw_action'), 'deleted') self.assertEqual(action.data.get('object_name'), layer_name) # objects are literally deleted so no action object or target should be related to a delete action. self.assertIsNone(action.action_object) self.assertIsNone(action.target) # Test the activity_item template tag action = Action.objects.all()[0] template_tag = activity_item(action) # Make sure the 'delete' class is returned self.assertEqual(template_tag.get('activity_class'), 'delete') # The layer's name should be returned self.assertEqual(template_tag.get('object_name'), layer_name) self.assertEqual(template_tag.get('verb'), _('deleted')) content_type = ContentType.objects.get_for_model(Layer) layer = Layer.objects.all()[0] comment = Comment(author=self.user, content_type=content_type, object_id=layer.id, comment="This is a cool layer.") comment.save() action = Action.objects.all()[0] self.assertEqual(action.actor, self.user) self.assertEqual(action.data.get('raw_action'), 'created') self.assertEqual(action.action_object, comment) self.assertEqual(action.target, layer) template_tag = activity_item(action) # <user> added a comment on <target> self.assertEqual(template_tag.get('verb'), _('added a comment')) self.assertEqual(template_tag.get('activity_class'), 'comment') self.assertEqual(template_tag.get('target'), action.target) self.assertEqual(template_tag.get('preposition'), _('on')) self.assertIsNone(template_tag.get('object')) self.assertEqual(template_tag.get('target'), layer) # Pre-fecthing actstream breaks the actor stream self.assertIn(action, actor_stream(self.user))