-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tests for api views and serializers
- Loading branch information
Showing
20 changed files
with
992 additions
and
83 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from rest_framework_json_api.views import ModelViewSet | ||
from rest_framework_json_api.views import ReadOnlyModelViewSet | ||
|
||
from .models import InternalResource | ||
from .serializers import InternalResourceSerializer | ||
|
||
|
||
class InternalResourceViewSet(ModelViewSet): # TODO: read-only | ||
class InternalResourceViewSet(ReadOnlyModelViewSet): | ||
queryset = InternalResource.objects.all() | ||
serializer_class = InternalResourceSerializer | ||
# TODO: permissions_classes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from rest_framework_json_api.views import ModelViewSet | ||
from rest_framework_json_api.views import ReadOnlyModelViewSet | ||
|
||
from .models import InternalUser | ||
from .serializers import InternalUserSerializer | ||
|
||
|
||
class InternalUserViewSet(ModelViewSet): # TODO: read-only | ||
class InternalUserViewSet(ReadOnlyModelViewSet): | ||
queryset = InternalUser.objects.all() | ||
serializer_class = InternalUserSerializer | ||
# TODO: permissions_classes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import factory | ||
from factory.django import DjangoModelFactory | ||
|
||
from addon_service import models as db | ||
|
||
|
||
class InternalUserFactory(DjangoModelFactory): | ||
class Meta: | ||
model = db.InternalUser | ||
|
||
user_uri = factory.Sequence(lambda n: f"http://osf.example/user{n}") | ||
|
||
|
||
class InternalResourceFactory(DjangoModelFactory): | ||
class Meta: | ||
model = db.InternalResource | ||
|
||
resource_uri = factory.Sequence(lambda n: f"http://osf.example/thing{n}") | ||
|
||
|
||
class CredentialsIssuerFactory(DjangoModelFactory): | ||
class Meta: | ||
model = db.CredentialsIssuer | ||
|
||
|
||
class ExternalCredentialsFactory(DjangoModelFactory): | ||
class Meta: | ||
model = db.ExternalCredentials | ||
|
||
|
||
class ExternalAccountFactory(DjangoModelFactory): | ||
class Meta: | ||
model = db.ExternalAccount | ||
|
||
remote_account_id = factory.Faker("word") | ||
remote_account_display_name = factory.Faker("word") | ||
|
||
credentials_issuer = factory.SubFactory(CredentialsIssuerFactory) | ||
owner = factory.SubFactory(InternalUserFactory) | ||
credentials = factory.SubFactory(ExternalCredentialsFactory) | ||
|
||
|
||
### | ||
# "Storage" models | ||
|
||
|
||
class ExternalStorageServiceFactory(DjangoModelFactory): | ||
class Meta: | ||
model = db.ExternalStorageService | ||
|
||
max_concurrent_downloads = factory.Faker("pyint") | ||
max_upload_mb = factory.Faker("pyint") | ||
auth_uri = factory.Sequence(lambda n: f"http://auth.example/{n}") | ||
credentials_issuer = factory.SubFactory(CredentialsIssuerFactory) | ||
|
||
|
||
class AuthorizedStorageAccountFactory(DjangoModelFactory): | ||
class Meta: | ||
model = db.AuthorizedStorageAccount | ||
|
||
default_root_folder = "/" | ||
external_storage_service = factory.SubFactory(ExternalStorageServiceFactory) | ||
external_account = factory.SubFactory(ExternalAccountFactory) | ||
# TODO: external_account.credentials_issuer same as | ||
# external_storage_service.credentials_issuer | ||
|
||
|
||
class ConfiguredStorageAddonFactory(DjangoModelFactory): | ||
class Meta: | ||
model = db.ConfiguredStorageAddon | ||
|
||
root_folder = "/" | ||
authorized_storage_account = factory.SubFactory(AuthorizedStorageAccountFactory) | ||
internal_resource = factory.SubFactory(InternalResourceFactory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from rest_framework.test import ( | ||
APIRequestFactory, | ||
force_authenticate, | ||
) | ||
|
||
|
||
def get_test_request(user=None, method="get", path=""): | ||
_factory_method = getattr(APIRequestFactory(), method) | ||
_request = _factory_method(path) # note that path is optional for view tests | ||
if user is not None: | ||
force_authenticate(_request, user=user) | ||
return _request |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.