Beispiel #1
0
    def test_offer_list_fields(self):
        """Test list's fields of offers REST API endpoint."""
        OfferFactory.create_batch(42)

        response = self.client.get('/api/offers/')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        for offer in response.data:
            common.test_offer_list_fields(self, offer)
Beispiel #2
0
    def test_offers_list_for_admin(self):
        """Test offers' list for account of admin."""
        OfferFactory.create_batch(37)

        self.client.force_login(
            UserFactory(userprofile__is_administrator=True))

        response = self.client.get('/o/offers')

        self._test_offers_list(response)
        self.assertEqual(len(response.context['offers']), 37)
Beispiel #3
0
    def test_offer_list_length(self):
        """Test offers list length for admin user.

        All existing offers are visible for admin user.
        """
        OfferFactory.create_batch(42)

        response = self.client.get('/api/offers/')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 42)
Beispiel #4
0
    def test_user_joined_some_offers(self):
        """Tests if user joined more than one offer."""

        user = UserFactory()
        self.client.force_login(user=user)

        OfferFactory.create_batch(2, volunteers=[user])

        # offer that user did not join
        OfferFactory(volunteers=UserFactory.create_batch(10))

        res = self.client.get(ENDPOINT_URL)

        self.assertEqual(res.status_code, 200)
        self.assertEqual(len(res.data), 2)
Beispiel #5
0
 def test_organization_offer_read_status(self):
     """Test organization offer's read status for user with organization."""
     for offer in OfferFactory.create_batch(94,
                                            organization=self.organization):
         response = self.client.get('/api/offers/{id}/'.format(id=offer.id))
         self.assertEqual(response.status_code, status.HTTP_200_OK)
         common.test_offer_list_fields(self, response.data)
Beispiel #6
0
    def test_offer_read_status(self):
        """Test offer's read status for admin user.

        All existing offers are visible for admin user.
        """
        for offer in OfferFactory.create_batch(63):
            response = self.client.get('/api/offers/{id}/'.format(id=offer.id))
            self.assertEqual(response.status_code, status.HTTP_200_OK)
            common.test_offer_list_fields(self, response.data)
 def setUp(self):
     super().setUp()
     user = UserFactory()
     self.client.force_login(user)
     OfferFactory.create_batch(
         67,
         offer_status='published',
         finished_at=None,
         recruitment_end_date=None,
         volunteers=UserFactory.create_batch(20)
     )
     OfferFactory.create_batch(
         73,
         offer_status='published',
         finished_at=None,
         recruitment_end_date=None,
         volunteers=UserFactory.create_batch(20) + [user]
     )
Beispiel #8
0
    def test_offer_list_length(self):
        """Test offers list length for user with organization.

        Because we set up 74 unpublished offer create for user's organization
        and 21 published, user with organization will see 95 offers.
        """
        OfferFactory.create_batch(21, offer_status='published')
        OfferFactory.create_batch(37, offer_status='unpublished')
        OfferFactory.create_batch(42, offer_status='rejected')
        OfferFactory.create_batch(74, organization=self.organization)

        response = self.client.get('/api/offers/')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 95)
Beispiel #9
0
    def test_offer_list_length(self):
        """Test offers list length for anonymous user.

        Because we set up 13 published offers, only them will be visible for
        anonymous user.
        """
        OfferFactory.create_batch(13, offer_status='published')
        OfferFactory.create_batch(54, offer_status='unpublished')
        OfferFactory.create_batch(47, offer_status='rejected')

        response = self.client.get('/api/offers/')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 13)
Beispiel #10
0
    def test_offer_list_for_anonymous_user(self):
        """Test offers' list for anonymus user."""
        OfferFactory.create_batch(
            31,
            offer_status='published',
            finished_at=None,
            recruitment_end_date=None,
        )
        OfferFactory.create_batch(48, offer_status='unpublished')
        OfferFactory.create_batch(52, offer_status='rejected')

        response = self.client.get('/o/offers')

        self._test_offers_list(response)
        self.assertEqual(len(response.context['offers']), 31)
Beispiel #11
0
    def test_offers_list_for_volunteer(self):
        """Test offers' list for account of volunteer."""
        OfferFactory.create_batch(
            67,
            offer_status='published',
            finished_at=None,
            recruitment_end_date=None,
        )
        OfferFactory.create_batch(73, offer_status='unpublished')
        OfferFactory.create_batch(89, offer_status='rejected')

        self.client.force_login(UserFactory())

        response = self.client.get('/o/offers')

        self._test_offers_list(response)
        self.assertEqual(len(response.context['offers']), 67)
Beispiel #12
0
    def test_offers_list_for_organization(self):
        """Test offers' list for account of organization."""
        OfferFactory.create_batch(
            96,
            offer_status='published',
            finished_at=None,
            recruitment_end_date=None,
        )
        OfferFactory.create_batch(17, offer_status='unpublished')
        OfferFactory.create_batch(22, offer_status='rejected')

        self.client.force_login(
            UserFactory(userprofile__organizations=[OrganizationFactory()]))

        response = self.client.get('/o/offers')

        self._test_offers_list(response)
        self.assertEqual(len(response.context['offers']), 96)
Beispiel #13
0
 def test_published_offer_read_status(self):
     """Test published offer's read status for anonymous user."""
     for offer in OfferFactory.create_batch(41, offer_status='published'):
         response = self.client.get('/api/offers/{id}/'.format(id=offer.id))
         self.assertEqual(response.status_code, status.HTTP_200_OK)
         common.test_offer_list_fields(self, response.data)
Beispiel #14
0
 def test_rejected_offer_read_status(self):
     """Test rejected offer's read status for regular user."""
     for offer in OfferFactory.create_batch(33, offer_status='rejected'):
         response = self.client.get('/api/offers/{id}/'.format(id=offer.id))
         self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Beispiel #15
0
 def test_unpublished_offer_read_status(self):
     """Test unpublished offer's read status for user with organization."""
     for offer in OfferFactory.create_batch(12, offer_status='unpublished'):
         response = self.client.get('/api/offers/{id}/'.format(id=offer.id))
         self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)