Added linting and got tests passing
This commit is contained in:
parent
ca62ed693a
commit
cfd6d45189
11
Makefile
11
Makefile
@ -1,10 +1,13 @@
|
|||||||
PYTHON=env/bin/python
|
PYTHON=env/bin/python
|
||||||
DROPZONE=5.7.0
|
DROPZONE=5.7.0
|
||||||
|
|
||||||
test:
|
test: check
|
||||||
coverage run --include "app/*" --omit "*/migrations/*" app/manage.py test app
|
poetry run coverage run --include "app/*" --omit "*/migrations/*" app/manage.py test app
|
||||||
coverage html
|
poetry run coverage html
|
||||||
coverage report
|
poetry run coverage report
|
||||||
|
|
||||||
|
check:
|
||||||
|
poetry run ruff check app
|
||||||
|
|
||||||
dev-setup:
|
dev-setup:
|
||||||
env/bin/pip install -r requirements.txt
|
env/bin/pip install -r requirements.txt
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from interface import models, utils
|
from interface import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
@ -16,7 +16,6 @@ class AccessTestCase(TestCase):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
|
|
||||||
cls.users = {}
|
cls.users = {}
|
||||||
for details in cls.USERS:
|
for details in cls.USERS:
|
||||||
cls.users[details["username"]] = User.objects.create_user(**details)
|
cls.users[details["username"]] = User.objects.create_user(**details)
|
||||||
@ -42,7 +41,6 @@ class AccessTestCase(TestCase):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def test_protected_views(self):
|
def test_protected_views(self):
|
||||||
|
|
||||||
self.assertAccess({x: False for x in self.PROTECTED_URLS})
|
self.assertAccess({x: False for x in self.PROTECTED_URLS})
|
||||||
|
|
||||||
if "admin" in self.users:
|
if "admin" in self.users:
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
from django.contrib.auth import views as auth_views
|
from django.contrib.auth import views as auth_views
|
||||||
from django.views.generic.base import RedirectView
|
from django.views.generic.base import RedirectView
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
@ -69,7 +70,6 @@ urlpatterns = [
|
|||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
from django.views.static import serve
|
from django.views.static import serve
|
||||||
|
|||||||
@ -1,20 +1,19 @@
|
|||||||
from django.shortcuts import resolve_url
|
from django.shortcuts import resolve_url
|
||||||
from django.core.signing import Signer
|
from django.core.signing import Signer
|
||||||
from django.core.exceptions import SuspiciousOperation
|
from django.core.exceptions import SuspiciousOperation
|
||||||
|
import logging
|
||||||
|
|
||||||
signer = Signer()
|
signer = Signer()
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def sign_data(data, l=None):
|
def sign_data(data, length=None):
|
||||||
sig = signer.sign(data)
|
sig = signer.sign(data)
|
||||||
p = len(data) + 1
|
pos = len(data) + 1
|
||||||
if l:
|
if length:
|
||||||
l += p
|
length += pos
|
||||||
return sig[p:l]
|
return sig[pos:length]
|
||||||
|
|
||||||
|
|
||||||
def signed_url(name, **kwargs):
|
def signed_url(name, **kwargs):
|
||||||
|
|||||||
@ -345,12 +345,11 @@ class Work(models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def identifier(self):
|
def identifier(self):
|
||||||
|
|
||||||
if self.code:
|
if self.code:
|
||||||
return self.code
|
return self.code
|
||||||
|
|
||||||
composer = self.composer or "Anon"
|
composer = self.composer or "Anon"
|
||||||
composer = re.sub("[^\w]", "", composer)
|
composer = re.sub(r"[^\w]", "", composer)
|
||||||
words = self.name.split()
|
words = self.name.split()
|
||||||
work = words[0][:3]
|
work = words[0][:3]
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
import re
|
||||||
|
|
||||||
GENERAL = """
|
GENERAL = """
|
||||||
mvmt Movement
|
mvmt Movement
|
||||||
@ -195,8 +196,8 @@ class MusicTag(namedtuple("MusicTag", ("name", "variant"), defaults=[None])):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def tag(self):
|
def tag(self):
|
||||||
l = self.name.lower()
|
lc = self.name.lower()
|
||||||
return MUSIC_TAG_BY_NAME.get(l, l)
|
return MUSIC_TAG_BY_NAME.get(lc, lc)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_general(self):
|
def is_general(self):
|
||||||
@ -232,9 +233,7 @@ class MusicTag(namedtuple("MusicTag", ("name", "variant"), defaults=[None])):
|
|||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
import re
|
PATTERNS = [re.compile(r"([A-Za-z]+)[_\- ]*(\d+)"), re.compile(r"([A-Za-z]+)()")]
|
||||||
|
|
||||||
PATTERNS = [re.compile("([A-Za-z]+)[_\- ]*(\d+)"), re.compile("([A-Za-z]+)()")]
|
|
||||||
|
|
||||||
|
|
||||||
def auto_tag(filename):
|
def auto_tag(filename):
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
from interface.tests import AccessTestCase
|
from interface.tests import AccessTestCase
|
||||||
|
|
||||||
from byostorage.user import UserStorage
|
from byostorage.user import UserStorage
|
||||||
from . import models
|
from library import models
|
||||||
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import json
|
import json
|
||||||
8
app/library/tests/test_modules.py
Normal file
8
app/library/tests/test_modules.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
from doctest import DocTestSuite
|
||||||
|
|
||||||
|
from library import music_tags
|
||||||
|
|
||||||
|
|
||||||
|
def load_tests(loader, tests, ignore):
|
||||||
|
tests.addTests(DocTestSuite(music_tags))
|
||||||
|
return tests
|
||||||
@ -477,7 +477,7 @@ class WorkAddDocumentView(CollectionMixin, CreateView):
|
|||||||
doc.sections.create(tag=inst.abbreviate())
|
doc.sections.create(tag=inst.abbreviate())
|
||||||
|
|
||||||
if self.request.headers["Accept"] == "application/json":
|
if self.request.headers["Accept"] == "application/json":
|
||||||
filename = os.path.basename(doc.upload.name)
|
os.path.basename(doc.upload.name)
|
||||||
return JsonResponse(
|
return JsonResponse(
|
||||||
{
|
{
|
||||||
"message": "created",
|
"message": "created",
|
||||||
@ -541,7 +541,7 @@ class DocumentAnnotateView(DocumentMixin, DetailView):
|
|||||||
for tag, start, end in data:
|
for tag, start, end in data:
|
||||||
# pages.sort()
|
# pages.sort()
|
||||||
# end = pages[-1] if len(pages) > 1 else None
|
# end = pages[-1] if len(pages) > 1 else None
|
||||||
o = self.object.sections.create(tag=tag, start=start, end=end)
|
self.object.sections.create(tag=tag, start=start, end=end)
|
||||||
|
|
||||||
return HttpResponse(status=204)
|
return HttpResponse(status=204)
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,20 @@
|
|||||||
|
from interface.views import AuthorizedResourceMixin
|
||||||
|
|
||||||
|
from rest_framework import serializers
|
||||||
|
from rest_framework.exceptions import APIException
|
||||||
|
from rest_framework import generics
|
||||||
|
|
||||||
|
from library.models import Collection, Work, Document, Section, WorkMeta
|
||||||
|
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import urllib
|
||||||
|
import shutil
|
||||||
|
import os.path
|
||||||
|
|
||||||
|
from django.db import transaction
|
||||||
|
from django.core.files.uploadedfile import TemporaryUploadedFile
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Views relating to importing and exporting collection items
|
Views relating to importing and exporting collection items
|
||||||
"""
|
"""
|
||||||
@ -33,22 +50,6 @@ class WorkExportView(EnsembleMixin, WorkMixin, View):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from interface.views import AuthorizedResourceMixin
|
|
||||||
|
|
||||||
from rest_framework import serializers
|
|
||||||
from rest_framework.exceptions import APIException
|
|
||||||
|
|
||||||
from library.models import Collection, Work, Document, Section, WorkMeta
|
|
||||||
|
|
||||||
|
|
||||||
import requests
|
|
||||||
import urllib
|
|
||||||
import shutil
|
|
||||||
import os.path
|
|
||||||
|
|
||||||
from django.db import transaction
|
|
||||||
from django.core.files.uploadedfile import TemporaryUploadedFile
|
|
||||||
|
|
||||||
|
|
||||||
class WorkMetaSerializer(serializers.ModelSerializer):
|
class WorkMetaSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -176,9 +177,6 @@ class CollectionSerializer(serializers.Serializer):
|
|||||||
return Collection.objects.get(pk=collection)
|
return Collection.objects.get(pk=collection)
|
||||||
|
|
||||||
|
|
||||||
from rest_framework import generics
|
|
||||||
|
|
||||||
|
|
||||||
class CollectionExportView(AuthorizedResourceMixin, generics.RetrieveAPIView):
|
class CollectionExportView(AuthorizedResourceMixin, generics.RetrieveAPIView):
|
||||||
serializer_class = CollectionSerializer
|
serializer_class = CollectionSerializer
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
try:
|
try:
|
||||||
from .local_settings import *
|
from .local_settings import * # noqa
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from .default_settings import *
|
from .default_settings import * # noqa
|
||||||
|
|
||||||
INSTALLED_APPS += POLYPHONIC_MODULES
|
INSTALLED_APPS += POLYPHONIC_MODULES # type: ignore #noqa
|
||||||
|
|||||||
@ -15,7 +15,7 @@ Including another URLconf
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path, re_path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
|
|||||||
@ -26,6 +26,7 @@ packages = [{include = "*", from="app"}]
|
|||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
django-debug-toolbar = "5.2"
|
django-debug-toolbar = "5.2"
|
||||||
ruff = "^0.15.12"
|
ruff = "^0.15.12"
|
||||||
|
coverage = "^7.14.0"
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
manage = "manage:main"
|
manage = "manage:main"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user