def test_filter_on_task_wallpost_list(self): """ Tests that project initiator can post and view task wallposts """ self.project.task_manager = BlueBottleUserFactory.create() self.project.promoter = BlueBottleUserFactory.create() self.project.save() authenticated = Group.objects.get(name='Authenticated') authenticated.permissions.remove( Permission.objects.get(codename='api_read_wallpost')) authenticated.permissions.add( Permission.objects.get(codename='api_read_own_wallpost')) MediaWallpostFactory.create_batch(3, content_object=self.task) response = self.client.get(self.wallpost_url, { 'parent_id': str(self.task.id), 'parent_type': 'task' }, token=self.owner_token) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['count'], 3)
def test_wallpost_owner(self): MediaWallpostFactory.create( content_object=self.activity, author=self.activity.owner, email_followers=True ) self.assertEqual(len(mail.outbox), 1) follow_mail = mail.outbox[0] self.assertEqual( follow_mail.subject, "Update from '{}'".format(self.activity.title) )
def test_wallpost_owner(self): MediaWallpostFactory.create(content_object=self.initiative, author=self.initiative.owner, email_followers=True) self.assertEqual(len(mail.outbox), 1) follow_mail = mail.outbox[0] self.assertEqual(follow_mail.subject, "Update from '{}'".format(self.initiative.title)) self.assertTrue('{} posted an update to {}'.format( self.initiative.owner.first_name, self.initiative.title) in follow_mail.body)
def test_wallpost(self): wallpost_user = BlueBottleUserFactory.create() MediaWallpostFactory.create(content_object=self.initiative, author=wallpost_user, email_followers=False) self.assertEqual(len(mail.outbox), 1) owner_mail = mail.outbox[0] self.assertEqual( owner_mail.subject, "You have a new post on '{}'".format(self.initiative.title))
def test_task_textwallpost_admin(self): task = AssignmentFactory.create() self.wallpost = MediaWallpostFactory.create(content_object=task) url = reverse('admin:wallposts_mediawallpost_change', args=(self.wallpost.id, )) response = self.client.get(url) self.assertEqual(response.status_code, 200, response.content) self.assertContains(response, task.title)
def test_fundraiser_textwallpost_admin(self): event = EventFactory() self.wallpost = MediaWallpostFactory.create(content_object=event) url = reverse('admin:wallposts_mediawallpost_change', args=(self.wallpost.id, )) response = self.client.get(url) self.assertEqual(response.status_code, 200, response.content) self.assertContains(response, event.title)
def test_reaction(self): reaction_user = BlueBottleUserFactory.create() wallpost_user = BlueBottleUserFactory.create() wallpost = MediaWallpostFactory.create( content_object=self.activity, author=wallpost_user, email_followers=True ) mail.outbox = [] ReactionFactory.create( wallpost=wallpost, author=reaction_user ) self.assertEqual(len(mail.outbox), 2) wallpost_owner_mail = mail.outbox[0] self.assertEqual( wallpost_owner_mail.subject, "You have a new post on '{}'".format(self.activity.title) ) owner_mail = mail.outbox[1] self.assertEqual( owner_mail.subject, "You have a new post on '{}'".format(self.activity.title) )
def setUp(self): super(WallpostPhotoTest, self).setUp() self.owner = BlueBottleUserFactory.create() self.owner_token = "JWT {0}".format(self.owner.get_jwt_token()) self.initiative = InitiativeFactory.create(owner=self.owner) self.funding = FundingFactory.create(target=Money(5000, 'EUR'), status='open', initiative=self.initiative) self.wallpost = MediaWallpostFactory.create(content_object=self.funding) self.photo = MediaWallpostPhotoFactory( author=self.wallpost.author, mediawallpost=MediaWallpostFactory.create(content_object=self.funding, author=self.wallpost.author) ) self.url = reverse('mediawallpost_photo_detail', args=(self.photo.pk, ))
def test_project_systemwallpost_admin(self): funding = FundingFactory.create() donation = DonationFactory(activity=funding) self.wallpost = MediaWallpostFactory.create(content_object=funding, donation=donation) url = reverse('admin:wallposts_mediawallpost_change', args=(self.wallpost.id, )) response = self.client.get(url) self.assertEqual(response.status_code, 200, response.content) self.assertContains(response, funding.title)
def test_pinned_wallposts(self): wallpost = MediaWallpostFactory.create(author=self.initiator, content_object=self.initiative) wallpost.refresh_from_db() self.assertEqual(wallpost.pinned, True) MediaWallpostFactory.create(author=self.user, content_object=self.initiative) MediaWallpostFactory.create(author=self.initiator, content_object=self.initiative) MediaWallpostFactory.create_batch(3, author=self.user, content_object=self.initiative) response = self.client.get(self.wallpost_url, {'parent_id': self.initiative.id, 'parent_type': 'initiative'}, token=self.user_token) # There should be 6 wallposts self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data['results']), 6) # First post should by latest by the initiator self.assertEqual(response.data['results'][0]['author']['id'], self.initiator.id) self.assertEqual(response.data['results'][0]['pinned'], True) # Second item shoudl be by user and unpinned self.assertEqual(response.data['results'][1]['author']['id'], self.user.id) self.assertEqual(response.data['results'][1]['pinned'], False) # The sixth wallposts should be by initiator but unpinned self.assertEqual(response.data['results'][5]['author']['id'], self.initiator.id) self.assertEqual(response.data['results'][5]['pinned'], False)
def test_wallpost(self): wallpost_user = BlueBottleUserFactory.create() MediaWallpostFactory.create( content_object=self.activity, author=wallpost_user, email_followers=False ) self.assertEqual(len(mail.outbox), 1) owner_mail = mail.outbox[0] self.assertEqual( owner_mail.subject, "You have a new post on '{}'".format(self.activity.title) ) self.assertTrue( "{} posted a comment to '{}'.".format(wallpost_user.first_name, self.activity.title) in owner_mail.body )
def test_mediawallpost_admin(self): initiative = InitiativeFactory.create() self.wallpost = MediaWallpostFactory.create(content_object=initiative) MediaWallpostPhotoFactory.create_batch(10, mediawallpost=self.wallpost) self.wallpost.save() response = self.client.get(self.media_wallpost_url) self.assertContains(response, '9 more') url = reverse('admin:wallposts_mediawallpost_change', args=(self.wallpost.id, )) response = self.client.get(url) self.assertContains(response, initiative.title)
def test_photo_different_wallpost_owner(self): photo_author = BlueBottleUserFactory.create() self.photo.author = photo_author self.photo.mediawallpost = MediaWallpostFactory.create(content_object=self.funding, author=photo_author) self.photo.save() response = self.client.put( self.url, data={ 'mediawallpost': self.wallpost.pk }, token="JWT {0}".format(self.photo.author.get_jwt_token()) ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_filter_on_assignment_wallpost_list(self): self.initiative.activity_manager = BlueBottleUserFactory.create() self.initiative.promoter = BlueBottleUserFactory.create() self.initiative.save() authenticated = Group.objects.get(name='Authenticated') authenticated.permissions.remove( Permission.objects.get(codename='api_read_wallpost') ) authenticated.permissions.add( Permission.objects.get(codename='api_read_own_wallpost') ) MediaWallpostFactory.create_batch(3, content_object=self.initiative) response = self.client.get( self.wallpost_url, {'parent_id': self.initiative.id, 'parent_type': 'initiative'}, token=self.owner_token ) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['count'], 3)
def test_put(self): wallpost = MediaWallpostFactory.create(content_object=self.funding) author = wallpost.author url = reverse('wallpost_detail', args=(wallpost.pk, )) response = self.client.put( url, data={ 'author': BlueBottleUserFactory.create().pk, 'parent_id': self.funding.pk, 'parent_type': 'funding' }, token="JWT {0}".format(author.get_jwt_token()) ) self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
def test_filtering_on_wallpost_list(self): authenticated = Group.objects.get(name='Authenticated') authenticated.permissions.remove( Permission.objects.get(codename='api_read_mediawallpost')) authenticated.permissions.add( Permission.objects.get(codename='api_read_own_mediawallpost')) MediaWallpostFactory.create(content_object=self.task) MediaWallpostFactory.create(content_object=self.project) MediaWallpostFactory.create(content_object=self.fundraiser) MediaWallpostFactory.create(content_object=ProjectFactory( owner=self.other_user)) response = self.client.get(self.media_wallpost_url, token=self.owner_token) self.assertEqual(response.data['count'], 3) response = self.client.get(self.media_wallpost_url, token=self.other_token) self.assertEqual(response.data['count'], 1)
def setUp(self): super(WallpostDeletePermissionTest, self).setUp() self.owner = BlueBottleUserFactory.create() self.owner_token = "JWT {0}".format(self.owner.get_jwt_token()) self.author_user = BlueBottleUserFactory.create() self.author_token = "JWT {0}".format( self.author_user.get_jwt_token()) self.other_user = BlueBottleUserFactory.create() self.other_token = "JWT {0}".format( self.other_user.get_jwt_token()) self.initiative = InitiativeFactory.create(owner=self.owner) self.wallpost = MediaWallpostFactory.create( content_object=self.initiative, author=self.author_user ) self.wallpost_detail_url = reverse('wallpost_detail', args=(self.wallpost.id, ))