def test_foia_list_user(self): """Test the foia-list-user view""" users = UserFactory.create_batch(2) FOIARequestFactory.create_batch(4, composer__user=users[0]) FOIARequestFactory.create_batch(3, composer__user=users[1]) for user in users: response = get_allowed( self.client, reverse('foia-list-user', kwargs={ 'user_pk': user.pk, }) ) nose.tools.eq_( set(response.context['object_list']), set( FOIARequest.objects.get_viewable(AnonymousUser()) .filter(composer__user=user) ) ) nose.tools.ok_( all( foia.user == user for foia in response.context['object_list'] ) )
def test_feeds(self): """Test the RSS feed views""" user = UserFactory() foias = FOIARequestFactory.create_batch(4, composer__user=user) get_allowed(self.client, reverse('foia-submitted-feed')) get_allowed(self.client, reverse('foia-done-feed')) get_allowed( self.client, reverse('foia-feed', kwargs={ 'idx': foias[0].pk }) ) get_allowed( self.client, reverse( 'foia-user-submitted-feed', kwargs={ 'username': user.username } ) ) get_allowed( self.client, reverse('foia-user-done-feed', kwargs={ 'username': user.username }) ) get_allowed( self.client, reverse('foia-user-feed', kwargs={ 'username': user.username }) )
def test_move(self): foias = FOIARequestFactory.create_batch(2) foia_1_comm_count = foias[0].communications.all().count() foia_2_comm_count = foias[1].communications.all().count() starting_date = self.task.communication.datetime self.client.post( self.url, { 'move': True, 'foia_pks': ', '.join(str(f.pk) for f in foias), 'task': self.task.pk, }, ) updated_foia_1_comm_count = foias[0].communications.all().count() updated_foia_2_comm_count = foias[1].communications.all().count() updated_task = OrphanTask.objects.get(pk=self.task.pk) ending_date = updated_task.communication.datetime ok_( updated_task.resolved, 'Orphan task should be resolved by posting the FOIA pks and task ID.' ) eq_( updated_foia_1_comm_count, foia_1_comm_count + 1, 'Communication should be added to FOIA' ) eq_( updated_foia_2_comm_count, foia_2_comm_count + 1, 'Communication should be added to FOIA' ) eq_( starting_date, ending_date, 'The date of the communication should not change.' )
def test_following_request_list(self): """Test to make sure following request list shows correct requests""" user = UserFactory() factory = RequestFactory() request = factory.get(reverse('foia-list-following')) request.user = user foias = FOIARequestFactory.create_batch(7) for foia in foias[::2]: follow(user, foia) response = FollowingRequestList.as_view()(request) eq_(len(response.context_data['object_list']), 4) for foia in foias[::2]: nose.tools.assert_in(foia, response.context_data['object_list']) unfollow(user, foias[2]) response = FollowingRequestList.as_view()(request) eq_(len(response.context_data['object_list']), 3) for foia in (foias[0], foias[4], foias[6]): nose.tools.assert_in(foia, response.context_data['object_list'])