Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ dist
env*
*.egg-info
.vscode
build
build
out_result
*BACKUP*
*BASE*
*LOCAL*
*REMOTE*
*.log
*.orig
11 changes: 7 additions & 4 deletions ltu/engine/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 17 additions & 8 deletions ltu/engine/testsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"""
Expand All @@ -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)
Expand All @@ -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)

Expand Down