def setUp(self): """Set up each test""" OrganizationFactory.create( name="Flota zjednoczonych sił", address="Psia Wólka" ) self.fake_organization = OrganizationFactory.create()
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")
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)
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)
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)
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'))
def setUp(self): """Set up each test.""" super().setUp() self.organization = OrganizationFactory() self.client.force_login(UserFactory( userprofile__organizations=[self.organization] ))
def initialize_empty_organization(): """Initialize empty organization.""" organization1 = OrganizationFactory() UserFactory(email='*****@*****.**', password='******', userprofile__organizations=[organization1]) return organization1
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, )
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
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)
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
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)
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)
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
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)
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'))
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)
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'))
def setUp(self): """ Set up for each test """ self.org = OrganizationFactory.create()