-
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.
Merge pull request #5 from CenterForOpenScience/feature/tests
[ENG-5111] chore: add tests for api views and serializers
- Loading branch information
Showing
25 changed files
with
1,017 additions
and
117 deletions.
There are no files selected for viewing
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
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 = "/" | ||
base_account = factory.SubFactory(AuthorizedStorageAccountFactory) | ||
authorized_resource = factory.SubFactory(InternalResourceFactory) |
Oops, something went wrong.