summaryrefslogtreecommitdiff
path: root/archaeological_operations/tests.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-10-19 22:19:45 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:20:59 +0100
commitdce7ab14dfb23d953598a92a578b8cb9e0738fff (patch)
tree19988c86ec4f03874017d54b3ad5a9ec6276a0a4 /archaeological_operations/tests.py
parentd15d5ec54c73e657370cc8d4d7e1c1e7e6f40af4 (diff)
downloadIshtar-dce7ab14dfb23d953598a92a578b8cb9e0738fff.tar.bz2
Ishtar-dce7ab14dfb23d953598a92a578b8cb9e0738fff.zip
Syndication - generate libreoffice match document
Diffstat (limited to 'archaeological_operations/tests.py')
-rw-r--r--archaeological_operations/tests.py66
1 files changed, 57 insertions, 9 deletions
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 74ae5819a..ee1f2645c 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -4579,6 +4579,17 @@ class ApiTest(OperationInitTest, APITestCase):
)
return src
+ def _mock_request(self, mock_get, json_file="external_source_types_1.json"):
+ json_file = "../archaeological_operations/tests/" + json_file
+ mock_get.return_value.status_code = 200
+
+ def __json():
+ return json.loads(mock_get.return_value.text)
+
+ mock_get.return_value.json = __json
+ with open(json_file, "r") as tpes:
+ mock_get.return_value.text = tpes.read()
+
@patch("requests.get")
def test_type_admin(self, mock_get):
# POV: local
@@ -4623,10 +4634,7 @@ class ApiTest(OperationInitTest, APITestCase):
response.content.decode(),
)
- with open(
- "../archaeological_operations/tests/external_source_types_1.json", "r"
- ) as tpes:
- mock_get.return_value.text = tpes.read()
+ self._mock_request(mock_get)
response = self.client.post(url, params, follow=True)
result = {"created": "XXXXX"}
@@ -4635,10 +4643,7 @@ class ApiTest(OperationInitTest, APITestCase):
)
self.assertIn(msg_created, response.content.decode())
# test incoherent search_model and types
- with open(
- "../archaeological_operations/tests/external_source_types_2.json", "r"
- ) as tpes:
- mock_get.return_value.text = tpes.read()
+ self._mock_request(mock_get, "external_source_types_2.json")
response = self.client.post(url, params, follow=True)
content = response.content.decode()
@@ -4662,7 +4667,50 @@ class ApiTest(OperationInitTest, APITestCase):
msg = str(_(f"{result['deleted']} matches deleted"))
self.assertIn(msg, response.content.decode())
- pass
+ @tag("libreoffice")
+ @patch("requests.get")
+ def test_match_doc(self, mock_get):
+ if not settings.USE_LIBREOFFICE:
+ return
+ self._mock_request(mock_get)
+ self.client.login(username=self.username, password=self.password)
+ source = self._get_source()
+ url = "/admin/{}/{}/".format(
+ "ishtar_common", models_rest.ApiExternalSource.__name__.lower()
+ )
+ params = {
+ "action": "update_types_from_source",
+ "_selected_action": [source.pk],
+ }
+ self.client.post(url, params, follow=True)
+
+ params["action"] = "generate_match_document"
+ response = self.client.post(url, params, follow=True)
+ #src_doc = source.generate_match_document()
+ zip_file = zipfile.ZipFile(BytesIO(response.content))
+
+ self.assertIsNone(
+ zip_file.testzip(),
+ "Libreoffice match doc generated is not a correct zip file.",
+ )
+
+ filename = None
+ for name in zip_file.namelist():
+ if name == "content.xml":
+ filename = name
+ break
+ self.assertIsNotNone(filename)
+
+ # only check that all operation types are listed
+ with tempfile.TemporaryDirectory(prefix="tmp-ishtar-") as tmpdir:
+ match_file = zip_file.extract(filename, tmpdir)
+ with open(match_file) as content_file:
+ content = content_file.read()
+ for ope_type in models.OperationType.objects.filter(
+ available=True
+ ).all():
+ ope_type = str(ope_type).replace("'", "&apos;")
+ self.assertIn(ope_type, content)
def test_query_transformation(self):
# POV: local