From 4298f7948e8963176debf5877fce30c49ae4e3ad Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Sat, 15 Dec 2018 22:01:12 +0100 Subject: [PATCH] Remove unused dependency on nose. Move to default tests discovery. --- .gitignore | 1 + Makefile | 10 +++ README.md | 2 +- requirements/requirements-test.txt | 4 +- src/catalogue/tests/__init__.py | 10 --- .../tests/files/fraszka-do-anusie.xml | 0 src/catalogue/tests/files/fraszki.xml | 0 .../{book_import.py => test_book_import.py} | 5 +- .../tests/{bookmedia.py => test_bookmedia.py} | 0 .../tests/{cover.py => test_cover.py} | 0 src/catalogue/tests/{tags.py => test_tags.py} | 0 .../{templatetags.py => test_templatetags.py} | 0 .../tests/{visit.py => test_visit.py} | 0 src/oai/tests/__init__.py | 5 -- src/oai/tests/files/antygona.xml | 0 src/oai/tests/files/lubie-kiedy-kobieta.xml | 0 .../tests/{oaipmhapi.py => test_oaipmhapi.py} | 0 src/opds/tests/__init__.py | 62 ------------------- src/opds/tests/test_opds.py | 62 +++++++++++++++++++ src/picture/tests/__init__.py | 5 -- ...cture_import.py => test_picture_import.py} | 0 21 files changed, 77 insertions(+), 89 deletions(-) create mode 100644 Makefile mode change 100755 => 100644 src/catalogue/tests/files/fraszka-do-anusie.xml mode change 100755 => 100644 src/catalogue/tests/files/fraszki.xml rename src/catalogue/tests/{book_import.py => test_book_import.py} (99%) rename src/catalogue/tests/{bookmedia.py => test_bookmedia.py} (100%) rename src/catalogue/tests/{cover.py => test_cover.py} (100%) mode change 100755 => 100644 rename src/catalogue/tests/{tags.py => test_tags.py} (100%) rename src/catalogue/tests/{templatetags.py => test_templatetags.py} (100%) rename src/catalogue/tests/{visit.py => test_visit.py} (100%) mode change 100755 => 100644 src/oai/tests/files/antygona.xml mode change 100755 => 100644 src/oai/tests/files/lubie-kiedy-kobieta.xml rename src/oai/tests/{oaipmhapi.py => test_oaipmhapi.py} (100%) mode change 100755 => 100644 src/opds/tests/__init__.py create mode 100644 src/opds/tests/test_opds.py rename src/picture/tests/{picture_import.py => test_picture_import.py} (100%) diff --git a/.gitignore b/.gitignore index ed1bedc89..a1c1ad15a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ src/wolnelektury/static/scss/*.css coverage.xml pip-log.txt nosetests.xml +/htmlcov # Mac OS X garbage .DS_Store diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..5ef3ba7e4 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +.ONESHELL: +test: + cd src + coverage run --branch --source='.' ./manage.py test; true + rm -rf ../htmlcov + coverage html -d ../htmlcov.new + rm -rf ../htmlcov + mv ../htmlcov.new ../htmlcov + coverage report + rm .coverage diff --git a/README.md b/README.md index 340ae0477..5b39ff9cb 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ How to deploy (development version) 1. Checkout the source code from Github and enter the directory 2. Install libraries (we recommend using pip): - pip install -r requirements.txt + pip install -r requirements/requirements.txt git submodule update --init 3. Setup your local configuration based on settings.py. You need to generate a new SECRET_KEY, database stuff and domain related stuff. diff --git a/requirements/requirements-test.txt b/requirements/requirements-test.txt index 87aa0fe38..794632d4d 100644 --- a/requirements/requirements-test.txt +++ b/requirements/requirements-test.txt @@ -1,6 +1,4 @@ -i https://py.mdrn.pl:8443/simple/ -nose>=1.3.7 -django-nose>=1.4.2,<1.5 -nosexcover +coverage mock diff --git a/src/catalogue/tests/__init__.py b/src/catalogue/tests/__init__.py index 4eb8e8dd6..e69de29bb 100644 --- a/src/catalogue/tests/__init__.py +++ b/src/catalogue/tests/__init__.py @@ -1,10 +0,0 @@ -# -*- coding: utf-8 -*- -# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. -# -from catalogue.tests.book_import import * -from catalogue.tests.bookmedia import * -from catalogue.tests.cover import * -from catalogue.tests.tags import * -from catalogue.tests.templatetags import * -from .visit import * diff --git a/src/catalogue/tests/files/fraszka-do-anusie.xml b/src/catalogue/tests/files/fraszka-do-anusie.xml old mode 100755 new mode 100644 diff --git a/src/catalogue/tests/files/fraszki.xml b/src/catalogue/tests/files/fraszki.xml old mode 100755 new mode 100644 diff --git a/src/catalogue/tests/book_import.py b/src/catalogue/tests/test_book_import.py similarity index 99% rename from src/catalogue/tests/book_import.py rename to src/catalogue/tests/test_book_import.py index a4452686c..da5e58621 100644 --- a/src/catalogue/tests/book_import.py +++ b/src/catalogue/tests/test_book_import.py @@ -7,7 +7,6 @@ from catalogue.test_utils import * from catalogue import models from librarian import WLURI -from nose.tools import raises from os import path, makedirs @@ -112,12 +111,12 @@ class BookImportLogicTests(WLTestCase): self.assertEqual(book.fragments.count(), 0) self.assertEqual(book.tags.filter(category='theme').count(), 0) - @raises(ValueError) def test_book_with_invalid_slug(self): """ Book with invalid characters in slug shouldn't be imported """ self.book_info.url = WLURI.from_slug(u"default_book") book_text = "" - models.Book.from_text_and_meta(ContentFile(book_text), self.book_info) + with self.assertRaises(ValueError): + models.Book.from_text_and_meta(ContentFile(book_text), self.book_info) def test_book_replace_title(self): book_text = """""" diff --git a/src/catalogue/tests/bookmedia.py b/src/catalogue/tests/test_bookmedia.py similarity index 100% rename from src/catalogue/tests/bookmedia.py rename to src/catalogue/tests/test_bookmedia.py diff --git a/src/catalogue/tests/cover.py b/src/catalogue/tests/test_cover.py old mode 100755 new mode 100644 similarity index 100% rename from src/catalogue/tests/cover.py rename to src/catalogue/tests/test_cover.py diff --git a/src/catalogue/tests/tags.py b/src/catalogue/tests/test_tags.py similarity index 100% rename from src/catalogue/tests/tags.py rename to src/catalogue/tests/test_tags.py diff --git a/src/catalogue/tests/templatetags.py b/src/catalogue/tests/test_templatetags.py similarity index 100% rename from src/catalogue/tests/templatetags.py rename to src/catalogue/tests/test_templatetags.py diff --git a/src/catalogue/tests/visit.py b/src/catalogue/tests/test_visit.py similarity index 100% rename from src/catalogue/tests/visit.py rename to src/catalogue/tests/test_visit.py diff --git a/src/oai/tests/__init__.py b/src/oai/tests/__init__.py index 561ef604a..e69de29bb 100644 --- a/src/oai/tests/__init__.py +++ b/src/oai/tests/__init__.py @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- -# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. -# -from oai.tests.oaipmhapi import * diff --git a/src/oai/tests/files/antygona.xml b/src/oai/tests/files/antygona.xml old mode 100755 new mode 100644 diff --git a/src/oai/tests/files/lubie-kiedy-kobieta.xml b/src/oai/tests/files/lubie-kiedy-kobieta.xml old mode 100755 new mode 100644 diff --git a/src/oai/tests/oaipmhapi.py b/src/oai/tests/test_oaipmhapi.py similarity index 100% rename from src/oai/tests/oaipmhapi.py rename to src/oai/tests/test_oaipmhapi.py diff --git a/src/opds/tests/__init__.py b/src/opds/tests/__init__.py old mode 100755 new mode 100644 index 339bfaa37..e69de29bb --- a/src/opds/tests/__init__.py +++ b/src/opds/tests/__init__.py @@ -1,62 +0,0 @@ -# -*- coding: utf-8 -*- -# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. -# -from unittest import skipIf -from lxml import etree -from django.conf import settings -import catalogue -from catalogue.test_utils import WLTestCase, get_fixture -from catalogue.models import Book -from librarian import WLURI, XMLNamespace -from search.index import Index - -AtomNS = XMLNamespace("http://www.w3.org/2005/Atom") - - -@skipIf(getattr(settings, 'NO_SEARCH_INDEX', False), u'Requires search server and NO_SEARCH_INDEX=False.') -class OpdsSearchTests(WLTestCase): - """Tests search feed in OPDS..""" - def setUp(self): - WLTestCase.setUp(self) - index = Index() - index.index.delete_all() - index.index.commit() - - self.do_doktora = Book.from_xml_file( - get_fixture('do-doktora.xml')) - self.do_anusie = Book.from_xml_file( - get_fixture('fraszka-do-anusie.xml', catalogue)) - - def assert_finds(self, query, books): - """Takes a query and tests against books expected to be found.""" - tree = etree.fromstring( - self.client.get('/opds/search/?%s' % query).content) - elem_ids = tree.findall('.//%s/%s' % (AtomNS('entry'), AtomNS('id'))) - slugs = [WLURI(elem.text).slug for elem in elem_ids] - self.assertEqual(set(slugs), set(b.slug for b in books), u"OPDS search '%s' failed." % query) - - def test_opds_search_simple(self): - """Do a simple q= test, also emulate dumb OPDS clients.""" - both = {self.do_doktora, self.do_anusie} - self.assert_finds('q=fraszka', both) - self.assert_finds('q=fraszka&author={opds:author}', both) - - def test_opds_search_title(self): - """Search by title.""" - both = {self.do_doktora, self.do_anusie} - self.assert_finds('title=fraszka', both) - self.assert_finds('title=fraszka', both) - self.assert_finds('q=title:doktora', [self.do_doktora]) - - def test_opds_search_author(self): - """Search by author.""" - self.assert_finds('q=fraszka&author=Kochanowski', [self.do_doktora]) - self.assert_finds('q=fraszka+author:Kochanowski', [self.do_doktora]) - self.assert_finds('q=Kochanowski', [self.do_doktora]) - - def test_opds_search_translator(self): - """Search by translator.""" - self.assert_finds('q=fraszka&translator=Fikcyjny', [self.do_doktora]) - self.assert_finds('q=fraszka+translator:Fikcyjny', [self.do_doktora]) - self.assert_finds('q=Fikcyjny', [self.do_doktora]) diff --git a/src/opds/tests/test_opds.py b/src/opds/tests/test_opds.py new file mode 100644 index 000000000..339bfaa37 --- /dev/null +++ b/src/opds/tests/test_opds.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from unittest import skipIf +from lxml import etree +from django.conf import settings +import catalogue +from catalogue.test_utils import WLTestCase, get_fixture +from catalogue.models import Book +from librarian import WLURI, XMLNamespace +from search.index import Index + +AtomNS = XMLNamespace("http://www.w3.org/2005/Atom") + + +@skipIf(getattr(settings, 'NO_SEARCH_INDEX', False), u'Requires search server and NO_SEARCH_INDEX=False.') +class OpdsSearchTests(WLTestCase): + """Tests search feed in OPDS..""" + def setUp(self): + WLTestCase.setUp(self) + index = Index() + index.index.delete_all() + index.index.commit() + + self.do_doktora = Book.from_xml_file( + get_fixture('do-doktora.xml')) + self.do_anusie = Book.from_xml_file( + get_fixture('fraszka-do-anusie.xml', catalogue)) + + def assert_finds(self, query, books): + """Takes a query and tests against books expected to be found.""" + tree = etree.fromstring( + self.client.get('/opds/search/?%s' % query).content) + elem_ids = tree.findall('.//%s/%s' % (AtomNS('entry'), AtomNS('id'))) + slugs = [WLURI(elem.text).slug for elem in elem_ids] + self.assertEqual(set(slugs), set(b.slug for b in books), u"OPDS search '%s' failed." % query) + + def test_opds_search_simple(self): + """Do a simple q= test, also emulate dumb OPDS clients.""" + both = {self.do_doktora, self.do_anusie} + self.assert_finds('q=fraszka', both) + self.assert_finds('q=fraszka&author={opds:author}', both) + + def test_opds_search_title(self): + """Search by title.""" + both = {self.do_doktora, self.do_anusie} + self.assert_finds('title=fraszka', both) + self.assert_finds('title=fraszka', both) + self.assert_finds('q=title:doktora', [self.do_doktora]) + + def test_opds_search_author(self): + """Search by author.""" + self.assert_finds('q=fraszka&author=Kochanowski', [self.do_doktora]) + self.assert_finds('q=fraszka+author:Kochanowski', [self.do_doktora]) + self.assert_finds('q=Kochanowski', [self.do_doktora]) + + def test_opds_search_translator(self): + """Search by translator.""" + self.assert_finds('q=fraszka&translator=Fikcyjny', [self.do_doktora]) + self.assert_finds('q=fraszka+translator:Fikcyjny', [self.do_doktora]) + self.assert_finds('q=Fikcyjny', [self.do_doktora]) diff --git a/src/picture/tests/__init__.py b/src/picture/tests/__init__.py index b2e50b00f..e69de29bb 100644 --- a/src/picture/tests/__init__.py +++ b/src/picture/tests/__init__.py @@ -1,5 +0,0 @@ -# -*- coding: utf-8 -*- -# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. -# -from picture.tests.picture_import import * diff --git a/src/picture/tests/picture_import.py b/src/picture/tests/test_picture_import.py similarity index 100% rename from src/picture/tests/picture_import.py rename to src/picture/tests/test_picture_import.py -- 2.20.1