From 36e1e5e7f02df8b52ab880465076e0c36b5b45c5 Mon Sep 17 00:00:00 2001 From: Yannick Allusse Date: Wed, 24 Jan 2018 11:49:05 +0100 Subject: [PATCH 1/2] fix unit tests --- ltu/engine/client.py | 11 +++++++---- ltu/engine/testsclient.py | 25 +++++++++++++++++-------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/ltu/engine/client.py b/ltu/engine/client.py index e6ff321..fe3423b 100644 --- a/ltu/engine/client.py +++ b/ltu/engine/client.py @@ -90,10 +90,13 @@ def check_status(self): Logs advice on actions to take as warnings in case of wrong status. """ - result = self.get_application_status() - if result.status_code == 0: - return True - else: + try: + result = self.get_application_status() + if result.status_code == 0: + return True + else: + return False + except: return False def open_service(self, service, params={}, files=None): diff --git a/ltu/engine/testsclient.py b/ltu/engine/testsclient.py index e4f2032..84164d6 100755 --- a/ltu/engine/testsclient.py +++ b/ltu/engine/testsclient.py @@ -4,15 +4,24 @@ from result import Result from client import BaseClient, QueryClient, ModifyClient + +# !!!! +# Please specify a valid application key HERE +# !!!! +MY_APPLICATION_KEY = None + class ClientTestCase(unittest2.TestCase): def setUp(self): - self.application_key = "123456" - self.server_url = "http://ltutech.com" + self.application_key = MY_APPLICATION_KEY + if not self.application_key: + raise ValueError("You need to specify a valid application key to be able to perform the unit tests\n" \ + "Update your unit test file.") + self.server_url = "https://api.ltu-engine.com" self.query_client = QueryClient(application_key=self.application_key) self.modify_client = ModifyClient(application_key=self.application_key) - self.image_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), - "../../data/kill-bill-vol-1.jpg") + self.image_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), + "../../data/fire-truck.jpg") # Query results self.search_image_result = """{"images": [{"keywords": [], "score": 0.10410962999999999, "id": "4ea5cc294f13c137cc000063", "result_info": "{\\n \\"category\\" : \\"LOCALMATCHING\\",\\n \\"query\\" : \\n {\\n \\"originalDimensions\\" : [500, 718],\\n \\"resizedDimensions\\" : [356, 512],\\n \\"matchingBox\\" : \\n {\\n \\"topLeftPoint\\" : [0.0197, 0.0449],\\n \\"bottomRightPoint\\" : [0.9663, 0.9922]\\n }\\n },\\n \\"reference\\" : \\n {\\n \\"originalDimensions\\" : [1000, 1435],\\n \\"resizedDimensions\\" : [356, 512],\\n \\"matchingBox\\" : \\n {\\n \\"topLeftPoint\\" : [0.0197, 0.0449],\\n \\"bottomRightPoint\\" : [0.9663, 0.9922]\\n }\\n },\\n \\"homography\\" : \\n {\\n \\"source\\" : \\"reference\\",\\n \\"destination\\" : \\"query\\",\\n \\"coefficients\\" : [1.0005, 0.0005, -0.0004, -0.0003, 1.0009, -0.0001, -0.0000, 0.0008, 1.0000]\\n }\\n}"}, {"keywords": [], "score": 0.18547931300000001, "id": "4ea60983a34d4b41fd000065", "result_info": "{\\n \\"category\\" : \\"LOCALMATCHING\\",\\n \\"query\\" : \\n {\\n \\"originalDimensions\\" : [500, 718],\\n \\"resizedDimensions\\" : [356, 512],\\n \\"matchingBox\\" : \\n {\\n \\"topLeftPoint\\" : [0.0197, 0.0449],\\n \\"bottomRightPoint\\" : [0.9663, 0.9238]\\n }\\n },\\n \\"reference\\" : \\n {\\n \\"originalDimensions\\" : [1000, 1435],\\n \\"resizedDimensions\\" : [356, 512],\\n \\"matchingBox\\" : \\n {\\n \\"topLeftPoint\\" : [0.0169, 0.0449],\\n \\"bottomRightPoint\\" : [0.9663, 0.9238]\\n }\\n },\\n \\"homography\\" : \\n {\\n \\"source\\" : \\"reference\\",\\n \\"destination\\" : \\"query\\",\\n \\"coefficients\\" : [0.9990, 0.0005, -0.0003, -0.0002, 0.9990, 0.0006, 0.0000, 0.0000, 1.0000]\\n }\\n}"}], "status": {"message": "No error", "code": 0}, "nb_results_found": 2}""" @@ -22,13 +31,13 @@ def setUp(self): self.delete_image_result = """{"status": {"message": "Image deleted from the reference database", "code": 0}, "task_id": 0}""" def testInit(self): + # we do not test the server_url because it can be updated by the + # API auto-discovery feature from the client. client = BaseClient(self.application_key, self.server_url) self.assertEqual(self.application_key, client.application_key) - self.assertEqual(self.server_url, client.server_url) query_client = QueryClient(self.application_key, self.server_url) self.assertEqual(query_client.application_key, client.application_key) - self.assertEqual(query_client.server_url, client.server_url) def testSearchImageByUpload(self): self.query_client.open_service = mock.MagicMock(return_value=self.search_image_result) @@ -50,12 +59,12 @@ def testGetApplicationStatus(self): def testAddImage(self): # Success self.modify_client.open_service = mock.MagicMock(return_value=self.add_image_result) - result = self.modify_client.add_image("myimage", self.image_path) + result = self.modify_client.add_image(self.image_path, "myimage") self.assertEqual(0, result.status_code) # Error self.modify_client.open_service = mock.MagicMock(return_value=self.add_image_error_result) - result = self.modify_client.add_image("myimage", self.image_path, keywords=";*()[]") + result = self.modify_client.add_image(self.image_path, "myimage", keywords=";*()[]") self.assertEqual(-1404, result.status_code) self.assertEqual("status='-1404' status_message='Invalid chars in keyword'", result.status_message) From 2a803c8ac0356e1f8f0fc59c3076f6eb39e817bd Mon Sep 17 00:00:00 2001 From: Yannick Allusse Date: Wed, 24 Jan 2018 11:58:47 +0100 Subject: [PATCH 2/2] update .gitignore --- .gitignore | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e61f024..255e972 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,11 @@ dist env* *.egg-info .vscode -build \ No newline at end of file +build +out_result +*BACKUP* +*BASE* +*LOCAL* +*REMOTE* +*.log +*.orig \ No newline at end of file