|
| 1 | +from typing import List |
| 2 | + |
| 3 | +import pytest |
| 4 | +from thehive4py.client import TheHiveApi |
| 5 | +from thehive4py.errors import TheHiveError |
| 6 | +from thehive4py.types.case_template import InputCaseTemplate, OutputCaseTemplate |
| 7 | + |
| 8 | + |
| 9 | +class TestCaseTemplateEndpoint: |
| 10 | + def test_create_and_get(self, thehive: TheHiveApi): |
| 11 | + created_case_template = thehive.case_template.create( |
| 12 | + case_template={ |
| 13 | + "name": "my first template", |
| 14 | + "description": "Template description", |
| 15 | + } |
| 16 | + ) |
| 17 | + fetched_case_template = thehive.case_template.get(created_case_template["_id"]) |
| 18 | + assert created_case_template == fetched_case_template |
| 19 | + |
| 20 | + def test_update(self, thehive: TheHiveApi, test_case_template: OutputCaseTemplate): |
| 21 | + case_template_id = test_case_template["_id"] |
| 22 | + update_fields: InputCaseTemplate = { |
| 23 | + "name": "updated template name", |
| 24 | + "description": "updated template description", |
| 25 | + } |
| 26 | + thehive.case_template.update( |
| 27 | + case_template_id=case_template_id, fields=update_fields |
| 28 | + ) |
| 29 | + updated_case_template = thehive.case_template.get( |
| 30 | + case_template_id=case_template_id |
| 31 | + ) |
| 32 | + |
| 33 | + for key, value in update_fields.items(): |
| 34 | + assert updated_case_template.get(key) == value |
| 35 | + |
| 36 | + def test_delete(self, thehive: TheHiveApi, test_case_template: OutputCaseTemplate): |
| 37 | + case_template_id = test_case_template["_id"] |
| 38 | + thehive.case_template.delete(case_template_id=case_template_id) |
| 39 | + with pytest.raises(TheHiveError): |
| 40 | + thehive.case_template.get(case_template_id=case_template_id) |
| 41 | + |
| 42 | + def test_find( |
| 43 | + self, |
| 44 | + thehive: TheHiveApi, |
| 45 | + test_case_templates: List[OutputCaseTemplate], |
| 46 | + ): |
| 47 | + found_templates = thehive.case_template.find() |
| 48 | + original_ids = [template["_id"] for template in test_case_templates] |
| 49 | + found_ids = [template["_id"] for template in found_templates] |
| 50 | + assert sorted(found_ids) == sorted(original_ids) |
0 commit comments