|
| 1 | +import unittest |
| 2 | +from hydra_python_core.doc_writer import Context |
| 3 | +from unittest.mock import MagicMock, patch |
| 4 | + |
| 5 | + |
| 6 | +class TestContext: |
| 7 | + |
| 8 | + def test_context_with_nothing(self, get_context): |
| 9 | + """ |
| 10 | + Test method to test if correct context is generated when no arguments are passed |
| 11 | +
|
| 12 | + """ |
| 13 | + context = get_context |
| 14 | + expected_context = { |
| 15 | + 'hydra': 'http://www.w3.org/ns/hydra/core#', |
| 16 | + 'property': { |
| 17 | + '@type': '@id', |
| 18 | + '@id': 'hydra:property' |
| 19 | + }, |
| 20 | + 'supportedClass': 'hydra:supportedClass', |
| 21 | + 'supportedProperty': 'hydra:supportedProperty', |
| 22 | + 'supportedOperation': 'hydra:supportedOperation', |
| 23 | + 'label': 'rdfs:label', |
| 24 | + 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
| 25 | + "xsd": "https://www.w3.org/TR/xmlschema-2/#", |
| 26 | + 'domain': { |
| 27 | + '@type': '@id', |
| 28 | + '@id': 'rdfs:domain' |
| 29 | + }, |
| 30 | + 'ApiDocumentation': 'hydra:ApiDocumentation', |
| 31 | + 'range': { |
| 32 | + '@type': '@id', |
| 33 | + '@id': 'rdfs:range' |
| 34 | + }, |
| 35 | + 'rdfs': 'http://www.w3.org/2000/01/rdf-schema#', |
| 36 | + 'title': 'hydra:title', |
| 37 | + 'expects': { |
| 38 | + '@type': '@id', |
| 39 | + '@id': 'hydra:expects' |
| 40 | + }, |
| 41 | + 'returns': { |
| 42 | + '@id': 'hydra:returns', |
| 43 | + '@type': '@id' |
| 44 | + }, |
| 45 | + 'entrypoint': { |
| 46 | + '@id': 'hydra:entrypoint', |
| 47 | + '@type': '@id' |
| 48 | + }, |
| 49 | + 'object': { |
| 50 | + '@id': 'hydra:object', |
| 51 | + '@type': '@id' |
| 52 | + }, |
| 53 | + 'subject': { |
| 54 | + '@id': 'hydra:subject', |
| 55 | + '@type': '@id' |
| 56 | + }, |
| 57 | + 'readable': 'hydra:readable', |
| 58 | + 'writeable': 'hydra:writeable', |
| 59 | + 'possibleStatus': 'hydra:possibleStatus', |
| 60 | + 'required': 'hydra:required', |
| 61 | + 'method': 'hydra:method', |
| 62 | + 'statusCode': 'hydra:statusCode', |
| 63 | + 'description': 'hydra:description', |
| 64 | + 'expectsHeader': 'hydra:expectsHeader', |
| 65 | + 'returnsHeader': 'hydra:returnsHeader', |
| 66 | + 'manages': 'hydra:manages', |
| 67 | + 'subClassOf': { |
| 68 | + '@id': 'rdfs:subClassOf', |
| 69 | + '@type': '@id' |
| 70 | + }, |
| 71 | + 'search': 'hydra:search' |
| 72 | + } |
| 73 | + assert expected_context == context.generate() |
| 74 | + |
| 75 | + def test_context_with_entrypoint(self, capsys, get_hydra_entrypoint): |
| 76 | + _entrypoint = get_hydra_entrypoint |
| 77 | + context = Context("http://www.hydrus.com/", entrypoint=_entrypoint) |
| 78 | + expected_context = {'EntryPoint': 'http://hydrus.com/test_api/vocab?resource=EntryPoint'} |
| 79 | + assert expected_context == context.generate() |
| 80 | + |
| 81 | + def test_context_with_class(self, capsys, get_hydra_class): |
| 82 | + _class = get_hydra_class |
| 83 | + context = Context("http://www.hydrus.com/", class_=_class) |
| 84 | + expected_context = { |
| 85 | + 'hydra': 'http://www.w3.org/ns/hydra/core#', |
| 86 | + 'members': 'http://www.w3.org/ns/hydra/core#member', |
| 87 | + 'object': 'http://schema.org/object', |
| 88 | + 'dummyClass': 'http://hydrus.com/test_api/vocab?resource=dummyClass' |
| 89 | + } |
| 90 | + assert expected_context == context.generate() |
| 91 | + |
| 92 | + def test_context_with_collection(self, capsys, get_hydra_collection): |
| 93 | + collection_ = get_hydra_collection |
| 94 | + context = Context("http://www.hydrus.com/", collection=collection_) |
| 95 | + expected_context = { |
| 96 | + 'hydra': 'http://www.w3.org/ns/hydra/core#', |
| 97 | + 'members': 'http://www.w3.org/ns/hydra/core#member', |
| 98 | + 'dummyclasses': 'http://hydrus.com/test_api/vocab?resource=dummyclasses' |
| 99 | + } |
| 100 | + assert expected_context == context.generate() |
0 commit comments