def test_single_organization(self): """ Ensure multiple orgs to be forbidden. """ my_site = SiteFactory.create(domain='my_site.org') other_site = SiteFactory.create( domain='other_site.org') # ensure no collision. my_org = OrganizationFactory.create(sites=[my_site]) OrganizationFactory.create(sites=[other_site]) # ensure no collision. request = Mock(site=my_site) assert my_org == get_current_organization(request)
def test_on_main_site_without_uuid_parameter(self, settings): """ Non superusers shouldn't use the CAG on main site ( e.g. tahoe.appsembler.com/admin ). """ main_site = SiteFactory.create(domain='main_site') settings.SITE_ID = main_site.id customer_site = SiteFactory.create(domain='customer_site') OrganizationFactory.create(sites=[customer_site ]) # Creates customer_org superuser = UserFactory.create(is_superuser=True) request = Mock(site=main_site, user=superuser, GET={}) with pytest.raises(Organization.DoesNotExist, match=r'Tahoe.*Should not find.*SITE_ID'): get_requested_organization(request)
def test_on_main_site_with_uuid_parameter(self, settings): """ Superusers can use the `get_requested_organization` helper with `organization_uuid`. """ main_site = SiteFactory.create(domain='main_site') settings.SITE_ID = main_site.id customer_site = SiteFactory.create(domain='customer_site') customer_org = OrganizationFactory.create(sites=[customer_site]) superuser = UserFactory.create(is_superuser=True) request = Mock(site=main_site, user=superuser, GET={ 'organization_uuid': customer_org.edx_uuid, }) requested_org = get_requested_organization(request) assert requested_org == customer_org, 'Should return the site organization'
def test_two_organizations(self): """ Ensure multiple orgs to be forbidden. """ site = SiteFactory.create(domain='my_site.org') OrganizationFactory.create_batch(2, sites=[site]) request = Mock(site=site) with pytest.raises(Organization.MultipleObjectsReturned): get_current_organization(request)
def test_organization_main_site(self, settings): """ Ensure no orgs are handled properly. """ site = SiteFactory.create(domain='my_site.org') settings.SITE_ID = site.id request = Mock(site=site) with pytest.raises(Organization.DoesNotExist, match=r'Tahoe.*Should not find.*SITE_ID'): get_current_organization(request)
def test_no_organization(self): """ Ensure no orgs are handled properly. """ site = SiteFactory.create(domain='my_site.org') request = Mock(site=site) with pytest.raises( Organization.DoesNotExist, match=r'Organization matching query does not exist'): get_current_organization(request)
def test_on_customer_site(self): """ Customer sites can use CAG APIs. """ site = SiteFactory.create(domain='my_site.org') expected_org = OrganizationFactory.create(sites=[site]) non_superuser = UserFactory.create() request = Mock(site=site, user=non_superuser, GET={}) requested_org = get_requested_organization(request) assert requested_org == expected_org, 'Should return the site organization'
def setup(self, client): client.defaults['SERVER_NAME'] = self.domain self.user = UserFactory.create(username='******') self.site = SiteFactory.create(domain=self.domain) self.my_org = OrganizationFactory.create(name='my_org', sites=[self.site]) self.other_org = OrganizationFactory.create(name='other_org') self.staff = UserOrganizationMapping.objects.create( user=self.user, organization=self.my_org, is_amc_admin=True, ) client.force_login(self.user)
def test_on_main_site_with_uuid_parameter_non_staff(self, settings): """ Non superusers shouldn't be able to use the `organization_uuid` parameters. """ main_site = SiteFactory.create(domain='main_site') settings.SITE_ID = main_site.id customer_site = SiteFactory.create(domain='customer_site') customer_org = OrganizationFactory.create(sites=[customer_site]) non_superuser = UserFactory.create() request = Mock(site=main_site, user=non_superuser, GET={ 'organization_uuid': customer_org.edx_uuid, }) with pytest.raises( PermissionDenied, match=r'Not permitted to use the `organization_uuid` parameter.' ): get_requested_organization(request)
def setup(self, db, monkeypatch, standard_test_users): self.site = SiteFactory.create() self.organization = OrganizationFactory(sites=[self.site]) self.callers = [ UserFactory.create(username='******'), UserFactory.create(username='******'), UserFactory.create(username='******'), ] self.user_organization_mappings = [ UserOrganizationMapping.objects.create( user=self.callers[0], organization=self.organization), UserOrganizationMapping.objects.create( user=self.callers[1], organization=self.organization, is_amc_admin=True) ] self.callers += standard_test_users self.request = APIRequestFactory().get('/') self.request.site = self.site monkeypatch.setattr(sites_shortcuts, 'get_current_site', self.get_test_site)