Skip to content
This repository was archived by the owner on Jan 7, 2021. It is now read-only.

Commit 288bf7d

Browse files
committed
Refactored the public client part of the DocumentTest to run faster as well. We're making progress here.
1 parent 7fa20db commit 288bf7d

1 file changed

Lines changed: 63 additions & 95 deletions

File tree

test.py

Lines changed: 63 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def setUp(self):
121121
)
122122
self.fake_client = DocumentCloud("John Doe", "TK")
123123
self.version = self.get_version()
124-
# self.editable_document = self.get_editable_document(self.version)
125124
# self.editable_project = self.get_editable_project(self.version)
126125

127126

@@ -186,102 +185,71 @@ def test_search(self):
186185
obj.__unicode__()
187186

188187

189-
#class DocumentTest(BaseTest):
190-
# """"
191-
# Document object related tests.
192-
# """
193-
# def test_get(self):
194-
# """
195-
# Test a get request for a particular document.
196-
# """
197-
# obj = self.public_client.documents.get(self.test_id)
198-
# self.assertEqual(type(obj), Document)
199-
200-
# def test_get_attrs(self):
201-
# """
202-
# Verify that all the Document attributes exist.
203-
# """
204-
# obj = self.public_client.documents.get(self.test_id)
205-
# attr_list = [
206-
# 'access',
207-
# 'annotations',
208-
# 'canonical_url',
209-
# 'contributor',
210-
# 'contributor_organization',
211-
# 'created_at',
212-
# 'description',
213-
# 'id',
214-
# 'pages',
215-
# 'resources',
216-
# 'sections',
217-
# 'source',
218-
# 'title',
219-
# 'updated_at',
220-
# 'data',
221-
# 'file_hash',
222-
# ]
223-
# [self.assertTrue(hasattr(obj, attr)) for attr in attr_list]
224-
# obj.__str__()
225-
# obj.__unicode__()
226-
227-
# def test_get_pdf(self):
228-
# """
229-
# Test if you can pull the PDF
230-
# """
231-
# obj = self.public_client.documents.get(self.test_id)
232-
# pdf = obj.pdf
233-
# self.assertTrue(len(pdf) > 0, True)
234-
# self.assertEqual(hashlib.sha1(pdf).hexdigest(), obj.file_hash)
235-
236-
## def test_get_full_text(self):
237-
## """
238-
## Test if you can pull the full text
239-
## """
240-
## obj = self.public_client.documents.get(self.test_id)
241-
## try:
242-
## self.assertTrue(len(obj.full_text) > 0, True)
243-
## except:
244-
## self.assertRaises(obj.full_text, NotImplementedError)
245-
246-
# def test_get_images(self):
247-
# """
248-
# Test if you can pull the images
249-
# """
250-
# obj = self.public_client.documents.get(self.test_id)
251-
# self.assertTrue(len(obj.small_image) > 0, True)
252-
# self.assertTrue(len(obj.thumbnail_image) > 0, True)
253-
# self.assertTrue(len(obj.normal_image) > 0, True)
254-
# self.assertTrue(len(obj.large_image) > 0, True)
255-
256-
# def test_get_annotations(self):
257-
# """
258-
# Test whether annotations exist.
259-
# """
260-
# doc = self.public_client.documents.get(self.test_id)
261-
# obj = doc.annotations[0]
262-
# self.assertEqual(type(obj), Annotation)
263-
# obj.__str__()
264-
# obj.__unicode__()
188+
class DocumentTest(BaseTest):
189+
""""
190+
Document object related tests.
191+
"""
192+
def test_public_actions(self):
193+
"""
194+
Test all the tricks available without authentication.
195+
"""
196+
# Pull a document
197+
self.obj = self.public_client.documents.get(self.test_id)
265198

266-
# def test_get_sections(self):
267-
# """
268-
# Test whether sections exist.
269-
# """
270-
# doc = self.public_client.documents.get(self.test_id)
271-
# obj = doc.sections[0]
272-
# self.assertEqual(type(obj), Section)
273-
# obj.__str__()
274-
# obj.__unicode__()
199+
# Test its attributions
200+
self.assertTrue(isinstance(self.obj, Document))
201+
obj = self.public_client.documents.get(self.test_id)
202+
attr_list = [
203+
'access',
204+
'annotations',
205+
'canonical_url',
206+
'contributor',
207+
'contributor_organization',
208+
'created_at',
209+
'description',
210+
'id',
211+
'pages',
212+
'resources',
213+
'sections',
214+
'source',
215+
'title',
216+
'updated_at',
217+
'data',
218+
'file_hash',
219+
]
220+
[self.assertTrue(hasattr(obj, attr)) for attr in attr_list]
221+
obj.__str__()
222+
obj.__unicode__()
275223

276-
# def test_get_entities(self):
277-
# """
278-
# Test whether entities exist.
279-
# """
280-
# doc = self.public_client.documents.get(self.test_id)
281-
# obj = doc.entities[0]
282-
# self.assertEqual(type(obj), Entity)
283-
# obj.__str__()
284-
# obj.__unicode__()
224+
# Raw PDF
225+
self.assertTrue(len(obj.pdf) > 0)
226+
# Turning this test off until @knowtheory gets all the value filled
227+
# for all the old documents in the database.
228+
#self.assertEqual(hashlib.sha1(pdf).hexdigest(), obj.file_hash)
229+
230+
# Images
231+
self.assertTrue(len(obj.small_image) > 0)
232+
self.assertTrue(len(obj.thumbnail_image) > 0)
233+
self.assertTrue(len(obj.normal_image) > 0)
234+
self.assertTrue(len(obj.large_image) > 0)
235+
236+
# Annotations
237+
ann = obj.annotations[0]
238+
self.assertTrue(isinstance(ann, Annotation))
239+
ann.__str__()
240+
ann.__unicode__()
241+
242+
# Sections
243+
sec = obj.sections[0]
244+
self.assertTrue(isinstance(sec, Section))
245+
sec.__str__()
246+
sec.__unicode__()
247+
248+
# Entities
249+
ent = obj.entities[0]
250+
self.assertTrue(isinstance(ent, Entity))
251+
ent.__str__()
252+
ent.__unicode__()
285253

286254
# def test_set_data_type_restrictions(self):
287255
# """

0 commit comments

Comments
 (0)