-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #669 from bounswe/get-annotation-update
Get annotation update
- Loading branch information
Showing
2 changed files
with
111 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,25 @@ class AnnotationGetTest(TestCase): | |
def setUp(self): | ||
source = Source.objects.create(uri='http://example.com/source1') | ||
body = Body.objects.create(value='Annotation Test Content') | ||
creator = Creator.objects.create(name='[email protected]') | ||
creator = Creator.objects.create(name='http://13.51.205.39/profile/[email protected]') | ||
selector = Selector.objects.create(start=0, end=5, source=source) | ||
self.annotation = Annotation.objects.create( | ||
body=body, | ||
target=selector, | ||
creator=creator, | ||
created=datetime.now(), | ||
) | ||
|
||
source2 = Source.objects.create(uri='http://example.com/source2') | ||
body2 = Body.objects.create(value='Annotation Test Content2') | ||
creator2 = Creator.objects.create(name='http://13.51.205.39/profile/[email protected]') | ||
selector2 = Selector.objects.create(start=0, end=5, source=source2) | ||
self.annotation2 = Annotation.objects.create( | ||
body=body2, | ||
target=selector2, | ||
creator=creator2, | ||
created=datetime.now(), | ||
) | ||
|
||
def tearDown(self): | ||
Annotation.objects.all().delete() | ||
|
@@ -26,6 +37,61 @@ def tearDown(self): | |
Source.objects.all().delete() | ||
print("All Annotation Get API Tests Completed") | ||
|
||
#TODO: update matched annotations test | ||
|
||
def test_get_matched_annotations(self): | ||
client = Client() | ||
|
||
url = reverse('get_annotation') | ||
multicreator_data = { | ||
'creator': [ | ||
'http://13.51.205.39/profile/[email protected]', | ||
'http://13.51.205.39/profile/[email protected]'] | ||
} | ||
multisource_data = { | ||
'source' : [ | ||
'http://example.com/source1', | ||
'http://example.com/source2' | ||
] | ||
} | ||
|
||
data = { | ||
'source' : 'http://example.com/source2', | ||
'creator': 'http://13.51.205.39/profile/[email protected]' | ||
} | ||
|
||
response = client.get(url, multicreator_data, format='json') | ||
self.assertEqual(response.status_code, 200, response.json()) | ||
self.assertEqual(len(response.json()), 2) | ||
|
||
response = client.get(url, multisource_data, format='json') | ||
self.assertEqual(response.status_code, 200, response.json()) | ||
self.assertEqual(len(response.json()), 2) | ||
|
||
response = client.get(url, data, format='json') | ||
self.assertEqual(response.status_code, 200, response.json()) | ||
response = response.json()[0] | ||
self.assertEqual(response['@context'], 'http://www.w3.org/ns/anno.jsonld') | ||
self.assertEqual(response['id'],f'http://13.51.55.11:8001/annotations/annotation/{self.annotation2.id}') | ||
self.assertEqual(response['type'], self.annotation2.type) | ||
self.assertEqual(response['body'], { | ||
'type': self.annotation2.body.type, | ||
'format': self.annotation2.body.format, | ||
'language': self.annotation2.body.language, | ||
'value': self.annotation2.body.value, | ||
}) | ||
self.assertEqual(response['target'], { | ||
'id': self.annotation2.target.source.uri, | ||
'type': 'text', | ||
'selector': { | ||
'type': self.annotation2.target.type, | ||
'start': self.annotation2.target.start, | ||
'end': self.annotation2.target.end, | ||
} | ||
}) | ||
self.assertTrue(response['creator']['id'], self.annotation2.creator.name) | ||
self.assertIn('created', response) | ||
|
||
def test_get_annotation_by_id(self): | ||
#Test the annotation response format | ||
client = Client() | ||
|
@@ -130,8 +196,8 @@ def test_create_annotation(self): | |
response = self.client.post(self.url, data=self.body_missing_creator, headers=self.headers) | ||
self.assertEqual(response.status_code, 400, "Missing creator field test failed. expected 400, got " + str(response.status_code)) | ||
|
||
response = self.client.post(self.url, data=self.body, headers=self.headers, content_type='application/json') | ||
self.assertEqual(response.status_code, 200, "Successful create annotation test failed. expected 200, got " + str(response.status_code)) | ||
response = self.client.post(self.url, data=self.body) | ||
self.assertEqual(response.status_code, 201, "Successful create annotation test failed. expected 201, got " + str(response.status_code)) | ||
|
||
records = Annotation.objects.filter(id=response.json()['id']) | ||
self.assertEqual(len(records), 1, "Successful create annotation test (database insertion) failed. expected 1 row, got " + str(len(records))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters