コード例 #1
0
    def handle(self, *args, **options):
        """Populate database with fake objects."""

        self.stdout.write(self.style.SUCCESS('Creating 15 organizations'))
        for _ in tqdm(range(15)):
            organization = OrganizationFactory.create()
            UserProfileFactory.create(organizations=(organization, ), )

        self.stdout.write(self.style.SUCCESS('Creating 50 offers'))
        for _ in tqdm(range(50)):
            OfferFactory.create(
                organization=random.choice(Organization.objects.all()),
                image__path=ImageField(
                    from_func=placeimg_com_download(1000, 400, 'any')))

        self.stdout.write(self.style.SUCCESS('Creating 150 volunteers'))
        for _ in tqdm(range(150)):
            userprofile = UserProfileFactory.create()
            no_of_offers = random.randrange(10)
            for offer in random.sample(list(Offer.objects.all()),
                                       no_of_offers):
                offer.volunteers.add(userprofile.user)

        self.stdout.write(
            self.style.SUCCESS('Database successfully populated'))
コード例 #2
0
ファイル: common.py プロジェクト: v3rth/volontulo
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
コード例 #3
0
    def setUpTestData(cls):
        """Set up data for all tests."""
        cls.organization = OrganizationFactory()

        cls.inactive_offer = OfferFactory(
            organization=cls.organization,
            offer_status='unpublished',
        )
        cls.active_offer = OfferFactory(
            organization=cls.organization,
            offer_status='published',
            finished_at=None,
            recruitment_end_date=None,
        )

        cls.volunteer = UserProfileFactory.create(
            user__username='******',
            user__email='*****@*****.**',
            user__password='******',
        )
        cls.organization_profile = UserProfileFactory.create(
            user__username='******',
            user__email='*****@*****.**',
            user__password='******',
            organizations=(cls.organization, ),
        )
        cls.admin = UserProfileFactory.create(
            user__username='******',
            user__email='*****@*****.**',
            user__password='******',
            is_administrator=True,
        )
コード例 #4
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)
コード例 #5
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)
コード例 #6
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)
コード例 #7
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)
コード例 #8
0
ファイル: test_join.py プロジェクト: w1stler/volontulo
 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)
コード例 #9
0
ファイル: test_read.py プロジェクト: w1stler/volontulo
 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)
コード例 #10
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())
コード例 #11
0
ファイル: test_delete.py プロジェクト: w1stler/volontulo
    def test_offer_delete_status(self):
        """Test offer's delete status for regular user.

        API for now is read-only.
        """
        response = self.client.delete('/api/offers/{}/'.format(
            OfferFactory().id))
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
コード例 #12
0
ファイル: test_delete.py プロジェクト: w1stler/volontulo
    def test_offer_delete_status(self):
        """Test offer's delete status for user with organization.

        API for now is read-only.
        """
        offer = OfferFactory(organization=self.organization)
        response = self.client.delete('/api/offers/{}/'.format(offer.id))
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
コード例 #13
0
 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]
     )
コード例 #14
0
ファイル: test_offer.py プロジェクト: w1stler/volontulo
 def test_image(self):
     """Test image field."""
     offer = OfferFactory()
     request = RequestFactory().get('/')
     request.user = AnonymousUser()
     self.assertEqual(urlparse(OfferSerializer(
         offer,
         context={'request': request},
     ).data['image']).path, offer.image.url)
コード例 #15
0
ファイル: test_read.py プロジェクト: w1stler/volontulo
    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)
コード例 #16
0
 def setUp(self):
     self.offer = OfferFactory(
         organization__name="Halperin Organix",
         description="Dokładny opis oferty",
         requirements="Dokładny opis wymagań",
         time_commitment="333 dni w roku",
         benefits="Wszelkie korzyści z uczestnictwa w wolontariacie",
         location="Polska, Poznań",
         title="Zwięzły tytuł oferty",
         time_period="Od 23.09.2015 do 25.12.2016",
     )
コード例 #17
0
ファイル: test_update.py プロジェクト: w1stler/volontulo
    def test_offer_update_status(self):
        """Test offer's update status for admin user.

        Admin user without connected organization is allowed to edit any offer.
        """
        response = self.client.put(
            '/api/offers/{}/'.format(OfferFactory().id),
            self.offer_payload,
            content_type='application/json',
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
コード例 #18
0
 def test_image(self):
     """Test image field."""
     offer = OfferFactory()
     self.assertEqual(
         urlparse(
             OfferSerializer(
                 offer,
                 context={
                     'request': RequestFactory().get('/')
                 },
             ).data['image']).path,
         offer.images.get(is_main=True).path.url)
コード例 #19
0
ファイル: test_update.py プロジェクト: w1stler/volontulo
    def test_offer_update_status(self):
        """Test offer's update status for anonymous user.

        Anonymous user is not allowed to edit offer.
        """
        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)
コード例 #20
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)
コード例 #21
0
    def handle(self, *args, **options):
        """Populate database with fake objects."""

        # create 5 organizations:
        for _ in range(5):
            organization = OrganizationFactory.create()
            UserProfileFactory.create(organizations=(organization, ), )

        # create 50 offers:
        for _ in range(50):
            OfferFactory.create(
                organization=random.choice(Organization.objects.all()))

        # create 150 volunteers:
        for _ in range(150):
            userprofile = UserProfileFactory.create()
            no_of_offers = random.randrange(10)
            for offer in random.sample(list(Offer.objects.all()),
                                       no_of_offers):
                offer.volunteers.add(userprofile.user)

        self.stdout.write(
            self.style.SUCCESS('Database successfully populated'))
コード例 #22
0
ファイル: test_update.py プロジェクト: w1stler/volontulo
    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)
コード例 #23
0
ファイル: test_update.py プロジェクト: w1stler/volontulo
    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)
コード例 #24
0
    def handle(self, *args, **options):
        """Populate database with fake objects."""

        # create 5 organizations
        for organization in range(0, 5):
            OrganizationFactory.create()

        # create admin-user
        UserProfileFactory.create(is_administrator=True)

        # create 15 volunteers
        for volunteer in range(0, 14):
            UserProfileFactory.create(
                organizations=self.create_list_of_objects('Organization', 3),
                is_administrator=False)

        # create 50 offers
        for offer in range(0, 50):
            OfferFactory.create(
                organization=self.create_list_of_objects('Organization', 1)[0],
                volunteers=self.create_list_of_objects('User', 3))

        self.stdout.write(
            self.style.SUCCESS('Database successfully populated'))
コード例 #25
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'])
コード例 #26
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)
コード例 #27
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)
コード例 #28
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)
コード例 #29
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)
コード例 #30
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)