Skip to content

Commit

Permalink
Fix PEP8 issues in tests except line length
Browse files Browse the repository at this point in the history
  • Loading branch information
karenc committed Oct 13, 2015
1 parent a82ca4d commit 63e4109
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 26 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ before_script:
- sudo -u postgres createdb -O cnxarchive cnxarchive-testing
- pip install pep8
- pep8 --exclude=tests *.py cnxpublishing/
- pep8 --max-line-length=200 cnxpublishing/tests
env:
- TESTING_CONFIG="testing.ini"
script:
Expand Down
24 changes: 12 additions & 12 deletions cnxpublishing/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ def test_licensor_additions(self, cursor):

# Create existing licensor records.
values = [
(uuid_, 'charrose', True), ##(uuid_, 'frahablar', None),
(uuid_, 'charrose', True), # (uuid_, 'frahablar', None),
(uuid_, 'impicky', True), (uuid_, 'marknewlyn', True),
(uuid_, 'ream', True), ##(uuid_, 'rings', None),
(uuid_, 'ream', True), # (uuid_, 'rings', None),
]
serial_values = []
for v in values:
Expand Down Expand Up @@ -413,12 +413,12 @@ def test_role_additions(self, cursor):
values = [
(uuid_, 'charrose', 'Author', True),
(uuid_, 'frahablar', 'Translator', True),
##(uuid_, 'frahablar', 'Illustrator', None),
# (uuid_, 'frahablar', 'Illustrator', None),
(uuid_, 'impicky', 'Editor', True),
(uuid_, 'marknewlyn', 'Author', True),
(uuid_, 'ream', 'Copyright Holder', True),
(uuid_, 'ream', 'Publisher', True),
##(uuid_, 'rings', 'Publisher', None),
# (uuid_, 'rings', 'Publisher', None),
]
serial_values = []
for v in values:
Expand Down Expand Up @@ -559,7 +559,7 @@ def test_mixed_update(self, cursor):
values = [
(uuid_, 'charrose', 'Author', None),
(uuid_, 'frahablar', 'Translator', None),
##(uuid_, 'frahablar', 'Illustrator', None),
# (uuid_, 'frahablar', 'Illustrator', None),
(uuid_, 'impicky', 'Editor', True),
(uuid_, 'marknewlyn', 'Author', True),
(uuid_, 'ream', 'Copyright Holder', True),
Expand Down Expand Up @@ -703,7 +703,7 @@ class DatabaseIntegrationTestCase(BaseDatabaseIntegrationTestCase):
def test_add_duplicate_pending_resources(self):
"""Add duplicate pending resources to the database"""
resource = cnxepub.Resource('a.txt', io.BytesIO('hello world\n'),
'text/plain')
'text/plain')

from ..db import add_pending_resource
with psycopg2.connect(self.db_conn_str) as db_conn:
Expand All @@ -716,9 +716,9 @@ def test_add_duplicate_pending_resources(self):
self.assertEqual(cursor.fetchone()[0], 1)

self.assertEqual(resource.hash,
'22596363b3de40b06f981fb85d82312e8c0ed511')
'22596363b3de40b06f981fb85d82312e8c0ed511')
self.assertEqual(resource.id,
'22596363b3de40b06f981fb85d82312e8c0ed511')
'22596363b3de40b06f981fb85d82312e8c0ed511')

def test_add_new_pending_document(self):
"""Add a pending document to the database."""
Expand Down Expand Up @@ -892,12 +892,12 @@ def test_add_pending_document_wo_permission(self, cursor):
INSERT INTO document_acl (uuid, user_id, permission)
VALUES ((SELECT uuid from control_insert), 'ream', 'publish'::permission_type)
""",
(document_id,))
(document_id,))

# Create and add a document for the publication.
metadata = {'authors': [{'id': 'able', 'type': 'cnx-id'}],
'publishers': [{'id': 'able', 'type': 'cnx-id'}],
'cnx-archive-uri': 'http://cnx.org/contents/{}' \
'cnx-archive-uri': 'http://cnx.org/contents/{}'
.format(document_id),
}
document = self.make_document(metadata=metadata)
Expand Down Expand Up @@ -1378,7 +1378,7 @@ def test_12_valid_derived_from_uri(self, cursor):
INSERT INTO modules
(module_ident, portal_type, moduleid, uuid, name,
major_version, minor_version,
created, revised, abstractid, licenseid,
created, revised, abstractid, licenseid,
doctype, submitter, submitlog, stateid, parent, parentauthors,
language, authors, maintainers, licensors,
google_analytics, buylink)
Expand Down Expand Up @@ -1425,7 +1425,7 @@ def test_12_derived_from_uri_not_found(self, cursor):
"""
# Create a Document model.
invalid_derived_from_uri = \
u"http://cnx.org/contents/b07fd622-a2f1-4ccb-967c-9b966935961f"
u"http://cnx.org/contents/b07fd622-a2f1-4ccb-967c-9b966935961f"
metadata = {u'derived_from_uri': invalid_derived_from_uri}
model = self.make_document(metadata=metadata)

Expand Down
3 changes: 2 additions & 1 deletion cnxpublishing/tests/test_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .testing import config_uri
from .test_views import BaseFunctionalViewTestCase


class DocTestTestCase(BaseFunctionalViewTestCase):
"""Run all the examples"""

Expand Down Expand Up @@ -52,4 +53,4 @@ def test_readme(self):

