Skip to content

Commit

Permalink
Make flake8 check mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Jan 10, 2019
1 parent 24642e3 commit bf5ad31
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 50 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,3 @@ matrix:
env: TOXENV=py34
- python: "3.6"
env: TOXENV=flake8
allow_failures:
- python: "3.6"
env: TOXENV=flake8
2 changes: 1 addition & 1 deletion agentarchives/archivesspace/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .client import *
from .client import * # noqa
8 changes: 3 additions & 5 deletions agentarchives/archivesspace/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,9 @@ def edit_record(self, new_record):

self._post(record_id, data=json.dumps(record))


def get_levels_of_description(self):
"""
Returns an array of all levels of description defined in this ArchivesSpace instance.
"""
"""Returns an array of all levels of description defined in this
ArchivesSpace instance."""
if not hasattr(self, 'levels_of_description'):
# TODO: * fetch human-formatted strings
# * is hardcoding this ID okay?
Expand Down Expand Up @@ -752,7 +750,7 @@ def add_digital_object(self, parent_archival_object, identifier, title=None, uri
"xlink_actuate_attribute": xlink_actuate,
}]

note_digital_object_type = ["summary", "bioghist", "accessrestrict", "userestrict", "custodhist", "dimensions", "edition", "extent","altformavail", "originalsloc", "note", "acqinfo", "inscription", "langmaterial", "legalstatus", "physdesc", "prefercite", "processinfo", "relatedmaterial"]
note_digital_object_type = ["summary", "bioghist", "accessrestrict", "userestrict", "custodhist", "dimensions", "edition", "extent", "altformavail", "originalsloc", "note", "acqinfo", "inscription", "langmaterial", "legalstatus", "physdesc", "prefercite", "processinfo", "relatedmaterial", ]

