diff --git a/Makefile b/Makefile index 3aaa0ae..8566283 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,11 @@ PYTHON=env/bin/python DROPZONE=5.7.0 +test: + coverage run --include "app/*" --omit "*/migrations/*" app/manage.py test app + coverage html + coverage report + dev-setup: env/bin/pip install -r requirements.txt env/bin/pip install -r dev-requirements.txt diff --git a/app/library/tests.py b/app/library/tests.py index 210c15c..3009f39 100644 --- a/app/library/tests.py +++ b/app/library/tests.py @@ -44,6 +44,10 @@ class LibraryTestCase(AccessTestCase): '/collections/2/works/1/upload', '/collections/2/docs/1/annotate', + # Need to add storage before we can test these + #'/api/collections/2', + #'/api/collections/2/works/1', + '/admin/library/collection/', '/admin/library/document/', '/admin/library/ensembleaccess/', @@ -81,28 +85,9 @@ class LibraryTestCase(AccessTestCase): - def oldSetUp(self): - self.homer = User.objects.create(username='homer') - self.ned = User.objects.create(username="ned") - self.lisa = User.objects.create(username="lisa") - self.dewey = User.objects.create(username="dewey") - - self.be_sharps = self.homer.ensembles.create(name='Be Sharps', code="barbershop") - self.sesd = self.dewey.ensembles.create(name="Springfield Elementary School Band", code="sax") - - self.sel = self.lisa.collections.create(name="Springfield Elementary Library") - self.flanders = self.ned.collections.create(name="Neds Shed") - def test_integration(self): pass -# def test_get_views(self): -# -# self.assertAccess({ x: False for x in self.PROTECTED_URLS }) -# -# self.login('admin', 'secret') -# self.assertAccess({ x: True for x in self.PROTECTED_URLS }) - def test_superuser_access(self): self.login('admin', 'secret') self.assertAccess({ diff --git a/app/library/urls.py b/app/library/urls.py index aec1277..431b577 100644 --- a/app/library/urls.py +++ b/app/library/urls.py @@ -35,7 +35,7 @@ urlpatterns = [ path('collections//download//', views.PartDownloadView.as_view(), name="part_download"), #path('api/', include(router.urls)) - path('api/collections/', api.CollectionExportView.as_view(), name="collection_export"), + path('api/collections/', api.CollectionExportView.as_view(), name="collection_export"), path('api/collections//works/', api.WorkExportView.as_view(), name="work_export"), path('api/collections//import', api.WorkImportView.as_view(), name="work_import"), path('api/collections//bulk_import', api.CollectionImportView.as_view(), name="collection_import"), diff --git a/app/library/views/api.py b/app/library/views/api.py index 521bb4a..1358d5a 100644 --- a/app/library/views/api.py +++ b/app/library/views/api.py @@ -167,16 +167,20 @@ from rest_framework import generics class CollectionExportView(AuthorizedResourceMixin, generics.RetrieveAPIView): serializer_class = CollectionSerializer - lookup_url_kwarg = 'collection' def get_queryset(self): + if self.request.user.is_superuser: + return Collection.objects.all() return Collection.objects.filter(administrators=self.request.user) class WorkExportView(AuthorizedResourceMixin, generics.RetrieveAPIView): serializer_class = WorkSerializer def get_queryset(self): - return Work.objects.filter(collection__administrators=self.request.user, collection=self.kwargs['collection']) + works = Work.objects.filter(collection=self.kwargs['collection']) + if self.request.user.is_superuser: + return works + return works.filter(collection__administrators=self.request.user) class WorkImportView(AuthorizedResourceMixin, generics.CreateAPIView): serializer_class = WorkSerializer