Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refact repository #265

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
015bed8
Merge pull request #251 from Ilhasoft/develop
johncordeiro May 29, 2019
7754364
Migration Categories v1 to v2 and Update URLS
dyohan9 Jul 23, 2019
f736479
Added Deprecated Category v1
dyohan9 Jul 23, 2019
e9af872
Migration Repository v1 to v2
dyohan9 Jul 23, 2019
71474af
Migration Translations v1 to v2 and refact
dyohan9 Jul 23, 2019
959ebee
Added tests Repository v2
dyohan9 Jul 23, 2019
3f1eadb
Update URLS Tests
dyohan9 Jul 23, 2019
5c7b67d
PEP8
dyohan9 Jul 23, 2019
05dc971
Migration Repository Example v1 to v2 and refact
dyohan9 Jul 23, 2019
f726ea5
Migration Search Repositories v1 to v2
dyohan9 Jul 23, 2019
a51f6df
Migration Search Repositories v1 to v2
dyohan9 Jul 23, 2019
00c43a7
Migration Repository Translate Example v1 to v2 and refact
dyohan9 Jul 23, 2019
7925ef6
Migration Repository Translations v1 to v2 and refact
dyohan9 Jul 23, 2019
7d09735
Migration Repository Updates v1 to v2 and refact
dyohan9 Jul 23, 2019
c593bf8
Added Tests Repository
dyohan9 Jul 23, 2019
09ef94c
Migration Repository v1 to v2 and refact
dyohan9 Jul 23, 2019
dd1447f
[fix] Repository Router
dyohan9 Jul 23, 2019
e4c40a2
PEP8
dyohan9 Jul 23, 2019
3a7dbe0
Migration Repository Example New v1 to v2 and refact
dyohan9 Jul 23, 2019
27375b4
Migration Request Authorization v1 to v2 and refact
dyohan9 Jul 23, 2019
0675689
Added tests Request Authorization and Repository Example
dyohan9 Jul 23, 2019
56a8fff
Migration Review Auth Request v1 to v2 and refact
dyohan9 Jul 23, 2019
15fd28f
Migration Authorizations v1 to v2 and refact
dyohan9 Jul 23, 2019
d45dda2
Migration Auth Role v1 to v2 and refact
dyohan9 Jul 23, 2019
561e16c
Migration Repository Auth Requests v1 to v2 and refact
dyohan9 Jul 23, 2019
9679d56
PEP8
dyohan9 Jul 23, 2019
3a2ce37
Merge branch 'master' into feature/refact_repository
dyohan9 Jul 24, 2019
8abeabe
Added test without nickname ListRepositoryContributionsTestCase
dyohan9 Jul 24, 2019
c359c78
Added test without nickname Contributions
dyohan9 Jul 24, 2019
5ec230f
Added test Repository Votes empty
dyohan9 Jul 24, 2019
44093dd
Pragma no cover
dyohan9 Jul 24, 2019
68f1f2d
[fix] pyparsing version 2.4.0
dyohan9 Jul 24, 2019
46beb28
Coveralls
dyohan9 Jul 24, 2019
f7e2c84
Refact Repository Example
dyohan9 Jul 29, 2019
1a76f0c
[fix] Repository Example
dyohan9 Jul 29, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ coreapi = "==2.3.3"
whitenoise = "==4.1.2"
pytz = "==2018.7"
drf-yasg = "*"
pyparsing = "==2.4.0"

[dev-packages]
"flake8" = "*"
Expand Down
17 changes: 13 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

158 changes: 155 additions & 3 deletions bothub/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ def get_object(self):

# ViewSets

