Esempio n. 1
0
 def setUp(self):
     """Set up each test"""
     OrganizationFactory.create(
         name="Flota zjednoczonych sił",
         address="Psia Wólka"
     )
     self.fake_organization = OrganizationFactory.create()
Esempio n. 2
0
 def setUp(self):
     OrganizationFactory.create(name="Nazwa organizacji1", )
     OrganizationFactory.create()
     # User is created as a Subfactory of UserProfile
     self.fake_user_profile = UserProfileFactory.create(
         user__first_name="Edmund",
         organizations=Organization.objects.all(),
         phone_no="22909")
Esempio n. 3
0
    def test_organization_list_length(self):
        """Test organizations list length for anonymous user.

        Organizations are readable for everyone.
        """
        OrganizationFactory.create_batch(93)

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

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 93)
Esempio n. 4
0
    def test_organization_list_length(self):
        """Test organizations list length for user with organization.

        Organizations are readable for everyone.
        """
        OrganizationFactory.create_batch(75)

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

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # it's 76 here, as one organization is created when user is created:
        self.assertEqual(len(response.data), 76)
Esempio n. 5
0
    def test_organization_list_fields(self):
        """Test list's fields of organization REST API endpoint."""
        OrganizationFactory.create_batch(56)

        response = self.client.get('/api/organizations/')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        for organization in response.data:
            self.assertIsInstance(organization.pop('address'), str)
            self.assertIsInstance(organization.pop('description'), str)
            self.assertIsInstance(organization.pop('id'), int)
            self.assertIsInstance(organization.pop('name'), str)
            self.assertIsInstance(organization.pop('slug'), str)
            self.assertIsInstance(organization.pop('url'), str)
            self.assertEqual(len(organization), 0)
Esempio n. 6
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'))
Esempio n. 7
0
 def setUp(self):
     """Set up each test."""
     super().setUp()
     self.organization = OrganizationFactory()
     self.client.force_login(UserFactory(
         userprofile__organizations=[self.organization]
     ))
Esempio n. 8
0
def initialize_empty_organization():
    """Initialize empty organization."""
    organization1 = OrganizationFactory()
    UserFactory(email='*****@*****.**',
                password='******',
                userprofile__organizations=[organization1])
    return organization1
Esempio n. 9
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,
        )
Esempio n. 10
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
Esempio n. 11
0
    def test_organization_delete_status(self):
        """Test organization's delete status for anonymous user.

        API for now is read-only.
        """
        response = self.client.delete('/api/organizations/{}/'.format(
            OrganizationFactory()))

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Esempio n. 12
0
 def setUpTestData(cls):
     """Set up data for all tests."""
     cls.organization = OrganizationFactory()
     cls.offer_payload = b"""{
         "benefits": "offer benefits",
         "description": "offer description",
         "location": "offer location",
         "organization": {"id": %d},
         "timeCommitment": "offer time commitment",
         "title": "offer title"
     }""" % cls.organization.id
Esempio n. 13
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)
Esempio n. 14
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)
Esempio n. 15
0
 def setUpClass(cls):
     """Set up each test."""
     super().setUpClass()
     cls.organization = OrganizationFactory()
     cls.offer_payload = b"""{
         "benefits": "offer benefits",
         "description": "offer description",
         "location": "offer location",
         "organization": {"id": %d},
         "timeCommitment": "offer time commitment",
         "title": "offer title"
     }""" % cls.organization.id
Esempio n. 16
0
    def test_organization_update_status(self):
        """Test organization's update status for admin user.

        API for now is read-only.
        """
        response = self.client.put(
            '/api/organizations/{}/'.format(OrganizationFactory().id),
            self.organization_payload,
            content_type='application/json',
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
Esempio n. 17
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)
    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'))
Esempio n. 19
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)
Esempio n. 20
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'))
Esempio n. 21
0
 def setUp(self):
     """ Set up for each test """
     self.org = OrganizationFactory.create()