|
| 1 | +import json |
| 2 | + |
| 3 | +from steamship import PluginInstance |
| 4 | +from ..client.helpers import deploy_plugin, _steamship |
| 5 | +from tests.client.operations.test_tag_file import parse_file |
| 6 | + |
| 7 | +__copyright__ = "Steamship" |
| 8 | +__license__ = "MIT" |
| 9 | + |
| 10 | + |
| 11 | +def test_e2e_parser(): |
| 12 | + client = _steamship() |
| 13 | + |
| 14 | + configTemplate = {"tagKind": {"type":"string"}, |
| 15 | + "tagName": {"type":"string"}, |
| 16 | + "numberValue": {"type":"number"}, |
| 17 | + "booleanValue": {"type":"boolean"}} |
| 18 | + instanceConfig1 = {"tagKind": "testTagKind", |
| 19 | + "tagName": "testTagName", |
| 20 | + "numberValue": 3, |
| 21 | + "booleanValue": True} |
| 22 | + |
| 23 | + with deploy_plugin("plugin_configurable_tagger.py", "tagger", versionConfigTemplate=configTemplate, instanceConfig=instanceConfig1) as (plugin, version, instance): |
| 24 | + test_doc = "Hi there" |
| 25 | + res = client.tag(doc=test_doc, pluginInstance=instance.handle) |
| 26 | + res.wait() |
| 27 | + assert (res.error is None) |
| 28 | + assert (res.data is not None) |
| 29 | + assert (len(res.data.file.blocks) == 1) |
| 30 | + assert (res.data.file.blocks[0].text == test_doc) |
| 31 | + |
| 32 | + #Validate configured content |
| 33 | + assert (len(res.data.file.tags) == 1) |
| 34 | + tag = res.data.file.tags[0] |
| 35 | + assert (tag.name == instanceConfig1['tagName']) |
| 36 | + assert (tag.kind == instanceConfig1['tagKind']) |
| 37 | + tagValue = json.loads(tag.value) |
| 38 | + assert (tagValue['numberValue'] == instanceConfig1['numberValue']) |
| 39 | + assert (tagValue['booleanValue'] == instanceConfig1['booleanValue']) |
| 40 | + |
| 41 | + instanceConfig2 = {"tagKind": "testTagKind2", |
| 42 | + "tagName": "testTagName2", |
| 43 | + "numberValue": 4, |
| 44 | + "booleanValue": False} |
| 45 | + |
| 46 | + instance2 = PluginInstance.create( |
| 47 | + client, |
| 48 | + pluginId=plugin.id, |
| 49 | + pluginVersionId=version.id, |
| 50 | + config=instanceConfig2 |
| 51 | + ) |
| 52 | + instance2.wait() |
| 53 | + assert (instance2.error is None) |
| 54 | + assert (instance2.data is not None) |
| 55 | + instance2 = instance2.data |
| 56 | + |
| 57 | + res = client.tag(doc=test_doc, pluginInstance=instance2.handle) |
| 58 | + res.wait() |
| 59 | + assert (res.error is None) |
| 60 | + assert (res.data is not None) |
| 61 | + assert (len(res.data.file.blocks) == 1) |
| 62 | + assert (res.data.file.blocks[0].text == test_doc) |
| 63 | + |
| 64 | + # Validate configured content |
| 65 | + assert (len(res.data.file.tags) == 1) |
| 66 | + tag = res.data.file.tags[0] |
| 67 | + assert (tag.name == instanceConfig2['tagName']) |
| 68 | + assert (tag.kind == instanceConfig2['tagKind']) |
| 69 | + tagValue = json.loads(tag.value) |
| 70 | + assert (tagValue['numberValue'] == instanceConfig2['numberValue']) |
| 71 | + assert (tagValue['booleanValue'] == instanceConfig2['booleanValue']) |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
0 commit comments