doctest.testfile(
'../../README.rst',
optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE)
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
10 changes: 5 additions & 5 deletions cnxpublishing/tests/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_document_insertion_wo_id_n_version(self):
# XXX We don't have a mapping.
'publishers': [{'id': 'ream', 'type': None}],
'authors': [{'id': 'rbates', 'type': 'cnx-id',
'name': 'Richard Bates'},],
'name': 'Richard Bates'}],
'editors': [{'id': 'jone', 'type': None},
{'id': 'kahn', 'type': None}],
# XXX We don't have a mapping.
Expand Down Expand Up @@ -288,7 +288,7 @@ def test_document_insertion_w_id_n_version_provided(self):
# XXX We don't have a mapping.
'publishers': [{'id': 'ream', 'type': None}],
'authors': [{'id': 'rbates', 'type': 'cnx-id',
'name': 'Richard Bates'},],
'name': 'Richard Bates'}],
'editors': [{'id': 'jone', 'type': None},
{'id': 'kahn', 'type': None}],
# XXX We don't have a mapping.
Expand Down Expand Up @@ -340,7 +340,7 @@ def test_document_w_derived_from(self):
'license_url': 'http://creativecommons.org/licenses/by/3.0/',
'publishers': [{'id': 'ream', 'type': None}], # XXX We don't have a mapping.
'authors': [{'id': 'rbates', 'type': 'cnx-id',
'name': 'Richard Bates'},],
'name': 'Richard Bates'}],
'editors': [{'id': 'jone', 'type': None}, {'id': 'kahn', 'type': None}],
'illustrators': [{'id': 'AbagaleBates', 'type': None}], # XXX We don't have a mapping.
'translators': [{'id': 'RhowandaOkofarBates', 'type': None},
Expand Down Expand Up @@ -371,7 +371,7 @@ def test_document_w_derived_from(self):
'license_url': 'http://creativecommons.org/licenses/by/3.0/',
'publishers': [{'id': 'someone', 'type': None}], # XXX We don't have a mapping.
'authors': [{'id': 'someone', 'type': 'cnx-id',
'name': 'Someone'},],
'name': 'Someone'}],
'editors': [],
'illustrators': [], # XXX We don't have a mapping.
'translators': [],
Expand All @@ -389,7 +389,7 @@ def test_document_w_derived_from(self):
with self.db_connect() as db_conn:
with db_conn.cursor() as cursor:
derived_ident_hash = _insert_metadata(cursor, document,
publisher, message)[1]
publisher, message)[1]

self.assertNotEqual(derived_ident_hash.split('@')[0], ident_hash.split('@')[0])
with self.db_connect() as db_conn:
Expand Down
8 changes: 3 additions & 5 deletions cnxpublishing/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def copy(self, src, dst_name='book'):
class BaseFunctionalViewTestCase(unittest.TestCase, EPUBMixInTestCase):
"""Request/response client interactions"""


settings = None
db_conn_str = None
db_connect = None
Expand All @@ -119,7 +118,7 @@ def api_keys_by_uid(self):
from ..main import _parse_api_key_lines
api_keys = _parse_api_key_lines(self.settings)
setattr(self, attr_name, api_keys)
return {x[1]:x[0] for x in api_keys}
return {x[1]: x[0] for x in api_keys}

def gen_api_key_headers(self, user):
"""Generate authentication headers for the given user."""
Expand Down Expand Up @@ -347,7 +346,7 @@ def test_roles_request(self, cursor):
" last_name IS NOT NULL, "
" full_name IS NOT NULL] "
"FROM users ORDER BY username")
users = {u:set(b) for u, b in cursor.fetchall()}
users = {u: set(b) for u, b in cursor.fetchall()}
self.assertEqual(users.keys(), sorted([x['uid'] for x in data]))
for username, null_checks in users.items():
self.assertNotIn(None, null_checks,
Expand Down Expand Up @@ -581,7 +580,6 @@ def test_create_identifier_on_acl_request(self):
resp = self.app.get(path, headers=headers)
self.assertEqual(resp.json, expected)


def test_create_identifier_for_all_routes(self):
"""Tests that creating an identifier result in non-404
on other routes. See also,
Expand Down Expand Up @@ -873,7 +871,7 @@ def test_new_to_publication(self):
" last_name IS NOT NULL, "
" full_name IS NOT NULL] "
"FROM users ORDER BY username")
users = {u:set(b) for u, b in cursor.fetchall()}
users = {u: set(b) for u, b in cursor.fetchall()}
self.assertEqual(sorted(users.keys()), sorted(uids))
for username, null_checks in users.items():
self.assertNotIn(None, null_checks,
Expand Down
1 change: 1 addition & 0 deletions cnxpublishing/tests/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
here = os.path.abspath(os.path.dirname(__file__))
TEST_DATA_DIR = os.path.join(here, 'data')


def config_uri():
"""Return the file path of the testing config uri"""
config_uri = os.environ.get('TESTING_CONFIG', None)
Expand Down
6 changes: 3 additions & 3 deletions cnxpublishing/tests/use_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def _read_file(filepath, mode='rb'):
u'authors': [{u'id': u'butcher',
u'name': u'James Doakes',
u'type': u'cnx-id'},
],
],
u'copyright_holders': [
{u'id': u'ream',
u'name': u'Ream',
Expand Down Expand Up @@ -395,7 +395,7 @@ def _read_file(filepath, mode='rb'):
u'authors': [{u'id': u'charrose',
u'name': u'Charmaine St. Rose',
u'type': u'cnx-id'},
],
],
u'copyright_holders': [
{u'id': u'ream',
u'name': u'Ream',
Expand Down Expand Up @@ -791,7 +791,7 @@ def setup_BOOK_in_archive(test_case, cursor):
_insert_user_info(binder, cursor)
publish_model(cursor, binder, publisher, publication_message)
_set_uri(binder)
_insert_acl_for_model(binder,cursor)
_insert_acl_for_model(binder, cursor)
return binder


Expand Down

0 comments on commit 63e4109

Please sign in to comment.