Skip to content

Commit 4bae06b

Browse files
committed
BOM-1028
Adding tox for django20,21,22 Added constraint for boto. fixing all quality issues. added the twine check as suggested
1 parent 8d2ffeb commit 4bae06b

23 files changed

+822
-105
lines changed

.travis.yml

+18-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,26 @@ python:
55
- 3.5
66

77
env:
8-
- TOXENV=django18
9-
- TOXENV=django19
10-
- TOXENV=django110
118
- TOXENV=django111
9+
- TOXENV=django20
10+
- TOXENV=django21
11+
- TOXENV=django22
1212

1313
sudo: false
1414

15+
matrix:
16+
exclude:
17+
- python: 2.7
18+
env: TOXENV=django20
19+
- python: 2.7
20+
env: TOXENV=django21
21+
- python: 2.7
22+
env: TOXENV=django22
23+
24+
include:
25+
- python: 3.5
26+
env: TOXENV=quality
27+
1528
install:
1629
- pip install -r requirements/travis.txt
1730

@@ -30,3 +43,5 @@ deploy:
3043
on:
3144
tags: true
3245
all_branches: true
46+
python: 3.5
47+
condition: '$TOXENV = quality'

Makefile

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ test: clean ## run tests in the current virtualenv
2626
test-all: ## run tests on every supported Python/Django combination
2727
tox
2828

29+
quality: ## Run Quality checks
30+
tox -e quality
31+
32+
2933
upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in
3034
pip install -q pip-tools
31-
pip-compile --upgrade -o requirements/dev.txt requirements/base.in requirements/dev.in
32-
pip-compile --upgrade -o requirements/test.txt requirements/base.in requirements/test.in
33-
pip-compile --upgrade -o requirements/travis.txt requirements/travis.in
35+
pip-compile --rebuild --upgrade -o requirements/dev.txt requirements/base.in requirements/dev.in
36+
pip-compile --rebuild --upgrade -o requirements/test.txt requirements/base.in requirements/test.in
37+
pip-compile --rebuild --upgrade -o requirements/travis.txt requirements/travis.in
38+
pip-compile --rebuild --upgrade -o requirements/quality.txt requirements/quality.in
3439
# Let tox control the django version for tests
3540
sed '/^django==/d' requirements/test.txt > requirements/test.tmp
3641
mv requirements/test.tmp requirements/test.txt

djpyfs/djpyfs.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
3) The ability to create objects with a limited lifetime. A
99
task can garbage-collect those objects.
1010
"""
11+
# pylint: disable=W6100
1112

1213
from __future__ import absolute_import
1314

@@ -20,7 +21,6 @@
2021
from fs.osfs import OSFS
2122
from fs_s3fs import S3FS
2223

23-
2424
if hasattr(settings, 'DJFS'):
2525
DJFS_SETTINGS = settings.DJFS # pragma: no cover
2626
else:
@@ -79,7 +79,8 @@ def patch_fs(fs, namespace, url_method):
7979
Returns:
8080
obj: Patched filesystem instance
8181
"""
82-
def expire(self, filename, seconds, days=0, expires=True):
82+
83+
def expire(self, filename, seconds, days=0, expires=True): # pylint: disable=unused-argument
8384
"""
8485
Set the lifespan of a file on the filesystem.
8586
@@ -135,7 +136,7 @@ def get_s3fs(namespace):
135136
fullpath = os.path.join(DJFS_SETTINGS['prefix'], fullpath)
136137
s3fs = S3FS(DJFS_SETTINGS['bucket'], fullpath, aws_secret_access_key=key_id, aws_access_key_id=key_secret)
137138

138-
def get_s3_url(self, filename, timeout=60):
139+
def get_s3_url(self, filename, timeout=60): # pylint: disable=unused-argument
139140
"""
140141
Patch method to returns a signed S3 url for the given filename
141142

djpyfs/models.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
"""
2+
Database models for django-pyfs
3+
"""
4+
# pylint: disable=W6100
15
import os
26

37
from django.db import models
48
from django.utils import timezone
9+
from django.utils.encoding import python_2_unicode_compatible
510

611

