##############################################################################
import json
-from tornado.web import Application
-from tornado.testing import AsyncHTTPTestCase
+from tornado import testing
+from tornado import web
-from opnfv_testapi.router import url_mappings
-from opnfv_testapi.resources.models import CreateResponse
import fake_pymongo
+from opnfv_testapi.resources import models
+from opnfv_testapi.router import url_mappings
-class TestBase(AsyncHTTPTestCase):
+class TestBase(testing.AsyncHTTPTestCase):
headers = {'Content-Type': 'application/json; charset=UTF-8'}
def setUp(self):
self.basePath = ''
- self.create_res = CreateResponse
+ self.create_res = models.CreateResponse
self.get_res = None
self.list_res = None
self.update_res = None
super(TestBase, self).setUp()
def get_app(self):
- return Application(
+ return web.Application(
url_mappings.mappings,
db=fake_pymongo,
debug=True,
+ auth=False
)
def create_d(self, *args):
return self.create_help(self.basePath, req, *args)
def create_help(self, uri, req, *args):
- if req:
+ if req and not isinstance(req, str) and hasattr(req, 'format'):
req = req.format()
res = self.fetch(self._update_uri(uri, *args),
method='POST',
return uri.count('%s')
def _get_query_uri(self, query):
- return self.basePath + '?' + query
+ return self.basePath + '?' + query if query else self.basePath
def _get_uri(self, *args):
return self._update_uri(self.basePath, *args)
self.assertIn(self.basePath, body.href)
def assert_create_body(self, body, req=None, *args):
+ import inspect
if not req:
req = self.req_d
- new_args = args + tuple([req.name])
+ resource_name = ''
+ if inspect.isclass(req):
+ resource_name = req.name
+ elif isinstance(req, dict):
+ resource_name = req['name']
+ elif isinstance(req, str):
+ resource_name = json.loads(req)['name']
+ new_args = args + tuple([resource_name])
self.assertIn(self._get_uri(*new_args), body.href)
@staticmethod
fake_pymongo.projects.clear()
fake_pymongo.testcases.clear()
fake_pymongo.results.clear()
+ fake_pymongo.scenarios.clear()