if inherit_notes:
for pnote in parent_record["notes"]:
Expand Down
2 changes: 1 addition & 1 deletion agentarchives/archivists_toolkit/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .client import *
from .client import * # noqa
30 changes: 15 additions & 15 deletions agentarchives/archivists_toolkit/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def get_resource_component_and_children(self, resource_id, resource_type='collec
# can use it to share state during recursion

recurse_max_level = kwargs.get('recurse_max_level', False)
query = kwargs.get('search_pattern', '')
query = kwargs.get('search_pattern', '')

# intialize sort position if this is the beginning of recursion
if level == 1:
Expand All @@ -237,26 +237,26 @@ def get_resource_component_and_children(self, resource_id, resource_type='collec
cursor.execute("SELECT title, dateExpression, resourceIdentifier1, resourceLevel FROM Resources WHERE resourceid=%s", (resource_id))

for row in cursor.fetchall():
resource_data['id'] = resource_id
resource_data['type'] = 'resource'
resource_data['sortPosition'] = sort_data['position']
resource_data['title'] = row[0]
resource_data['id'] = resource_id
resource_data['type'] = 'resource'
resource_data['sortPosition'] = sort_data['position']
resource_data['title'] = row[0]
# TODO reformat dates from the separate date fields, like ArchivesSpaceClient?
resource_data['dates'] = row[1]
resource_data['date_expression'] = row[1]
resource_data['identifier'] = row[2]
resource_data['dates'] = row[1]
resource_data['date_expression'] = row[1]
resource_data['identifier'] = row[2]
resource_data['levelOfDescription'] = row[3]
else:
cursor.execute("SELECT title, dateExpression, persistentID, resourceLevel FROM ResourcesComponents WHERE resourceComponentId=%s", (resource_id))

for row in cursor.fetchall():
resource_data['id'] = resource_id
resource_data['type'] = 'resource_component'
resource_data['sortPosition'] = sort_data['position']
resource_data['title'] = row[0]
resource_data['dates'] = row[1]
resource_data['date_expression'] = row[1]
resource_data['identifier'] = row[2]
resource_data['id'] = resource_id
resource_data['type'] = 'resource_component'
resource_data['sortPosition'] = sort_data['position']
resource_data['title'] = row[0]
resource_data['dates'] = row[1]
resource_data['date_expression'] = row[1]
resource_data['identifier'] = row[2]
resource_data['levelOfDescription'] = row[3]

# fetch children if we haven't reached the maximum recursion level
Expand Down
2 changes: 1 addition & 1 deletion agentarchives/atom/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .client import *
from .client import * # noqa
12 changes: 5 additions & 7 deletions agentarchives/atom/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ def get_record(self, record_id):

def _format_date_from_atom(self, date):
# Map AtoM date specification to generic
updated_date = {}

date_mapping = {
'start_date': 'begin',
'end_date': 'end',
Expand Down Expand Up @@ -200,7 +198,7 @@ def edit_record(self, new_record):
# within that note.
# If the record already has at least one note, then replace the first note
# within that record with this one.
if not 'notes' in record or record['notes'] == []:
if 'notes' not in record or record['notes'] == []:
record['notes'] = [new_note]
else:
record['notes'][0] = new_note
Expand All @@ -222,9 +220,9 @@ def edit_record(self, new_record):
# Map agentarchives date specification to AtoM specification
date_mapping = {
'start_date': 'start_date',
#'begin': 'start_date',
# 'begin': 'start_date',
'end_date': 'end_date',
#'end': 'end_date',
# 'end': 'end_date',
'date_expression': 'date'
}

Expand Down Expand Up @@ -539,8 +537,8 @@ def augment_resource_ids(self, resource_ids):
"""
resources_augmented = []
for id in resource_ids:
#resource_data = self.get_resource_component_and_children(id, recurse_max_level=2)
#resources_augmented.append(resource_data)
# resource_data = self.get_resource_component_and_children(id, recurse_max_level=2)
# resources_augmented.append(resource_data)
resources_augmented.append(
self.get_resource_component_and_children(id, recurse_max_level=2)
)
Expand Down
Empty file added tests/__init__.py
Empty file.
22 changes: 18 additions & 4 deletions tests/test_archivesspace_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
import os

import collections
import sys

import pytest
import vcr

here = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, here)

from agentarchives.archivesspace.client import ArchivesSpaceClient, ArchivesSpaceError, CommunicationError


THIS_DIR = os.path.dirname(os.path.abspath(__file__))
AUTH = {
'host': 'http://localhost:8089',
Expand Down Expand Up @@ -215,6 +212,7 @@ def test_find_collection_ids_search():
ids = client.find_collection_ids(search_pattern='Some')
assert ids == ['/repositories/2/resources/2']


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_count_collection_ids.yaml'))
def test_count_collection_ids():
client = ArchivesSpaceClient(**AUTH)
Expand All @@ -228,6 +226,7 @@ def test_count_collection_ids_search():
ids = client.count_collections(search_pattern='Some')
assert ids == 1


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_find_by_id_refid.yaml'))
def test_find_by_id_refid():
client = ArchivesSpaceClient(**AUTH)
Expand All @@ -240,6 +239,7 @@ def test_find_by_id_refid():
assert item['title'] == 'Test AO'
assert item['levelOfDescription'] == 'file'


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_augment_ids.yaml'))
def test_augment_ids():
client = ArchivesSpaceClient(**AUTH)
Expand All @@ -250,25 +250,29 @@ def test_augment_ids():
assert data[1]['title'] == 'Some other fonds'
assert data[1]['type'] == 'resource'


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_resource_type.yaml'))
def test_get_resource_type():
client = ArchivesSpaceClient(**AUTH)
assert client.resource_type('/repositories/2/resources/2') == 'resource'
assert client.resource_type('/repositories/2/archival_objects/3') == 'resource_component'


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_resource_type.yaml'))
def test_get_resource_type_raises_on_invalid_input():
client = ArchivesSpaceClient(**AUTH)
with pytest.raises(ArchivesSpaceError):
client.resource_type('invalid')


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_identifier_exact_match.yaml'))
def test_identifier_search_exact_match():
client = ArchivesSpaceClient(**AUTH)
assert client.find_collection_ids(identifier='F1') == ['/repositories/2/resources/1']
assert client.count_collections(identifier='F1') == 1
assert len(client.find_collections(identifier='F1')) == 1


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_identifier_wildcard.yaml'))
def test_identifier_search_wildcard():
client = ArchivesSpaceClient(**AUTH)
Expand All @@ -281,18 +285,21 @@ def test_identifier_search_wildcard():
assert client.count_collections(identifier='F*') == 2
assert len(client.find_collections(identifier='F*')) == 2


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_add_child_resource.yaml'))
def test_add_child_resource():
client = ArchivesSpaceClient(**AUTH)
uri = client.add_child('/repositories/2/resources/2', title='Test child', level='item')
assert uri == '/repositories/2/archival_objects/3'


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_add_child_resource_component.yaml'))
def test_add_child_resource_component():
client = ArchivesSpaceClient(**AUTH)
uri = client.add_child('/repositories/2/archival_objects/1', title='Test child', level='item')
assert uri == '/repositories/2/archival_objects/5'


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_adding_child_with_note.yaml'))
def test_adding_child_with_note():
client = ArchivesSpaceClient(**AUTH)
Expand All @@ -302,6 +309,7 @@ def test_adding_child_with_note():
notes=[{'type': 'odd', 'content': 'This is a test note'}])
assert uri == '/repositories/2/archival_objects/24'


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_posting_contentless_note.yaml'))
def test_posting_contentless_note():
client = ArchivesSpaceClient(**AUTH)
Expand All @@ -311,6 +319,7 @@ def test_posting_contentless_note():
notes=[{'type': 'odd', 'content': ''}])
assert client.get_record(uri)['notes'] == []


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_posting_multiple_notes.yaml'))
def test_posting_multiple_notes():
client = ArchivesSpaceClient(**AUTH)
Expand All @@ -324,6 +333,7 @@ def test_posting_multiple_notes():
assert record['notes'][1]['type'] == 'accessrestrict'
assert record['notes'][1]['subnotes'][0]['content'] == 'Access'


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_delete_record_resource.yaml'))
def test_delete_record_resource():
client = ArchivesSpaceClient(**AUTH)
Expand All @@ -334,6 +344,7 @@ def test_delete_record_resource():
with pytest.raises(CommunicationError):
client.get_record(record_id)


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_delete_record_archival_object.yaml'))
def test_delete_record_archival_object():
client = ArchivesSpaceClient(**AUTH)
Expand All @@ -344,6 +355,7 @@ def test_delete_record_archival_object():
with pytest.raises(CommunicationError):
client.get_record(record_id)


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_edit_archival_object.yaml'))
def test_edit_archival_object():
client = ArchivesSpaceClient(**AUTH)
Expand Down Expand Up @@ -392,6 +404,7 @@ def test_edit_record_empty_note():
updated = client.get_record('/repositories/2/archival_objects/3')
assert not updated['notes']


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_edit_record_multiple_notes.yaml'))
def test_edit_record_multiple_notes():
client = ArchivesSpaceClient(**AUTH)
Expand All @@ -416,6 +429,7 @@ def test_edit_record_multiple_notes():
assert updated['notes'][1]['type'] == new_record['notes'][1]['type']
assert updated['notes'][1]['subnotes'][0]['content'] == new_record['notes'][1]['content']


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures', 'test_add_digital_object.yaml'))
def test_add_digital_object():
client = ArchivesSpaceClient(**AUTH)
Expand Down
22 changes: 9 additions & 13 deletions tests/test_atom_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
import os

import pytest
import sys
import vcr

here = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, here)

from agentarchives.atom.client import AtomClient, AtomError, CommunicationError
from agentarchives.atom.client import AtomClient, CommunicationError

THIS_DIR = os.path.dirname(os.path.abspath(__file__))
AUTH = {
Expand All @@ -21,7 +17,7 @@
def test_levels_of_description():
client = AtomClient(**AUTH)
levels = client.get_levels_of_description()
assert levels == [u'Collection', u'File', u'Fonds', u'Item', u'Part', u'Series', u'Subfonds', u'Subseries']
assert levels == [u'Collection', u'File', u'Fonds', u'Item', u'Part', u'Series', u'Subfonds', u'Subseries']


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures/atom', 'test_listing_collections.yaml'))
Expand Down Expand Up @@ -125,7 +121,7 @@ def test_find_resource_children_recursion_level():
assert data['has_children'] is True


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures/atom', 'test_find_resource_children_recursion_level_two.yaml'))
@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures/atom', 'test_find_resource_children_recursion_level_two.yaml')) # noqa
def test_find_resource_children_recursion_level():
client = AtomClient(**AUTH)
data = client.get_resource_component_and_children('test-fonds',
Expand Down Expand Up @@ -208,19 +204,19 @@ def test_add_child_resource_component():
def test_adding_child_with_note():
client = AtomClient(**AUTH)
slug = client.add_child('test-fonds',
title='Another subfonds',
level='subfonds',
notes=[{'type': 'general', 'content': 'This is a test note'}])
title='Another subfonds',
level='subfonds',
notes=[{'type': 'general', 'content': 'This is a test note'}])
assert slug == 'another-subfonds'


@vcr.use_cassette(os.path.join(THIS_DIR, 'fixtures/atom', 'test_posting_contentless_note.yaml'))
def test_posting_contentless_note():
client = AtomClient(**AUTH)
slug = client.add_child('test-fonds',
title='Yet another subfonds',
level='subfonds',
notes=[{'type': 'general', 'content': ''}])
title='Yet another subfonds',
level='subfonds',
notes=[{'type': 'general', 'content': ''}])
assert client.get_record(slug)['notes'] == []


Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ commands = flake8 .
[flake8]
exclude = .env, .tox, .git, __pycache__, .cache, build, dist, *.pyc, *.egg-info, .eggs
application-import-names = flake8
ignore = E501

0 comments on commit bf5ad31

Please sign in to comment.