12+
@python_2_unicode_compatible
713
class FSExpirations(models.Model):
814
"""
915
Model to handle expiring temporary files.
@@ -72,7 +78,7 @@ class Meta(object):
7278
]
7379

7480
def __str__(self):
75-
if self.expires:
76-
return "{} Expires {}".format(os.path.join(self.module, self.filename), str(self.expiration))
81+
if self.expires:
82+
return u"{} Expires {}".format(os.path.join(self.module, self.filename), str(self.expiration))
7783
else:
78-
return "{} Permanent ({})".format(os.path.join(self.module, self.filename), str(self.expiration))
84+
return u"{} Permanent ({})".format(os.path.join(self.module, self.filename), str(self.expiration))

djpyfs/tests.py

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
"""
2+
Database models for django-pyfs
3+
"""
4+
15
from __future__ import absolute_import, unicode_literals
2-
import six
36

4-
import shutil
57
import os
8+
import shutil
69
import sys
710
import unittest
8-
from io import StringIO
911

1012
import boto
1113
import mock
14+
import six
1215
from django.test import TestCase
1316
from django.utils import timezone
1417
from fs.memoryfs import MemoryFS
@@ -19,7 +22,9 @@
1922

2023

2124
class FSExpirationsTest(TestCase):
25+
""" Tests for FSExpirations"""
2226
def setUp(self):
27+
super(FSExpirationsTest, self).setUp()
2328
self.fs = MemoryFS()
2429
self.test_file_path = '/foo/bar'
2530
self.expires = True
@@ -29,6 +34,7 @@ def setUp(self):
2934
self.module = "unittest"
3035

3136
def tearDown(self):
37+
super(FSExpirationsTest, self).tearDown()
3238
self.fs.close()
3339

3440
def test_create_expiration_exists(self):
@@ -105,14 +111,17 @@ def test_str(self):
105111
try:
106112
result = f.__str__()
107113
self.assertTrue(isinstance(result, six.string_types))
108-
except Exception as e:
114+
except Exception as e: # pylint: disable=broad-except
109115
self.fail("__str__ raised an exception! {}".format(e))
110116

111117

118+
# pylint: disable=literal-used-as-attribute
112119
class _BaseFs(TestCase):
120+
"""Tests for BaseFs"""
113121
djfs_settings = None
114122

115123
def setUp(self):
124+
super(_BaseFs, self).setUp()
116125
if self.djfs_settings is None:
117126
raise unittest.SkipTest("Skipping test on base class.")
118127

@@ -143,6 +152,7 @@ def setUp(self):
143152

144153
def tearDown(self):
145154
# Restore original settings
155+
super(_BaseFs, self).tearDown()
146156
djpyfs.DJFS_SETTINGS = self.orig_djpyfs_settings
147157

148158
def test_get_filesystem(self):
@@ -152,6 +162,7 @@ def test_get_filesystem(self):
152162
fs.getinfo(self.test_dir_name)
153163
fs.removedir(self.test_dir_name)
154164

165+
# pylint: disable=no-member
155166
def test_expire_objects(self):
156167
expire_secs = 0
157168
expire_days = 0
@@ -166,7 +177,7 @@ def test_expire_objects(self):
166177
for curr_fs in (fs1, fs2):
167178
curr_fs.makedir(self.test_dir_name)
168179

169-
foo = 'foo'
180+
foo = 'foo' # pylint: disable=blacklisted-name
170181
curr_fs.settext(self.relative_path_to_test_file, foo, 'utf-8', 'strict')
171182
curr_fs.settext(self.relative_path_to_secondary_test_file, foo, 'utf-8', 'strict')
172183

@@ -217,10 +228,11 @@ def test_patch_fs(self):
217228
Simple check to make sure the filesystem is patched as expected.
218229
"""
219230
fs = djpyfs.get_filesystem(self.namespace)
220-
self.assertTrue(callable(getattr(fs, 'expire')))
221-
self.assertTrue(callable(getattr(fs, 'get_url')))
231+
self.assertTrue(callable(getattr(fs, 'expire'))) # pylint: disable=literal-used-as-attribute
232+
self.assertTrue(callable(getattr(fs, 'get_url'))) # pylint: disable=literal-used-as-attribute
222233

