'Tests the activity functionality when a layer is saved.'

def test_layer_activity(self):

    self.assertEqual(Action.objects.all().count(), Layer.objects.all().count())
    action = Action.objects.all()[0]
    layer = action.action_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)
    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()
    action = Action.objects.all()[0]
    self.assertEqual(action.data.get('raw_action'), 'deleted')
    self.assertEqual(action.data.get('object_name'), layer_name)
    self.assertIsNone(action.action_object)
    self.assertIsNone(action.target)
    action = Action.objects.all()[0]
    template_tag = activity_item(action)
    self.assertEqual(template_tag.get('activity_class'), 'delete')
    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)
    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)
    self.assertIn(action, actor_stream(self.user))
