Skip to content

Commit

Permalink
Adjust ingest fix for utf-8 to also work for python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Aug 8, 2016
1 parent 1f7275d commit a89b0d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion eulfedora/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def ingest(self, text, logMessage=None):
# if text is unicode, it needs to be encoded so we can send the
# data as bytes; otherwise, we get ascii encode errors in httplib/ssl
if isinstance(text, six.text_type):
text = text.encode('utf-8')
text = bytes(text.encode('utf-8'))

return self.post(url, data=text, params=http_args, headers=headers)

Expand Down
8 changes: 5 additions & 3 deletions test/test_fedora/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def test_ingest_utf8(self):
# ingest with unicode log message
obj = self.loadFixtureData('basic-object.foxml')
response = self.rest_api.ingest(obj, logMessage=self.unicode_test_str)
pid = response.content
pid = response.text
self.assertTrue(pid)

response = self.rest_api.getObjectXML(pid)
Expand All @@ -525,9 +525,11 @@ def test_ingest_utf8(self):
self.rest_api.purgeObject(force_text(pid))

# ingest with unicode object label
obj = six.u(obj).replace(u"A test object", self.unicode_test_str)
# convert to text to replace string, then convert back to bytes
obj = force_bytes(force_text(obj).replace(
u"A test object", self.unicode_test_str))
response = self.rest_api.ingest(obj)
pid = response.content
pid = response.text
self.assertTrue(pid)

# object label in profile should match the unicode sent
Expand Down

0 comments on commit a89b0d9

Please sign in to comment.