Skip to content

Commit

Permalink
Merge pull request #3258 from cclauss/tabs
Browse files Browse the repository at this point in the history
Fix indentation in two Python files
  • Loading branch information
cdrini committed Mar 24, 2020
2 parents 4da77dd + d0ca4cb commit eae8c7e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 51 deletions.
65 changes: 33 additions & 32 deletions openlibrary/solr/solrdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
xwork document:
A dictionary contains all information about a work. It contains the following fields.
A dictionary contains all information about a work. It contains the following
fields.
work - The work document
editions - The list of edition documents belong to the work
authors - The list of authors of this work
ia - dictionary of ia metadata of all ia-ids referenced in the editions
duplicates - dict of duplicates mapping for key to all it's duplicates
work - The work document
editions - The list of edition documents belong to the work
authors - The list of authors of this work
ia - dictionary of ia metadata of all ia-ids referenced in the editions
duplicates - dict of duplicates mapping for key to all it's duplicates
solr document:
A dictionary with elements from Solr schema of Open Library. These
documents can be imported to solr after converting to xml.
A dictionary with elements from Solr schema of Open Library. These
documents can be imported to solr after converting to xml.
"""
from __future__ import print_function
import sys
Expand All @@ -27,39 +28,39 @@
from update_work import process_edition_data, process_work_data

def process_xwork(doc):
"""Process xwork document and yield multiple solr documents.
"""
work = doc['work']
editions = doc['editions']
authors = doc['authors']
ia = doc['ia']
"""Process xwork document and yield multiple solr documents.
"""
work = doc['work']
editions = doc['editions']
authors = doc['authors']
ia = doc['ia']

d = dict(work=work, editions=editions, authors=authors, ia=ia, duplicates={})
yield process_work_data(d)
d = dict(work=work, editions=editions, authors=authors, ia=ia, duplicates={})
yield process_work_data(d)

for e in editions:
d = web.storage(edition=e, work=work, authors=authors)
yield process_edition_data(d)
for e in editions:
d = web.storage(edition=e, work=work, authors=authors)
yield process_edition_data(d)

def xopen(path, mode="r"):
if path.endswith(".gz"):
return gzip.open(path, mode)
else:
return open(path, mode)
if path.endswith(".gz"):
return gzip.open(path, mode)
else:
return open(path, mode)

def read_xworks_dump(filename):
for line in xopen(filename):
key, jsontext = line.strip().split("\t")
yield json.loads(jsontext)
for line in xopen(filename):
key, jsontext = line.strip().split("\t")
yield json.loads(jsontext)

def write_solr_dump(docs):
for doc in docs:
print(json.dumps(doc))
for doc in docs:
print(json.dumps(doc))

def main(xworks_filename):
solr_docs = (doc for xwork in read_xworks_dump(xworks_filename)
for doc in process_xwork(xwork))
write_solr_dump(solr_docs)
solr_docs = (doc for xwork in read_xworks_dump(xworks_filename)
for doc in process_xwork(xwork))
write_solr_dump(solr_docs)

if __name__ == '__main__':
main(sys.argv[1])
main(sys.argv[1])
38 changes: 19 additions & 19 deletions openlibrary/tests/accounts/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@


def test_verify_hash():
secret_key = "aqXwLJVOcV"
hash = model.generate_hash(secret_key, "foo")
assert model.verify_hash(secret_key, "foo", hash) == True
secret_key = "aqXwLJVOcV"
hash = model.generate_hash(secret_key, "foo")
assert model.verify_hash(secret_key, "foo", hash)


class TestInternetArchiveAccount:
def test_xauth_http_error_without_json(self, monkeypatch):
xauth = InternetArchiveAccount.xauth
def test_xauth_http_error_without_json(self, monkeypatch):
xauth = InternetArchiveAccount.xauth
resp = Response()
resp.status_code = 500
resp._content = b'Internal Server Error'
monkeypatch.setattr(model.requests, 'post', lambda url, **kwargs: resp)
assert xauth('create', s3_key='_', s3_secret='_') == {'code': 500, 'error':
'Internal Server Error'}

resp = Response()
resp.status_code = 500
resp._content = b'Internal Server Error'
monkeypatch.setattr(model.requests, 'post', lambda url, **kwargs: resp)
assert xauth('create', s3_key='_', s3_secret='_') == {'code': 500, 'error': 'Internal Server Error'}

def test_xauth_http_error_with_json(self, monkeypatch):
xauth = InternetArchiveAccount.xauth

resp = Response()
resp.status_code = 400
resp._content = b'{"error": "Unknown Parameter Blah"}'
monkeypatch.setattr(model.requests, 'post', lambda url, **kwargs: resp)
assert xauth('create', s3_key='_', s3_secret='_') == {"error": "Unknown Parameter Blah"}
def test_xauth_http_error_with_json(self, monkeypatch):
xauth = InternetArchiveAccount.xauth
resp = Response()
resp.status_code = 400
resp._content = b'{"error": "Unknown Parameter Blah"}'
monkeypatch.setattr(model.requests, 'post', lambda url, **kwargs: resp)
assert xauth('create', s3_key='_', s3_secret='_') == {"error":
"Unknown Parameter Blah"}

0 comments on commit eae8c7e

Please sign in to comment.