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:07:04 +00:00
|
|
|
from os import path, environ
|
2016-09-27 14:45:09 +00:00
|
|
|
from .models import ProcessingNode
|
|
|
|
from .api_client import ApiClient
|
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:07:04 +00:00
|
|
|
|
|
|
|
node_odm_dir = path.join(current_dir, "external", "node-OpenDroneMap")
|
|
|
|
cls.node_odm = subprocess.Popen(['node', 'index.js', '--port', '11223', '--test'],
|
|
|
|
shell=False,
|
|
|
|
cwd=node_odm_dir,
|
|
|
|
env=dict(environ, NODE_PATH=path.join(node_odm_dir, "node_modules")))
|
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)
|
|
|
|
self.assertTrue(api.info() == None)
|
|
|
|
self.assertTrue(api.options() == None)
|
|
|
|
|
|
|
|
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")
|
|
|
|
self.assertTrue(online_node.last_refreshed != 0, "Last refreshed not yet set")
|
|
|
|
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")
|
|
|
|
self.assertTrue(online_node.last_refreshed != 0, "Last refreshed is set")
|
|
|
|
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")
|
|
|
|
|
|
|
|
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")
|