diff --git a/.dockerignore b/.dockerignore index c008b2c..dba8e09 100644 --- a/.dockerignore +++ b/.dockerignore @@ -7,4 +7,5 @@ !comic !comic_auth !manage.py -!pytest \ No newline at end of file +!pyproject.toml +!setup.cfg \ No newline at end of file diff --git a/Pipfile b/Pipfile index 9228e96..975ab62 100644 --- a/Pipfile +++ b/Pipfile @@ -7,7 +7,9 @@ verify_ssl = true pdbpp = "*" pytest-django = "*" pytest-black = "*" +pytest-cov = "*" pytest-flake8 = "*" +pytest-isort = "*" [packages] ujson = "*" diff --git a/Pipfile.lock b/Pipfile.lock index c1e22b4..ff2f7f0 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "6ac08e443037cce0633c9272ad59f12fc7924be76f4cc10222825dc09d16b661" + "sha256": "94f40433522196e554c531ddae0e2491a8713bbd73132c710ae1844aed548f3d" }, "pipfile-spec": 6, "requires": { @@ -292,13 +292,41 @@ ], "version": "==7.0" }, - "colorama": { + "coverage": { "hashes": [ - "sha256:05eed71e2e327246ad6b38c540c4a3117230b19679b875190486ddd2d721422d", - "sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48" + "sha256:3684fabf6b87a369017756b551cef29e505cb155ddb892a7a29277b978da88b9", + "sha256:39e088da9b284f1bd17c750ac672103779f7954ce6125fd4382134ac8d152d74", + "sha256:3c205bc11cc4fcc57b761c2da73b9b72a59f8d5ca89979afb0c1c6f9e53c7390", + "sha256:465ce53a8c0f3a7950dfb836438442f833cf6663d407f37d8c52fe7b6e56d7e8", + "sha256:48020e343fc40f72a442c8a1334284620f81295256a6b6ca6d8aa1350c763bbe", + "sha256:5296fc86ab612ec12394565c500b412a43b328b3907c0d14358950d06fd83baf", + "sha256:5f61bed2f7d9b6a9ab935150a6b23d7f84b8055524e7be7715b6513f3328138e", + "sha256:68a43a9f9f83693ce0414d17e019daee7ab3f7113a70c79a3dd4c2f704e4d741", + "sha256:6b8033d47fe22506856fe450470ccb1d8ba1ffb8463494a15cfc96392a288c09", + "sha256:7ad7536066b28863e5835e8cfeaa794b7fe352d99a8cded9f43d1161be8e9fbd", + "sha256:7bacb89ccf4bedb30b277e96e4cc68cd1369ca6841bde7b005191b54d3dd1034", + "sha256:839dc7c36501254e14331bcb98b27002aa415e4af7ea039d9009409b9d2d5420", + "sha256:8f9a95b66969cdea53ec992ecea5406c5bd99c9221f539bca1e8406b200ae98c", + "sha256:932c03d2d565f75961ba1d3cec41ddde00e162c5b46d03f7423edcb807734eab", + "sha256:988529edadc49039d205e0aa6ce049c5ccda4acb2d6c3c5c550c17e8c02c05ba", + "sha256:998d7e73548fe395eeb294495a04d38942edb66d1fa61eb70418871bc621227e", + "sha256:9de60893fb447d1e797f6bf08fdf0dbcda0c1e34c1b06c92bd3a363c0ea8c609", + "sha256:9e80d45d0c7fcee54e22771db7f1b0b126fb4a6c0a2e5afa72f66827207ff2f2", + "sha256:a545a3dfe5082dc8e8c3eb7f8a2cf4f2870902ff1860bd99b6198cfd1f9d1f49", + "sha256:a5d8f29e5ec661143621a8f4de51adfb300d7a476224156a39a392254f70687b", + "sha256:aca06bfba4759bbdb09bf52ebb15ae20268ee1f6747417837926fae990ebc41d", + "sha256:bb23b7a6fd666e551a3094ab896a57809e010059540ad20acbeec03a154224ce", + "sha256:bfd1d0ae7e292105f29d7deaa9d8f2916ed8553ab9d5f39ec65bcf5deadff3f9", + "sha256:c62ca0a38958f541a73cf86acdab020c2091631c137bd359c4f5bddde7b75fd4", + "sha256:c709d8bda72cf4cd348ccec2a4881f2c5848fd72903c185f363d361b2737f773", + "sha256:c968a6aa7e0b56ecbd28531ddf439c2ec103610d3e2bf3b75b813304f8cb7723", + "sha256:df785d8cb80539d0b55fd47183264b7002077859028dfe3070cf6359bf8b2d9c", + "sha256:f406628ca51e0ae90ae76ea8398677a921b36f0bd71aab2099dfed08abd0322f", + "sha256:f46087bbd95ebae244a0eda01a618aff11ec7a069b15a3ef8f6b520db523dcf1", + "sha256:f8019c5279eb32360ca03e9fac40a12667715546eed5c5eb59eb381f2f501260", + "sha256:fc5f4d209733750afd2714e9109816a29500718b32dd9a5db01c0cb3a019b96a" ], - "markers": "sys_platform == 'win32'", - "version": "==0.4.1" + "version": "==4.5.3" }, "entrypoints": { "hashes": [ @@ -328,6 +356,13 @@ ], "version": "==0.18" }, + "isort": { + "hashes": [ + "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1", + "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd" + ], + "version": "==4.3.21" + }, "mccabe": { "hashes": [ "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42", @@ -393,10 +428,10 @@ }, "pyparsing": { "hashes": [ - "sha256:1873c03321fc118f4e9746baf201ff990ceb915f433f23b395f5580d1840cb2a", - "sha256:9b6323ef4ab914af344ba97510e966d64ba91055d6b9afa6b30799340e89cc03" + "sha256:43c5486cefefa536c9aab528881c992328f020eefe4f6d06332449c365218580", + "sha256:d6c5ffe9d0305b9b977f7a642d36b9370954d1da7ada4c62393382cbadad4265" ], - "version": "==2.4.0" + "version": "==2.4.1.1" }, "pyreadline": { "hashes": [ @@ -418,6 +453,14 @@ "index": "pypi", "version": "==0.3.7" }, + "pytest-cov": { + "hashes": [ + "sha256:2b097cde81a302e1047331b48cadacf23577e431b61e9c6f49a1170bbe3d3da6", + "sha256:e00ea4fdde970725482f1f35630d12f074e121a23801aabf2ae154ec6bdd343a" + ], + "index": "pypi", + "version": "==2.7.1" + }, "pytest-django": { "hashes": [ "sha256:264fb4c506db5d48a6364c311a0b00b7b48a52715bad8839b2d8bee9b99ed6bb", @@ -434,6 +477,14 @@ "index": "pypi", "version": "==1.0.4" }, + "pytest-isort": { + "hashes": [ + "sha256:3be60e0de277b420ff89303ca6494320c41f7819ffa898756b90ef976e4c636a", + "sha256:4bfee60dad1870b51700d55a85f5ceda766bd9d3d2878c1bbabee80e61b1be1a" + ], + "index": "pypi", + "version": "==0.3.1" + }, "six": { "hashes": [ "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", diff --git a/comic/admin.py b/comic/admin.py index 516f47a..0fc5a11 100644 --- a/comic/admin.py +++ b/comic/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from comic.models import Setting, ComicBook, ComicPage, ComicStatus, Directory +from comic.models import ComicBook, ComicPage, ComicStatus, Directory, Setting @admin.register(Setting) diff --git a/comic/management/commands/scan_comics.py b/comic/management/commands/scan_comics.py index 0eb737e..d2df2ca 100644 --- a/comic/management/commands/scan_comics.py +++ b/comic/management/commands/scan_comics.py @@ -3,7 +3,7 @@ from os.path import isdir from django.core.management.base import BaseCommand -from comic.models import Setting, Directory, ComicBook +from comic.models import ComicBook, Directory, Setting class Command(BaseCommand): diff --git a/comic/migrations/0001_initial.py b/comic/migrations/0001_initial.py index 6b4c8b5..84b7912 100644 --- a/comic/migrations/0001_initial.py +++ b/comic/migrations/0001_initial.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/comic/migrations/0002_auto_20150616_1613.py b/comic/migrations/0002_auto_20150616_1613.py index bc24987..8728687 100644 --- a/comic/migrations/0002_auto_20150616_1613.py +++ b/comic/migrations/0002_auto_20150616_1613.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/comic/migrations/0003_comicbook_comicpage.py b/comic/migrations/0003_comicbook_comicpage.py index 3decbaa..c3d5497 100644 --- a/comic/migrations/0003_comicbook_comicpage.py +++ b/comic/migrations/0003_comicbook_comicpage.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/comic/migrations/0004_comicbook_unread.py b/comic/migrations/0004_comicbook_unread.py index 20bdb62..4267c99 100644 --- a/comic/migrations/0004_comicbook_unread.py +++ b/comic/migrations/0004_comicbook_unread.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/comic/migrations/0005_auto_20150625_1400.py b/comic/migrations/0005_auto_20150625_1400.py index c5ee393..fcc72ac 100644 --- a/comic/migrations/0005_auto_20150625_1400.py +++ b/comic/migrations/0005_auto_20150625_1400.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from django.conf import settings -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/comic/migrations/0006_auto_20150625_1411.py b/comic/migrations/0006_auto_20150625_1411.py index 6563179..2b1803c 100644 --- a/comic/migrations/0006_auto_20150625_1411.py +++ b/comic/migrations/0006_auto_20150625_1411.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/comic/migrations/0007_auto_20150626_1820.py b/comic/migrations/0007_auto_20150626_1820.py index daa26be..606ae9e 100644 --- a/comic/migrations/0007_auto_20150626_1820.py +++ b/comic/migrations/0007_auto_20150626_1820.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/comic/migrations/0008_auto_20160331_1140.py b/comic/migrations/0008_auto_20160331_1140.py index ea762d4..5a00214 100644 --- a/comic/migrations/0008_auto_20160331_1140.py +++ b/comic/migrations/0008_auto_20160331_1140.py @@ -3,11 +3,12 @@ from __future__ import unicode_literals import datetime -from django.db import migrations, models -import django.db.models.deletion -from django.utils.timezone import utc import uuid +import django.db.models.deletion +from django.db import migrations, models +from django.utils.timezone import utc + class Migration(migrations.Migration): diff --git a/comic/migrations/0009_auto_20160331_1140.py b/comic/migrations/0009_auto_20160331_1140.py index 198cbcf..fbda75a 100644 --- a/comic/migrations/0009_auto_20160331_1140.py +++ b/comic/migrations/0009_auto_20160331_1140.py @@ -2,10 +2,10 @@ # Generated by Django 1.9.2 on 2016-03-31 10:40 from __future__ import unicode_literals -from django.db import migrations - import uuid +from django.db import migrations + def gen_uuid(apps, schema_editor): comicbook = apps.get_model("comic", "comicbook") diff --git a/comic/migrations/0010_auto_20160331_1140.py b/comic/migrations/0010_auto_20160331_1140.py index 9bb6366..bc1f7f1 100644 --- a/comic/migrations/0010_auto_20160331_1140.py +++ b/comic/migrations/0010_auto_20160331_1140.py @@ -2,10 +2,10 @@ # Generated by Django 1.9.2 on 2016-03-31 10:40 from __future__ import unicode_literals -from django.db import migrations, models - import uuid +from django.db import migrations, models + class Migration(migrations.Migration): diff --git a/comic/migrations/0012_auto_20160401_0949.py b/comic/migrations/0012_auto_20160401_0949.py index 0b4c8e3..13c9a59 100644 --- a/comic/migrations/0012_auto_20160401_0949.py +++ b/comic/migrations/0012_auto_20160401_0949.py @@ -2,9 +2,10 @@ # Generated by Django 1.9.2 on 2016-04-01 08:49 from __future__ import unicode_literals -from django.db import migrations, models import uuid +from django.db import migrations, models + class Migration(migrations.Migration): diff --git a/comic/migrations/0018_auto_20170113_1531.py b/comic/migrations/0018_auto_20170113_1531.py index 9e927db..89738b9 100644 --- a/comic/migrations/0018_auto_20170113_1531.py +++ b/comic/migrations/0018_auto_20170113_1531.py @@ -9,7 +9,7 @@ def gen_feeds(apps, schema_editor): user_misc = apps.get_model("comic", "UserMisc") User = apps.get_model("auth", "user") for user in User.objects.all(): - um = user_misc.objects.create(user=user) + user_misc.objects.create(user=user) class Migration(migrations.Migration): diff --git a/comic/models.py b/comic/models.py index d9e585d..1c37102 100644 --- a/comic/models.py +++ b/comic/models.py @@ -1,6 +1,6 @@ import uuid import zipfile -from os import path, listdir +from os import listdir, path from django.conf import settings from django.contrib.auth.models import User diff --git a/comic/rarfile.py b/comic/rarfile.py index 4a705e7..451fc96 100644 --- a/comic/rarfile.py +++ b/comic/rarfile.py @@ -83,12 +83,15 @@ __all__ = ["is_rarfile", "RarInfo", "RarFile", "RarExtFile"] ## Imports and compat - support both Python 2.x and 3.x ## -import sys, os, struct, errno -from struct import pack, unpack +import errno +import os +import struct +import sys from binascii import crc32 -from tempfile import mkstemp -from subprocess import Popen, PIPE, STDOUT from datetime import datetime +from struct import pack, unpack +from subprocess import PIPE, STDOUT, Popen +from tempfile import mkstemp # only needed for encryped headers try: diff --git a/comic/tests/test_models.py b/comic/tests/test_models.py index 7231049..f162bf1 100644 --- a/comic/tests/test_models.py +++ b/comic/tests/test_models.py @@ -3,10 +3,10 @@ import os from os import path from django.contrib.auth.models import User -from django.test import TestCase, Client +from django.test import Client, TestCase from django.utils.http import urlsafe_base64_encode -from comic.models import ComicBook, ComicPage, Setting, ComicStatus, Directory +from comic.models import ComicBook, ComicPage, ComicStatus, Directory, Setting from comic.util import generate_directory diff --git a/comic/urls.py b/comic/urls.py index 6d15471..b11f613 100644 --- a/comic/urls.py +++ b/comic/urls.py @@ -1,7 +1,6 @@ from django.conf.urls import url -from . import feeds -from . import views +from . import feeds, views urlpatterns = [ url(r"^$", views.comic_list, name="index"), diff --git a/comic/util.py b/comic/util.py index 7baeb22..a5ee6e8 100644 --- a/comic/util.py +++ b/comic/util.py @@ -1,10 +1,10 @@ from collections import OrderedDict -from os import path, listdir +from os import listdir, path from django.db.transaction import atomic from django.utils.http import urlsafe_base64_encode -from .models import ComicBook, Setting, ComicStatus, Directory +from .models import ComicBook, ComicStatus, Directory, Setting def generate_title_from_path(file_path): diff --git a/comic/views.py b/comic/views.py index a2a4b47..444261b 100644 --- a/comic/views.py +++ b/comic/views.py @@ -5,26 +5,26 @@ except ImportError: import uuid from os import path -from django.contrib.auth import login, authenticate +from django.contrib.auth import authenticate, login from django.contrib.auth.decorators import login_required, user_passes_test from django.contrib.auth.models import User from django.db.models import Max from django.db.transaction import atomic from django.http import HttpResponse -from django.shortcuts import render, redirect, get_object_or_404 +from django.shortcuts import get_object_or_404, redirect, render from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.http import require_POST -from .forms import SettingsForm, AccountForm, EditUserForm, AddUserForm, InitialSetupForm -from .models import Setting, ComicBook, ComicStatus, Directory, ComicPage, UserMisc +from .forms import AccountForm, AddUserForm, EditUserForm, InitialSetupForm, SettingsForm +from .models import ComicBook, ComicPage, ComicStatus, Directory, Setting, UserMisc from .util import ( - generate_breadcrumbs_from_path, - generate_breadcrumbs_from_menu, - generate_title_from_path, Menu, + generate_breadcrumbs_from_menu, + generate_breadcrumbs_from_path, generate_directory, generate_label, + generate_title_from_path, ) diff --git a/comic_auth/views.py b/comic_auth/views.py index 1967fdb..903b3f4 100644 --- a/comic_auth/views.py +++ b/comic_auth/views.py @@ -1,6 +1,6 @@ from django.contrib.auth import authenticate, login, logout from django.contrib.auth.models import User -from django.shortcuts import render, redirect +from django.shortcuts import redirect, render from comic_auth.forms import LoginForm diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 0000000..a735eec --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,24 @@ +version: "3.7" + +services: + tests: + build: . + environment: + - TEST_DATABASE_URL=postgres://admin:password@database:5432/cbwebreader_test + - DJANGO_SETTINGS_MODULE=cbreader.settings.base + links: + - database + command: > + pytest + -vvv + --isort + --flake8 + --black + --cov=. + --cov-report=term-missing + --junitxml=/tmp/test-results.xml + volumes: + - ./cbreader:/src/cbreader + - ./comic:/src/comic + - ./comic_auth:/src/comic_auth + - ${COMIC_BOOK_VOLUME}:/data diff --git a/docker-compose.yml b/docker-compose.yml index a2c318a..880dce9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,6 @@ -version: '3.7' +version: "3.7" services: - app: build: . environment: @@ -15,11 +14,11 @@ services: - database ports: - "8000:8000" - # volumes: - # - ./cbreader:/src/cbreader - # - ./comic:/src/comic - # - ./comic_auth:/src/comic_auth - # - ${COMIC_BOOK_VOLUME}:/data + volumes: + - ./cbreader:/src/cbreader + - ./comic:/src/comic + - ./comic_auth:/src/comic_auth + - ${COMIC_BOOK_VOLUME}:/data command: python manage.py runserver 0.0.0.0:8000 database: diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..937c535 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,21 @@ +[tool:pytest] +addopts = -vv --black --isort --flake8 + +[flake8] +max-line-length = 119 +ignore = + # Ignore rules which contradicts black's formatting choices: + * E501 + * W503 + * W504 + * E266 +exclude = + # Exclude these files + comic/rarfile.py + + +[tool:isort] +line_length = 119 +indent = ' ' +multi_line_output = 3 +include_trailing_comma = 1 \ No newline at end of file