def get_queryset(self): username = self.kwargs.get('user') if not username and self.user_is_self: username = get(self.request.user, 'username') if username: return Organization.get_by_username(username) if self.request.user.is_anonymous: return Organization.get_public() if self.request.user.is_superuser or self.request.user.is_staff: return Organization.objects.filter(is_active=True) queryset = Organization.get_by_username(self.request.user.username) | Organization.get_public() return queryset.distinct()
def test_public_sources(self, source_set_mock): source_set_mock.exclude = Mock(return_value=Mock(filter=Mock(return_value=Mock(count=Mock(return_value=10))))) self.assertEqual(Organization().public_sources, 10) source_set_mock.exclude.assert_called_once_with(public_access=ACCESS_TYPE_NONE) source_set_mock.exclude().filter.assert_called_once_with(version=HEAD) source_set_mock.exclude().filter().count.assert_called_once()
def test_owner_type(self): org = Organization(id=123, mnemonic='org') user = UserProfile(id=123, username='******') self.assertIsNone(Mapping().owner_type) self.assertEqual(Mapping(parent=Source(organization=org)).owner_type, 'Organization') self.assertEqual(Mapping(parent=Source(user=user)).owner_type, 'User')
def test_owner(self): org = Organization(id=123) user = UserProfile(id=123) self.assertIsNone(Mapping().owner) self.assertEqual(Mapping(parent=Source(organization=org)).owner, org) self.assertEqual(Mapping(parent=Source(user=user)).owner, user)
def test_resource_uri(self): self.assertEqual( Pin(resource=Organization(uri='/orgs/foo/')).resource_uri, '/orgs/foo/') self.assertEqual( Pin(resource=Source(uri='/orgs/foo/sources/bar/')).resource_uri, '/orgs/foo/sources/bar/')
def get_queryset(self): username = self.kwargs.get('user') if not username and self.user_is_self: username = get(self.request.user, 'username') if username: self.queryset = Organization.get_by_username(username) elif self.request.user.is_anonymous: self.queryset = Organization.get_public() elif self.request.user.is_superuser or self.request.user.is_staff: self.queryset = Organization.objects.filter(is_active=True) else: self.queryset = Organization.get_by_username(self.request.user.username) | Organization.get_public() updated_since = parse_updated_since_param(self.request.query_params) if updated_since: self.queryset = self.queryset.filter(updated_at__gte=updated_since) return self.queryset.distinct()
def test_create_organization_negative__no_mnemonic(self): with self.assertRaises(ValidationError): org = Organization(name='My Organization') org.full_clean() org.save()
def test_members(self): org = Organization(id=123) self.assertEqual(org.members.count(), 0)
def test_is_versioned(self): self.assertFalse(Organization().is_versioned)
def test_org(self): self.assertEqual(Organization().org, '') self.assertEqual(Organization(mnemonic='blah').org, 'blah')
def test_resource_type(self): self.assertEqual(Organization().resource_type, ORG_OBJECT_TYPE)
def test_logo_url(self): self.assertIsNone(Organization(logo_path=None).logo_url) self.assertEqual( Organization(logo_path='path/foo.png').logo_url.replace('https://', 'http://'), 'http://oclapi2-dev.s3.amazonaws.com/path/foo.png' )