From b77b8d550466be3a2a8407d66beb350f87f94cc5 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Thu, 8 Dec 2016 15:34:04 -0500 Subject: [PATCH] Release version 0.0.4 (#7) * Setup for Coverage and Codcov.io (#6) * add pip install command (#8) * More tests (#9) * Update Version number --- .coveragerc | 13 ++++++++++++ README.md | 7 +++++-- dbfilestorage/urls.py | 7 +++---- docs/conf.py | 4 ++-- requirements.txt | 1 + setup.cfg | 8 ++++++++ setup.py | 2 +- tests/tests.py | 47 ++++++++++++++++++++++++++++++++++--------- 8 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 .coveragerc create mode 100644 setup.cfg diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..e227db0 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,13 @@ +[run] +branch = True +source = dbfilestorage + +[report] +exclude_lines = + if self.debug: + pragma: no cover + raise NotImplementedError + if __name__ == .__main__.: +ignore_errors = True +omit = + tests/* diff --git a/README.md b/README.md index 2b80d5b..faefb51 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Django-dbfilestorage - [![CircleCI](https://circleci.com/gh/tyrelsouza/django-dbfilestorage.svg?style=svg)](https://circleci.com/gh/tyrelsouza/django-dbfilestorage) [![codecov](https://codecov.io/gh/tyrelsouza/django-dbfilestorage/branch/master/graph/badge.svg)](https://codecov.io/gh/tyrelsouza/django-dbfilestorage) Custom file storage for Django that stores file data and content type in the database. @@ -10,7 +9,11 @@ Intended to be used in tests, never in production. ## INSTALLATION -In your project's `settings.py` file, add `'dbfilestorage'` to your `INSTALLED_APPS`: +``` +pip install django-dbfilestorage +``` + +Then in your project's `settings.py` file, add `'dbfilestorage'` to your `INSTALLED_APPS`: ```python INSTALLED_APPS = ( diff --git a/dbfilestorage/urls.py b/dbfilestorage/urls.py index 1fe30a0..35b7353 100644 --- a/dbfilestorage/urls.py +++ b/dbfilestorage/urls.py @@ -1,7 +1,6 @@ -from django.conf.urls import patterns, url +from django.conf.urls import url import views -urlpatterns = patterns( - '', +urlpatterns = [ url(r'^(?P.*)$', views.show_file, name="dbstorage_file"), -) +] diff --git a/docs/conf.py b/docs/conf.py index f56ad0a..febbc98 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -54,9 +54,9 @@ author = u'Tyrel Souza' # built documents. # # The short X.Y version. -version = u'0.0.3' +version = u'0.0.4' # The full version, including alpha/beta/rc tags. -release = u'0.0.3' +release = u'0.0.4' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/requirements.txt b/requirements.txt index edde82d..d09cb1e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ Django==1.10.4 Sphinx==1.5 +coverage==4.2 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..1e39ce9 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,8 @@ +[nosetests] +verbosity=1 +detailed-errors=1 +with-coverage=1 +cover-package=dbfilestorage +#pdb=1 +#pdb-failures=1 + diff --git a/setup.py b/setup.py index 47d4510..2a10b26 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ except ImportError: setup( name="django-dbfilestorage", - version="0.0.3", + version="0.0.4", description="Database backed file storage for testing.", long_description="Database backed file storage for testing. Stores files as base64 encoded textfields.", author="Tyrel Souza", diff --git a/tests/tests.py b/tests/tests.py index 170b37f..60ff34f 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -4,12 +4,14 @@ import os from dbfilestorage.models import DBFile from django.core.files.storage import default_storage -from django.test import TestCase +from django.test import TestCase, Client from django.test.utils import override_settings PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__)) +DEFAULT_FILE_STORAGE = "dbfilestorage.storage.DBStorage" +@override_settings(DEFAULT_FILE_STORAGE=DEFAULT_FILE_STORAGE) class DBFileTest(TestCase): def setUp(self): self.filename = "kris.jpg" @@ -20,37 +22,64 @@ class DBFileTest(TestCase): with open(self.filepath, 'rb') as f: return default_storage.save(self.filepath, f) - @override_settings( - DEFAULT_FILE_STORAGE="dbfilestorage.storage.DBStorage") def test_upload(self): """ Test that the file storage uploads and puts in DB Properly """ name = self._upload() self.assertEqual(name, self.md5) self.assertTrue(DBFile.objects.filter(name=name).exists()) - @override_settings( - DEFAULT_FILE_STORAGE="dbfilestorage.storage.DBStorage") def test_equality(self): """ Test that the DB entry matches what is expected from the file """ name = self._upload() + with open(self.filepath, 'rb') as f: dbf = DBFile.objects.get(name=name) self.assertEqual(dbf.b64.decode("base64"), f.read()) self.assertEqual(dbf.content_type, 'image/jpeg') - @override_settings( - DEFAULT_FILE_STORAGE="dbfilestorage.storage.DBStorage") def test_open(self): """ Test that the storage mechanism can upload """ name = self._upload() + dbf = default_storage.open(name) with open(self.filepath, 'rb') as f: self.assertEqual(dbf.read(), f.read()) - @override_settings( - DEFAULT_FILE_STORAGE="dbfilestorage.storage.DBStorage") def test_exists(self): """ Test that the storage mechanism can check existance """ name = self._upload() + self.assertTrue(default_storage.exists(name)) + + def test_delete(self): + """ Test Deletion """ + name = self._upload() + self.assertTrue(DBFile.objects.filter(name=name).exists()) + default_storage.delete(name) + self.assertFalse(DBFile.objects.filter(name=name).exists()) + + def test_path(self): + """ Test the path is just the md5 name """ + name = self._upload() + path = default_storage.path(name) + self.assertEqual(name, path) + self.assertNotIn(self.filename, path) + + def test_size(self): + """ Ensure we can get the proper size """ + name = self._upload() + size = default_storage.size(name) + self.assertGreater(size, 0) + + def test_url(self): + """ Test that the url returned is the md5 path not the filename """ + name = self._upload() + self.assertIn(self.md5, default_storage.url(name)) + + def test_view(self): + client = Client() + name = self._upload() + url = default_storage.url(name) + resp = client.get(url) + self.assertEqual(resp.status_code, 200)