223234

235+
# pylint: disable=test-inherits-tests; literal-used-as-attribute
224236
class BadFileSystemTestInh(_BaseFs):
225237
"""
226238
Test filesystem class that uses an unknown filesystem type to make sure all
@@ -253,6 +265,7 @@ def test_patch_fs(self):
253265
super(BadFileSystemTestInh, self).test_patch_fs()
254266

255267

268+
# pylint: disable=test-inherits-tests
256269
class OsfsTest(_BaseFs):
257270
"""
258271
Tests the OSFS implementation.
@@ -277,6 +290,7 @@ def tearDown(self):
277290
self._cleanDirs()
278291

279292

293+
# pylint: disable=test-inherits-tests
280294
class S3Test(_BaseFs):
281295
"""
282296
Tests the S3FS implementation, without a prefix.
@@ -307,6 +321,8 @@ def setUp(self):
307321
self._setUpS3()
308322

309323
def _setUpS3(self):
324+
"""setup class"""
325+
310326
# Start mocking S3
311327
self.mock_s3 = mock_s3()
312328
self.mock_s3.start()
@@ -330,6 +346,7 @@ def tearDown(self):
330346
super(S3Test, self).tearDown()
331347

332348

349+
# pylint: disable=test-inherits-tests
333350
class S3TestPrefix(S3Test):
334351
"""
335352
Same as S3Test above, but includes a prefix.

example/example/settings.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Django settings for example project.
22

3-
## CHANGED
4-
DJFS = {'type' : 'osfs',
5-
'directory_root' : 'sample/static/djpyfs',
6-
'url_root' : '/static/djpyfs'}
7-
## /CHANGED
3+
# CHANGED
4+
DJFS = {'type': 'osfs',
5+
'directory_root': 'sample/static/djpyfs',
6+
'url_root': '/static/djpyfs'}
7+
# /CHANGED
88

99
DEBUG = True
1010
TEMPLATE_DEBUG = DEBUG
@@ -17,12 +17,12 @@
1717

1818
DATABASES = {
1919
'default': {
20-
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
21-
'NAME': 'db.sql', # Or path to database file if using sqlite3.
22-
'USER': '', # Not used with sqlite3.
23-
'PASSWORD': '', # Not used with sqlite3.
24-
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
25-
'PORT': '', # Set to empty string for default. Not used with sqlite3.
20+
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
21+
'NAME': 'db.sql', # Or path to database file if using sqlite3.
22+
'USER': '', # Not used with sqlite3.
23+
'PASSWORD': '', # Not used with sqlite3.
24+
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
25+
'PORT': '', # Set to empty string for default. Not used with sqlite3.
2626
}
2727
}
2828

@@ -84,7 +84,7 @@
8484
STATICFILES_FINDERS = (
8585
'django.contrib.staticfiles.finders.FileSystemFinder',
8686
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
87-
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
87+
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
8888
)
8989

9090
# Make this unique, and don't share it with anybody.
@@ -94,10 +94,10 @@
9494
TEMPLATE_LOADERS = (
9595
'django.template.loaders.filesystem.Loader',
9696
'django.template.loaders.app_directories.Loader',
97-
# 'django.template.loaders.eggs.Loader',
97+
# 'django.template.loaders.eggs.Loader',
9898
)
9999

100-
MIDDLEWARE_CLASSES = (
100+
MIDDLEWARE = (
101101
'django.middleware.common.CommonMiddleware',
102102
'django.contrib.sessions.middleware.SessionMiddleware',
103103
'django.middleware.csrf.CsrfViewMiddleware',
@@ -125,7 +125,7 @@
125125
'django.contrib.sites',
126126
'django.contrib.messages',
127127
'django.contrib.staticfiles',
128-
'djpyfs', ## <-- CHANGED
128+
'djpyfs', ## <-- CHANGED
129129
'sample',
130130
# Uncomment the next line to enable the admin:
131131
# 'django.contrib.admin',

example/sample/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.http import HttpResponse
55
from djpyfs import djpyfs
66

7-
arrow = ["11011",
7+
arrow = ["11011",
88
"10001",
99
"00000",
1010
"11011",

0 commit comments

Comments
 (0)