@method_decorator(
name='create',
decorator=swagger_auto_schema(
deprecated=True
),
)
class NewRepositoryViewSet(
mixins.CreateModelMixin,
GenericViewSet):
Expand Down Expand Up @@ -415,7 +421,8 @@ def create(self, request, *args, **kwargs):
description='Nickname User to find repositories',
type=openapi.TYPE_STRING
),
]
],
deprecated=True
)
)
class SearchRepositoriesViewSet(
Expand Down Expand Up @@ -443,6 +450,30 @@ def get_queryset(self, *args, **kwargs):
return self.queryset.none()


@method_decorator(
name='retrieve',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='partial_update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='destroy',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RepositoryViewSet(
MultipleFieldLookupMixin,
mixins.RetrieveModelMixin,
Expand Down Expand Up @@ -473,6 +504,12 @@ class RepositoryViewSet(
RepositoryPermission,
]

@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@action(
detail=True,
methods=['GET'],
Expand Down Expand Up @@ -533,6 +570,12 @@ def train(self, request, **kwargs):
code=request.status_code)
return Response(request.json()) # pragma: no cover

@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@action(
detail=True,
methods=['POST'],
Expand Down Expand Up @@ -635,6 +678,12 @@ def get_permissions(self):
return super().get_permissions()


@method_decorator(
name='create',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class NewRepositoryExampleViewSet(
mixins.CreateModelMixin,
GenericViewSet):
Expand All @@ -652,6 +701,24 @@ class NewRepositoryExampleViewSet(
deprecated=True,
)
)
@method_decorator(
name='update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='partial_update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='destroy',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RepositoryExampleViewSet(
mixins.RetrieveModelMixin,
mixins.DestroyModelMixin,
Expand Down Expand Up @@ -682,6 +749,12 @@ def perform_destroy(self, obj):
obj.delete()


@method_decorator(
name='create',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class NewRepositoryTranslatedExampleViewSet(
mixins.CreateModelMixin,
GenericViewSet):
Expand All @@ -693,6 +766,30 @@ class NewRepositoryTranslatedExampleViewSet(
permission_classes = [permissions.IsAuthenticated]


@method_decorator(
name='retrieve',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='partial_update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='destroy',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RepositoryTranslatedExampleViewSet(
mixins.RetrieveModelMixin,
mixins.UpdateModelMixin,
Expand Down Expand Up @@ -952,6 +1049,12 @@ class UserProfileViewSet(
lookup_field = 'nickname'


@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True
),
)
class Categories(
mixins.ListModelMixin,
GenericViewSet):
Expand Down Expand Up @@ -989,6 +1092,12 @@ class RepositoriesViewSet(
]


@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class TranslationsViewSet(
mixins.ListModelMixin,
GenericViewSet):
Expand All @@ -1000,6 +1109,12 @@ class TranslationsViewSet(
filter_class = TranslationsFilter


@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RepositoryAuthorizationViewSet(
mixins.ListModelMixin,
GenericViewSet):
Expand Down Expand Up @@ -1030,7 +1145,7 @@ class RepositoryAuthorizationViewSet(
type=openapi.TYPE_STRING,
required=True
),
]
], deprecated=True
)
)
@method_decorator(
Expand All @@ -1051,7 +1166,8 @@ class RepositoryAuthorizationViewSet(
type=openapi.TYPE_STRING,
required=True
),
]
],
deprecated=True
)
)
class RepositoryAuthorizationRoleViewSet(
Expand Down Expand Up @@ -1121,6 +1237,12 @@ def list(self, request, *args, **kwargs):
return Response(serializer.data)


@method_decorator(
name='create',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RequestAuthorizationViewSet(
mixins.CreateModelMixin,
GenericViewSet):
Expand All @@ -1134,6 +1256,12 @@ class RequestAuthorizationViewSet(
]


@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RepositoryAuthorizationRequestsViewSet(
mixins.ListModelMixin,
GenericViewSet):
Expand All @@ -1149,6 +1277,24 @@ class RepositoryAuthorizationRequestsViewSet(
]


@method_decorator(
name='update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='partial_update',
decorator=swagger_auto_schema(
deprecated=True,
)
)
@method_decorator(
name='destroy',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class ReviewAuthorizationRequestViewSet(
mixins.UpdateModelMixin,
mixins.DestroyModelMixin,
Expand Down Expand Up @@ -1189,6 +1335,12 @@ class RepositoryEntitiesViewSet(
]


@method_decorator(
name='list',
decorator=swagger_auto_schema(
deprecated=True,
)
)
class RepositoryUpdatesViewSet(
mixins.ListModelMixin,
GenericViewSet):
Expand Down
8 changes: 4 additions & 4 deletions bothub/api/v2/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Metadata(BaseMetadata):
EntityText: 'entity text',
})

def determine_metadata(self, request, view):
def determine_metadata(self, request, view): # pragma: no cover
metadata = OrderedDict()
metadata['name'] = view.get_view_name()
metadata['description'] = view.get_view_description()
Expand All @@ -60,23 +60,23 @@ def determine_metadata(self, request, view):
metadata['actions'] = actions
return metadata

def determine_actions(self, request, view):
def determine_actions(self, request, view): # pragma: no cover
actions = {}
for method in {'PUT', 'POST'} & set(view.allowed_methods):
serializer = view.get_serializer()
actions[method] = self.get_serializer_info(serializer)
view.request = request
return actions

def get_serializer_info(self, serializer):
def get_serializer_info(self, serializer): # pragma: no cover
if hasattr(serializer, 'child'):
serializer = serializer.child
return OrderedDict([
(field_name, self.get_field_info(field))
for field_name, field in serializer.fields.items()
])

def get_field_info(self, field):
def get_field_info(self, field): # pragma: no cover
field_info = OrderedDict()
field_info['type'] = self.label_lookup[field] or 'field'
field_info['required'] = getattr(field, 'required', False)
Expand Down
20 changes: 20 additions & 0 deletions bothub/api/v2/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.shortcuts import get_object_or_404


class MultipleFieldLookupMixin(object):
"""
Apply this mixin to any view or viewset to get multiple field filtering
based on a `lookup_fields` attribute, instead of the default single field
filtering.
"""

def get_object(self): # pragma: no cover
queryset = self.get_queryset()
queryset = self.filter_queryset(queryset)
filter = {}
for field in self.lookup_fields:
if self.kwargs.get(field):
filter[field] = self.kwargs[field]
obj = get_object_or_404(queryset, **filter)
self.check_object_permissions(self.request, obj)
return obj
Loading