Release version 0.0.4 (#7)
* Setup for Coverage and Codcov.io (#6) * add pip install command (#8) * More tests (#9) * Update Version number
This commit is contained in:
parent
33d22038e6
commit
b77b8d5504
13
.coveragerc
Normal file
13
.coveragerc
Normal file
|
@ -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/*
|
|
@ -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 = (
|
||||
|
|
|
@ -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<name>.*)$', views.show_file, name="dbstorage_file"),
|
||||
)
|
||||
]
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
Django==1.10.4
|
||||
Sphinx==1.5
|
||||
coverage==4.2
|
||||
|
|
8
setup.cfg
Normal file
8
setup.cfg
Normal file
|
@ -0,0 +1,8 @@
|
|||
[nosetests]
|
||||
verbosity=1
|
||||
detailed-errors=1
|
||||
with-coverage=1
|
||||
cover-package=dbfilestorage
|
||||
#pdb=1
|
||||
#pdb-failures=1
|
||||
|
2
setup.py
2
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",
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user