def test_no_site(self): """ Ensure no sites are handled properly. """ request = Mock(get_host=Mock(return_value='my_site.org')) with pytest.raises(Site.DoesNotExist): get_current_organization(request)
def test_no_site(self): """ Ensure no sites are handled properly. """ request = Mock(site=None) with pytest.raises(Organization.DoesNotExist): get_current_organization(request)
def test_no_organization(self): """ Ensure no orgs are handled properly. """ site = SiteFactory(domain='my_site.org') request = Mock(get_host=Mock(return_value=site.domain)) with pytest.raises(Organization.DoesNotExist): get_current_organization(request)
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 get_queryset(self): organization = get_current_organization(self.context['request']) return get_user_model().objects.filter( id__in=UserOrganizationMapping.objects.filter( organization=organization, is_active=True, ).values('user_id'), )
def get_queryset(self): organization = get_current_organization(self.request) course_links = OrganizationCourse.objects.filter(organization=organization, active=True) return self.model.objects.filter( course_id__in=course_links.values('course_id'), )
def get_queryset(self): organization = get_current_organization(self.request) return CourseOverview.objects.filter( id__in=OrganizationCourse.objects.filter( organization=organization, active=True, ).values('course_id'), )
def get_queryset(self): organization = get_current_organization(self.request) return self.model.objects.filter( pk__in=UserOrganizationMapping.objects.filter( organization=organization, is_active=True, # TODO: Add test for `is_active` is_amc_admin=False, # Site admins shouldn't be included in the API. ).values('user_id'), )
def test_single_organization(self): """ Ensure multiple orgs to be forbidden. """ my_site = SiteFactory(domain='my_site.org') other_site = SiteFactory(domain='other_site.org') # ensure no collision. my_org = OrganizationFactory.create(sites=[my_site]) OrganizationFactory.create(sites=[other_site]) # ensure no collision. request = Mock(get_host=Mock(return_value=my_site.domain)) assert my_org == get_current_organization(request)
def get_queryset(self): organization = get_current_organization(self.context['request']) return CourseAccessGroup.objects.filter(organization=organization, )
def get_queryset(self): organization = get_current_organization(self.context['request']) organization_courses = OrganizationCourse.objects.filter( organization=organization, active=True) return CourseOverview.objects.filter( id__in=organization_courses.values('course_id'), )
def get_queryset(self): organization = get_current_organization(self.request) return self.model.objects.filter( group__in=CourseAccessGroup.objects.filter(organization=organization), )
def get_queryset(self): organization = get_current_organization(self.request) return self.model.objects.filter(organization=organization)
def perform_create(self, serializer): organization = get_current_organization(self.request) serializer.save(organization=organization)