2016-09-20 22:18:10 +00:00
|
|
|
from django.test import TestCase
|
2016-09-27 14:45:09 +00:00
|
|
|
from django.utils import six
|
|
|
|
import subprocess, time
|
2016-10-05 20:31:46 +00:00
|
|
|
from os import path
|
2016-09-27 14:45:09 +00:00
|
|
|
from .models import ProcessingNode
|
|
|
|
from .api_client import ApiClient
|
2016-10-25 16:19:14 +00:00
|
|
|
from requests.exceptions import ConnectionError
|
2016-09-20 22:18:10 +00:00
|
|
|
|
2016-09-27 14:45:09 +00:00
|
|
|
current_dir = path.dirname(path.realpath(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
class TestClientApi(TestCase):
|
|
|
|
fixtures = ['test_processingnodes', ]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(TestClientApi, cls).setUpClass()
|
2016-10-05 20:31:46 +00:00
|
|
|
cls.node_odm = subprocess.Popen(['node', 'index.js', '--port', '11223', '--test'], shell=False, cwd=path.join(current_dir, "external", "node-OpenDroneMap"))
|
2016-09-27 14:45:09 +00:00
|
|
|
time.sleep(5) # Wait for the server to launch
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TestClientApi, cls).tearDownClass()
|
|
|
|
cls.node_odm.terminate()
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.api_client = ApiClient("localhost", 11223)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def test_offline_api(self):
|
|
|
|
api = ApiClient("offline-host", 3000)
|
2016-10-25 16:19:14 +00:00
|
|
|
self.assertRaises(ConnectionError, api.info)
|
|
|
|
self.assertRaises(ConnectionError, api.options)
|
2016-09-27 14:45:09 +00:00
|
|
|
|
|
|
|
def test_info(self):
|
|
|
|
info = self.api_client.info()
|
|
|
|
self.assertTrue(isinstance(info['version'], six.string_types), "Found version string")
|
|
|
|
self.assertTrue(isinstance(info['taskQueueCount'], int), "Found task queue count")
|
|
|
|
|
|
|
|
def test_options(self):
|
|
|
|
options = self.api_client.options()
|
|
|
|
self.assertTrue(len(options) > 0, "Found options")
|
|
|
|
|
|
|
|
def test_online_processing_node(self):
|
|
|
|
online_node = ProcessingNode.objects.get(pk=1)
|
|
|
|
self.assertTrue(str(online_node) == "localhost:11223", "Formatting string works")
|
2016-10-24 18:34:37 +00:00
|
|
|
self.assertTrue(online_node.last_refreshed == None, "Last refreshed not yet set")
|
2016-09-27 14:45:09 +00:00
|
|
|
self.assertTrue(len(online_node.available_options) == 0, "Available options not yet set")
|
|
|
|
self.assertTrue(online_node.api_version == "", "API version is not set")
|
|
|
|
|
|
|
|
self.assertTrue(online_node.update_node_info(), "Could update info")
|
2016-10-24 18:34:37 +00:00
|
|
|
self.assertTrue(online_node.last_refreshed != None, "Last refreshed is set")
|
2016-09-27 14:45:09 +00:00
|
|
|
self.assertTrue(len(online_node.available_options) > 0, "Available options are set")
|
|
|
|
self.assertTrue(online_node.api_version != "", "API version is set")
|
|
|
|
|
|
|
|
self.assertTrue(isinstance(online_node.get_available_options_json(), six.string_types), "Available options json works")
|
2016-10-28 19:40:03 +00:00
|
|
|
self.assertTrue(isinstance(online_node.get_available_options_json(pretty=True), six.string_types), "Available options json works with pretty")
|
2016-09-27 14:45:09 +00:00
|
|
|
|
|
|
|
def test_offline_processing_node(self):
|
|
|
|
offline_node = ProcessingNode.objects.get(pk=2)
|
|
|
|
self.assertFalse(offline_node.update_node_info(), "Could not update info (offline)")
|
|
|
|
self.assertTrue(offline_node.api_version == "", "API version is not set")
|
2016-10-24 18:34:37 +00:00
|
|
|
|
|
|
|
def test_auto_update_node_info(self):
|
|
|
|
online_node = ProcessingNode.objects.create(hostname="localhost", port=11223)
|
|
|
|
self.assertTrue(online_node.last_refreshed != None, "Last refreshed info is here (update_node_info() was called)")
|
2016-10-25 20:04:24 +00:00
|
|
|
|
2016-10-26 16:54:46 +00:00
|
|
|
def test_client_api(self):
|
|
|
|
api = ApiClient("localhost", 11223)
|
2016-10-25 20:04:24 +00:00
|
|
|
|
2016-10-26 16:54:46 +00:00
|
|
|
# Can call info(), options()
|
|
|
|
self.assertTrue(type(api.info()['version']) in [str, unicode])
|
|
|
|
self.assertTrue(len(api.options()) > 0)
|
|
|
|
|
|
|
|
# Can call new_task()
|
|
|
|
import glob
|
|
|
|
res = api.new_task(
|
|
|
|
glob.glob("nodeodm/fixtures/test_images/*.JPG"),
|
|
|
|
"test",
|
|
|
|
[{'name': 'cmvs-maxImages', 'value': 5}])
|
|
|
|
uuid = res['uuid']
|
|
|
|
self.assertTrue(uuid != None)
|
|
|
|
|
|
|
|
# Can call task_info()
|
|
|
|
task_info = api.task_info(uuid)
|
2016-10-26 20:56:32 +00:00
|
|
|
self.assertTrue(isinstance(task_info['dateCreated'], (int, long)))
|
|
|
|
self.assertTrue(isinstance(task_info['uuid'], (str, unicode)))
|