diff --git a/.drone.yml b/.drone.yml index 97b24fe..37d0fdf 100644 --- a/.drone.yml +++ b/.drone.yml @@ -8,8 +8,16 @@ platform: arch: amd64 steps: -- name: test - commands: - - dnf install -y python3 python3-pip - - pip3 install -U Django - - python3 manage.py test + - name: install deps + commands: + - dnf install -y python3 python3-pip + - pip3 install -U Django coverage flake8 pylint django-coverage-plugin pylint-django + - name: run unittests + commands: + - coverage run --source='.' manage.py test --noinput --parallel + - name: run flake8 + commands: + - flake8 + - name: run pylint + commands: + - pylint --rcfile=.pylintrc -- **/*.py diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..e0faac0 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,14 @@ +[MASTER] +load-plugins=pylint_django + +[FORMAT] +max-line-length=120 + +[MESSAGES CONTROL] +disable=missing-docstring,invalid-name + +[DESIGN] +max-parents=13 + +[TYPECHECK] +generated-members=REQUEST,acl_users,aq_parent,"[a-zA-Z]+_set{1,2}",save,delete diff --git a/im/settings.py b/im/settings.py index 3969795..26d629a 100644 --- a/im/settings.py +++ b/im/settings.py @@ -38,6 +38,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'inventory.apps.InventoryConfig', + 'linttest', ] MIDDLEWARE = [ @@ -100,6 +101,10 @@ AUTH_PASSWORD_VALIDATORS = [ }, ] +# enabling this may speed up testing +#PASSWORD_HASHERS = [ +# 'django.contrib.auth.hashers.MD5PasswordHasher', +#] # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ diff --git a/inventory/tests.py b/inventory/tests.py index 7ce503c..52c08d1 100644 --- a/inventory/tests.py +++ b/inventory/tests.py @@ -1,3 +1,25 @@ from django.test import TestCase +from django.test import Client -# Create your tests here. +from inventory.models import PantryItem, Category + + +class PantryItemTestCase(TestCase): + """ simple test case for a model""" + def setUp(self): + cat = Category.objects.create(name="UNCATEGORIZED") + PantryItem.objects.create(name="testitem", category=cat) + + def test_pantryitem_looksok(self): + """Pantryitems to string is ok""" + testitem = PantryItem.objects.get(name="testitem") + self.assertEqual(str(testitem), 'testitem') + + +class InterFaceTestCase(TestCase): + """Simple test case for the web interface""" + + def test_consume_view_exists(self): + c = Client() + response = c.get('/consume/') + self.assertTrue("TODO" not in response) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..fa11995 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,9 @@ +[flake8] +max-line-length = 120 +exclude = .tox,.git,*/migrations/*,*/static/CACHE/*,docs,node_modules,venv + +[coverage:run] +include = '.' +omit = *migrations*, *tests* +plugins = + django_coverage_plugin