Beispiel #1
0
def initialize_filled_volunteer_and_organization():
    """Initialize volunteer filled with data."""

    # create volunteer user
    volunteer_user2 = UserFactory(
        email='*****@*****.**',
        password='******'
    )

    # create organization user to create offers
    organization2 = OrganizationFactory()
    # this is required due to login to this user
    UserFactory(
        email='*****@*****.**',
        password='******',
        userprofile__organizations=[organization2]
    )

    # create organization offers and assign volunteer to them
    for _ in range(11, 15):
        OfferFactory(
            organization=organization2,
            offer_status='published',
            volunteers=[volunteer_user2]
        )

    # create additional organization offers for administrator use
    for _ in range(100, 110):
        OfferFactory(
            organization=organization2,
            offer_status='unpublished',
        )

    return volunteer_user2, organization2
Beispiel #2
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 #3
0
 def test_second_registration(self):
     """Test register if user is registered already"""
     UserFactory.create(
         email="*****@*****.**",
         password="******",
     )
     response = self.client.post(
         reverse('register'),
         json.dumps({
             "email": "*****@*****.**",
             "password": "******"
         }),
         content_type='application/json'
     )
     self.assertEqual(response.status_code, 201)
Beispiel #4
0
    def test_get(self):
        for _ in range(5):
            UserFactory.create()

        admin_emails = sorted(
            UserFactory.create(userprofile__is_administrator=True).email
            for _ in range(2))

        res = self.client.get(ENDPOINT_URL)

        self.assertDictEqual(
            res.data, {
                'administrator_emails': admin_emails,
                'applicant_types': ContactSerializer.APPLICANT_CHOICES,
            })
Beispiel #5
0
    def setUp(self):
        """Set up test for OfferFactory"""

        self.fake_user1 = UserFactory.create(
            first_name="Fake user first_name1",
            last_name="Fake user last_name1")
        self.fake_user2 = UserFactory.create(
            first_name="Fake user first_name2",
            last_name="Fake user last_name2")
        self.fake_offer1 = OfferFactory.create(volunteers=User.objects.all())
        self.fake_offer2 = OfferFactory.create(
            title="Jakiś tytuł",
            description="Zwięzły opis",
            organization__name="Nazwa odnośnej organizacji")
        self.fake_offer3 = OfferFactory.create(
            organization=Organization.objects.last())
Beispiel #6
0
def initialize_empty_organization():
    """Initialize empty organization."""
    organization1 = OrganizationFactory()
    UserFactory(email='*****@*****.**',
                password='******',
                userprofile__organizations=[organization1])
    return organization1
Beispiel #7
0
    def test_does_not_raise_error_if_user_is_admin(self):
        user = UserFactory.create(userprofile__is_administrator=True)

        try:
            validate_admin_email(user.email)
        except ValidationError:
            self.fail('raised error when user is admin')
Beispiel #8
0
 def setUp(self):
     """Set up each test."""
     super().setUp()
     self.organization = OrganizationFactory()
     self.client.force_login(UserFactory(
         userprofile__organizations=[self.organization]
     ))
Beispiel #9
0
 def setUp(self):
     """Set up each test."""
     super(TestAuthenticatedUserJoinOffer, self).setUp()
     self.user = UserFactory.create()
     self.offer = OfferFactory.create()
     self.offer.publish()
     self.client.force_login(self.user)
 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 #11
0
    def test_raises_error_if_user_is_not_admin(self):
        user = UserFactory.create(userprofile__is_administrator=False)

        with self.assertRaises(
                ValidationError,
                msg='Administrator o adresie e-mail {} nie istnieje.'.format(
                    user.email, ),
        ):
            validate_admin_email(user.email)
Beispiel #12
0
 def setUpTestData(cls):
     """Fixtures for Offer model unittests."""
     volunteers = [
         UserFactory(email='*****@*****.**'),
         UserFactory(email='*****@*****.**'),
         UserFactory(email='*****@*****.**'),
     ]
     offer = OfferFactory(
         organization__name='Some great organization',
         description='A lot of unnecessary work.',
         requirements='Patience, lot of free time',
         time_commitment='12.12.2015',
         benefits='Friends with benefits',
         location='Poland, Poznań',
         title='Example Offer Title',
         time_period='2-5 times a week',
     )
     for volunteer in volunteers:
         offer.volunteers.add(volunteer)
Beispiel #13
0
    def test_user_joined_no_offers(self):
        """Tests if user did not join any offer."""

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

        res = self.client.get(ENDPOINT_URL)

        self.assertEqual(res.status_code, 200)
        self.assertEqual(res.data, [])
Beispiel #14
0
def initialize_empty_volunteer():
    """Initialize empty volunteer."""
    volunteer_user1 = UserFactory(
        email='*****@*****.**',
        password='******',
        first_name='Grzegorz',
        last_name='Brzęczyszczykiewicz',
        userprofile__phone_no='333666999',
    )
    return volunteer_user1
Beispiel #15
0
    def test_login(self):
        user = UserFactory(password='******',
                           userprofile__organizations=[OrganizationFactory()])

        res = self.client.post(ENDPOINT_URL, {
            'username': user.username,
            'password': '******'
        },
                               format='json')

        self.assertEqual(res.status_code, 200)
Beispiel #16
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 #17
0
    def test_login(self):
        user = UserFactory.create(password='******')
        organization = OrganizationFactory.create()
        organization.userprofiles = [user.userprofile]
        organization.save()

        res = self.client.post(ENDPOINT_URL, {
            'username': user.username,
            'password': '******'
        }, format='json')

        self.assertEqual(res.status_code, 200)
Beispiel #18
0
    def test_organization_update_status(self):
        """Test organization's update status for regular user.

        API for now is read-only.
        """
        self.client.force_login(UserFactory())

        response = self.client.put(
            '/api/organizations/{}/'.format(OrganizationFactory().id),
            self.organization_payload,
            content_type='application/json',
        )
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Beispiel #19
0
    def test_offer_update_status(self):
        """Test offer's update status for regular user.

        Regular user without connected organization is not allowed to edit
        offer.
        """
        self.client.force_login(UserFactory())

        response = self.client.put('/api/offers/{}/'.format(
            OfferFactory(offer_status='published').id),
                                   self.offer_payload,
                                   content_type='application/json')

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Beispiel #20
0
    def test_offer_update_status(self):
        """Test offer's update status for user with organization.

        Regular user with connected organization is allowed to edit its offer.
        """
        self.client.force_login(
            UserFactory(userprofile__organizations=[self.organization]))

        response = self.client.put('/api/offers/{}/'.format(
            OfferFactory(organization=self.organization).id),
                                   self.offer_payload,
                                   content_type='application/json')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
Beispiel #21
0
    def test_user_joined_one_offer(self):
        """Tests if user joined one offer."""

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

        offer = OfferFactory()
        offer.volunteers.add(user)

        res = self.client.get(ENDPOINT_URL)

        self.assertEqual(res.status_code, 200)
        self.assertEqual(len(res.data), 1)
        self.assertEqual(offer.id, res.data[0]['id'])
        self.assertEqual(offer.title, res.data[0]['title'])
Beispiel #22
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 #23
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 #24
0
 def setUp(self):
     """setting up each test."""
     UserFactory.create(first_name="nie-Jan", last_name="nie-Kowalski")
     self.totally_fake_user = UserFactory.create()
Beispiel #25
0
 def setUp(self):
     self.offer = OfferFactory(volunteers=UserFactory.create_batch(10))
Beispiel #26
0
 def setUp(self):
     """ Set up for each test """
     self.user = UserFactory.create()
     self.uid = str(urlsafe_base64_encode(force_bytes(self.user.pk)),
                    'utf-8')
     self.token = default_token_generator.make_token(self.user)
Beispiel #27
0
 def setUpClass(cls):
     super().setUpClass()
     cls.admin = UserFactory.create(userprofile__is_administrator=True)
Beispiel #28
0
 def setUp(self):
     """Set up each test."""
     super().setUp()
     self.client.force_login(UserFactory())
Beispiel #29
0
 def setUp(self):
     """Set up each test."""
     super().setUp()
     self.client.force_login(
         UserFactory(userprofile__is_administrator=True))
Beispiel #30
0
 def setUpClass(cls):
     cls.user = UserFactory.create()