+++ /dev/null
-##############################################################################
-# Copyright (c) 2015 Orange
-# guyrodrigue.koffi@orange.com / koffirodrigue@gmail.com
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-DEFAULT_REPRESENTATION = "application/json"
-HTTP_BAD_REQUEST = 400
-HTTP_UNAUTHORIZED = 401
-HTTP_FORBIDDEN = 403
-HTTP_NOT_FOUND = 404
-HTTP_OK = 200
from datetime import datetime
import functools
+import httplib
import json
from tornado import gen
from tornado import web
import models
-from opnfv_testapi.common import constants
from opnfv_testapi.tornado_swagger import swagger
+DEFAULT_REPRESENTATION = "application/json"
+
class GenericApiHandler(web.RequestHandler):
def __init__(self, application, request, **kwargs):
if self.request.method != "GET" and self.request.method != "DELETE":
if self.request.headers.get("Content-Type") is not None:
if self.request.headers["Content-Type"].startswith(
- constants.DEFAULT_REPRESENTATION):
+ DEFAULT_REPRESENTATION):
try:
self.json_args = json.loads(self.request.body)
except (ValueError, KeyError, TypeError) as error:
- raise web.HTTPError(constants.HTTP_BAD_REQUEST,
+ raise web.HTTPError(httplib.BAD_REQUEST,
"Bad Json format [{}]".
format(error))
def finish_request(self, json_object=None):
if json_object:
self.write(json.dumps(json_object))
- self.set_header("Content-Type", constants.DEFAULT_REPRESENTATION)
+ self.set_header("Content-Type", DEFAULT_REPRESENTATION)
self.finish()
def _create_response(self, resource):
try:
token = self.request.headers['X-Auth-Token']
except KeyError:
- raise web.HTTPError(constants.HTTP_UNAUTHORIZED,
+ raise web.HTTPError(httplib.UNAUTHORIZED,
"No Authentication Header.")
query = {'access_token': token}
check = yield self._eval_db_find_one(query, 'tokens')
if not check:
- raise web.HTTPError(constants.HTTP_FORBIDDEN,
+ raise web.HTTPError(httplib.FORBIDDEN,
"Invalid Token.")
ret = yield gen.coroutine(method)(self, *args, **kwargs)
raise gen.Return(ret)
:param db_checks: [(table, exist, query, error)]
"""
if self.json_args is None:
- raise web.HTTPError(constants.HTTP_BAD_REQUEST, "no body")
+ raise web.HTTPError(httplib.BAD_REQUEST, "no body")
data = self.table_cls.from_dict(self.json_args)
for miss in miss_checks:
miss_data = data.__getattribute__(miss)
if miss_data is None or miss_data == '':
- raise web.HTTPError(constants.HTTP_BAD_REQUEST,
+ raise web.HTTPError(httplib.BAD_REQUEST,
'{} missing'.format(miss))
for k, v in kwargs.iteritems():
def _get_one(self, query):
data = yield self._eval_db_find_one(query)
if data is None:
- raise web.HTTPError(constants.HTTP_NOT_FOUND,
+ raise web.HTTPError(httplib.NOT_FOUND,
"[{}] not exist in table [{}]"
.format(query, self.table))
self.finish_request(self.format_data(data))
def _delete(self, query):
data = yield self._eval_db_find_one(query)
if data is None:
- raise web.HTTPError(constants.HTTP_NOT_FOUND,
+ raise web.HTTPError(httplib.NOT_FOUND,
"[{}] not exit in table [{}]"
.format(query, self.table))
@authenticate
def _update(self, query, db_keys):
if self.json_args is None:
- raise web.HTTPError(constants.HTTP_BAD_REQUEST, "No payload")
+ raise web.HTTPError(httplib.BAD_REQUEST, "No payload")
# check old data exist
from_data = yield self._eval_db_find_one(query)
if from_data is None:
- raise web.HTTPError(constants.HTTP_NOT_FOUND,
+ raise web.HTTPError(httplib.NOT_FOUND,
"{} could not be found in table [{}]"
.format(query, self.table))
if not equal:
to_data = yield self._eval_db_find_one(new_query)
if to_data is not None:
- raise web.HTTPError(constants.HTTP_FORBIDDEN,
+ raise web.HTTPError(httplib.FORBIDDEN,
"{} already exists in table [{}]"
.format(new_query, self.table))
request = self._update_request(request, k, v,
data.__getattribute__(k))
if not request:
- raise web.HTTPError(constants.HTTP_FORBIDDEN, "Nothing to update")
+ raise web.HTTPError(httplib.FORBIDDEN, "Nothing to update")
edit_request = data.format()
edit_request.update(request)
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+import httplib
+
import handlers
-from opnfv_testapi.common import constants
from opnfv_testapi.tornado_swagger import swagger
import pod_models
def error(data):
message = '{} already exists as a pod'.format(data.name)
- return constants.HTTP_FORBIDDEN, message
+ return httplib.FORBIDDEN, message
miss_checks = ['name']
db_checks = [(self.table, False, query, error)]
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+import httplib
+
import handlers
-from opnfv_testapi.common import constants
from opnfv_testapi.tornado_swagger import swagger
import project_models
def error(data):
message = '{} already exists as a project'.format(data.name)
- return constants.HTTP_FORBIDDEN, message
+ return httplib.FORBIDDEN, message
miss_checks = ['name']
db_checks = [(self.table, False, query, error)]
##############################################################################
from datetime import datetime
from datetime import timedelta
+import httplib
from bson import objectid
from tornado import web
-from opnfv_testapi.common import constants
from opnfv_testapi.resources import handlers
from opnfv_testapi.resources import result_models
from opnfv_testapi.tornado_swagger import swagger
try:
value = int(value)
except:
- raise web.HTTPError(constants.HTTP_BAD_REQUEST,
+ raise web.HTTPError(httplib.BAD_REQUEST,
'{} must be int'.format(key))
return value
def pod_error(data):
message = 'Could not find pod [{}]'.format(data.pod_name)
- return constants.HTTP_NOT_FOUND, message
+ return httplib.NOT_FOUND, message
def project_query(data):
return {'name': data.project_name}
def project_error(data):
message = 'Could not find project [{}]'.format(data.project_name)
- return constants.HTTP_NOT_FOUND, message
+ return httplib.NOT_FOUND, message
def testcase_query(data):
return {'project_name': data.project_name, 'name': data.case_name}
def testcase_error(data):
message = 'Could not find testcase [{}] in project [{}]'\
.format(data.case_name, data.project_name)
- return constants.HTTP_NOT_FOUND, message
+ return httplib.NOT_FOUND, message
miss_checks = ['pod_name', 'project_name', 'case_name']
db_checks = [('pods', True, pod_query, pod_error),
import functools
+import httplib
from tornado import web
-from opnfv_testapi.common import constants
from opnfv_testapi.resources import handlers
import opnfv_testapi.resources.scenario_models as models
from opnfv_testapi.tornado_swagger import swagger
def error(data):
message = '{} already exists as a scenario'.format(data.name)
- return constants.HTTP_FORBIDDEN, message
+ return httplib.FORBIDDEN, message
miss_checks = ['name']
db_checks = [(self.table, False, query, error)]
def _update_requests_rename(self, data):
data.name = self._term.get('name')
if not data.name:
- raise web.HTTPError(constants.HTTP_BAD_REQUEST,
+ raise web.HTTPError(httplib.BAD_REQUEST,
"new scenario name is not provided")
def _update_requests_add_installer(self, data):
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from opnfv_testapi.common import constants
+import httplib
+
from opnfv_testapi.resources import handlers
from opnfv_testapi.resources import testcase_models
from opnfv_testapi.tornado_swagger import swagger
def p_error(data):
message = 'Could not find project [{}]'.format(data.project_name)
- return constants.HTTP_FORBIDDEN, message
+ return httplib.FORBIDDEN, message
def tc_error(data):
message = '{} already exists as a testcase in project {}'\
.format(data.name, data.project_name)
- return constants.HTTP_FORBIDDEN, message
+ return httplib.FORBIDDEN, message
miss_checks = ['name']
db_checks = [(self.db_projects, True, p_query, p_error),
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+import httplib
import unittest
-from opnfv_testapi.common import constants
from opnfv_testapi.resources import pod_models
import test_base as base
class TestPodCreate(TestPodBase):
def test_withoutBody(self):
(code, body) = self.create()
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
def test_emptyName(self):
req_empty = pod_models.PodCreateRequest('')
(code, body) = self.create(req_empty)
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('name missing', body)
def test_noneName(self):
req_none = pod_models.PodCreateRequest(None)
(code, body) = self.create(req_none)
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('name missing', body)
def test_success(self):
code, body = self.create_d()
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assert_create_body(body)
def test_alreadyExist(self):
self.create_d()
code, body = self.create_d()
- self.assertEqual(code, constants.HTTP_FORBIDDEN)
+ self.assertEqual(code, httplib.FORBIDDEN)
self.assertIn('already exists', body)
class TestPodGet(TestPodBase):
def test_notExist(self):
code, body = self.get('notExist')
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
def test_getOne(self):
self.create_d()
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+import httplib
import unittest
-from opnfv_testapi.common import constants
from opnfv_testapi.resources import project_models
import test_base as base
class TestProjectCreate(TestProjectBase):
def test_withoutBody(self):
(code, body) = self.create()
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
def test_emptyName(self):
req_empty = project_models.ProjectCreateRequest('')
(code, body) = self.create(req_empty)
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('name missing', body)
def test_noneName(self):
req_none = project_models.ProjectCreateRequest(None)
(code, body) = self.create(req_none)
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('name missing', body)
def test_success(self):
(code, body) = self.create_d()
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assert_create_body(body)
def test_alreadyExist(self):
self.create_d()
(code, body) = self.create_d()
- self.assertEqual(code, constants.HTTP_FORBIDDEN)
+ self.assertEqual(code, httplib.FORBIDDEN)
self.assertIn('already exists', body)
class TestProjectGet(TestProjectBase):
def test_notExist(self):
code, body = self.get('notExist')
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
def test_getOne(self):
self.create_d()
code, body = self.get(self.req_d.name)
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assert_body(body)
def test_list(self):
class TestProjectUpdate(TestProjectBase):
def test_withoutBody(self):
code, _ = self.update(None, 'noBody')
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
def test_notFound(self):
code, _ = self.update(self.req_e, 'notFound')
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
def test_newNameExist(self):
self.create_d()
self.create_e()
code, body = self.update(self.req_e, self.req_d.name)
- self.assertEqual(code, constants.HTTP_FORBIDDEN)
+ self.assertEqual(code, httplib.FORBIDDEN)
self.assertIn("already exists", body)
def test_noUpdate(self):
self.create_d()
code, body = self.update(self.req_d, self.req_d.name)
- self.assertEqual(code, constants.HTTP_FORBIDDEN)
+ self.assertEqual(code, httplib.FORBIDDEN)
self.assertIn("Nothing to update", body)
def test_success(self):
req = project_models.ProjectUpdateRequest('newName', 'new description')
code, body = self.update(req, self.req_d.name)
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assertEqual(_id, body._id)
self.assert_body(body, req)
class TestProjectDelete(TestProjectBase):
def test_notFound(self):
code, body = self.delete('notFound')
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
def test_success(self):
self.create_d()
code, body = self.delete(self.req_d.name)
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assertEqual(body, '')
code, body = self.get(self.req_d.name)
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
if __name__ == '__main__':
unittest.main()
##############################################################################
import copy
from datetime import datetime, timedelta
+import httplib
import unittest
-from opnfv_testapi.common import constants
from opnfv_testapi.resources import pod_models
from opnfv_testapi.resources import project_models
from opnfv_testapi.resources import result_models
self.project)
def assert_res(self, code, result, req=None):
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
if req is None:
req = self.req_d
self.assertEqual(result.pod_name, req.pod_name)
class TestResultCreate(TestResultBase):
def test_nobody(self):
(code, body) = self.create(None)
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('no body', body)
def test_podNotProvided(self):
req = self.req_d
req.pod_name = None
(code, body) = self.create(req)
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('pod_name missing', body)
def test_projectNotProvided(self):
req = self.req_d
req.project_name = None
(code, body) = self.create(req)
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('project_name missing', body)
def test_testcaseNotProvided(self):
req = self.req_d
req.case_name = None
(code, body) = self.create(req)
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('case_name missing', body)
def test_noPod(self):
req = self.req_d
req.pod_name = 'notExistPod'
(code, body) = self.create(req)
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
self.assertIn('Could not find pod', body)
def test_noProject(self):
req = self.req_d
req.project_name = 'notExistProject'
(code, body) = self.create(req)
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
self.assertIn('Could not find project', body)
def test_noTestcase(self):
req = self.req_d
req.case_name = 'notExistTestcase'
(code, body) = self.create(req)
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
self.assertIn('Could not find testcase', body)
def test_success(self):
(code, body) = self.create_d()
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assert_href(body)
def test_key_with_doc(self):
req = copy.deepcopy(self.req_d)
req.details = {'1.name': 'dot_name'}
(code, body) = self.create(req)
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assert_href(body)
def test_no_ti(self):
criteria=self.criteria)
(code, res) = self.create(req)
_id = res.href.split('/')[-1]
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
code, body = self.get(_id)
self.assert_res(code, body, req)
def test_queryPeriodNotInt(self):
code, body = self.query(self._set_query('period=a'))
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('period must be int', body)
def test_queryPeriodFail(self):
def test_queryLastNotInt(self):
code, body = self.query(self._set_query('last=a'))
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('last must be int', body)
def test_queryLast(self):
req = self._create_changed_date(**kwargs)
code, body = self.query(query)
if not found:
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assertEqual(0, len(body.results))
else:
self.assertEqual(1, len(body.results))
from copy import deepcopy
from datetime import datetime
import functools
+import httplib
import json
import os
-from opnfv_testapi.common import constants
import opnfv_testapi.resources.scenario_models as models
import test_base as base
return res.href.split('/')[-1]
def assert_res(self, code, scenario, req=None):
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
if req is None:
req = self.req_d
self.assertIsNotNone(scenario._id)
class TestScenarioCreate(TestScenarioBase):
def test_withoutBody(self):
(code, body) = self.create()
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
def test_emptyName(self):
req_empty = models.ScenarioCreateRequest('')
(code, body) = self.create(req_empty)
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('name missing', body)
def test_noneName(self):
req_none = models.ScenarioCreateRequest(None)
(code, body) = self.create(req_none)
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('name missing', body)
def test_success(self):
(code, body) = self.create_d()
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assert_create_body(body)
def test_alreadyExist(self):
self.create_d()
(code, body) = self.create_d()
- self.assertEqual(code, constants.HTTP_FORBIDDEN)
+ self.assertEqual(code, httplib.FORBIDDEN)
self.assertIn('already exists', body)
def _query_and_assert(self, query, found=True, reqs=None):
code, body = self.query(query)
if not found:
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assertEqual(0, len(body.scenarios))
else:
self.assertEqual(len(reqs), len(body.scenarios))
def _update_and_assert(self, update_req, new_scenario, name=None):
code, _ = self.update(update_req, self.scenario)
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self._get_and_assert(_none_default(name, self.scenario),
new_scenario)
def _success(self, status, new_scenario):
- self.assertEqual(status, constants.HTTP_OK)
+ self.assertEqual(status, httplib.OK)
self._get_and_assert(new_scenario.get('name'), new_scenario)
def _forbidden(self, status, new_scenario):
- self.assertEqual(status, constants.HTTP_FORBIDDEN)
+ self.assertEqual(status, httplib.FORBIDDEN)
def _bad_request(self, status, new_scenario):
- self.assertEqual(status, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(status, httplib.BAD_REQUEST)
class TestScenarioDelete(TestScenarioBase):
def test_notFound(self):
code, body = self.delete('notFound')
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
def test_success(self):
scenario = self.create_return_name(self.req_d)
code, _ = self.delete(scenario)
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
code, _ = self.get(scenario)
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
def _none_default(check, default):
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import copy
+import httplib
import unittest
-from opnfv_testapi.common import constants
from opnfv_testapi.resources import project_models
from opnfv_testapi.resources import testcase_models
import test_base as base
class TestCaseCreate(TestCaseBase):
def test_noBody(self):
(code, body) = self.create(None, 'vping')
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
def test_noProject(self):
code, body = self.create(self.req_d, 'noProject')
- self.assertEqual(code, constants.HTTP_FORBIDDEN)
+ self.assertEqual(code, httplib.FORBIDDEN)
self.assertIn('Could not find project', body)
def test_emptyName(self):
req_empty = testcase_models.TestcaseCreateRequest('')
(code, body) = self.create(req_empty, self.project)
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('name missing', body)
def test_noneName(self):
req_none = testcase_models.TestcaseCreateRequest(None)
(code, body) = self.create(req_none, self.project)
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
self.assertIn('name missing', body)
def test_success(self):
code, body = self.create_d()
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assert_create_body(body, None, self.project)
def test_alreadyExist(self):
self.create_d()
code, body = self.create_d()
- self.assertEqual(code, constants.HTTP_FORBIDDEN)
+ self.assertEqual(code, httplib.FORBIDDEN)
self.assertIn('already exists', body)
class TestCaseGet(TestCaseBase):
def test_notExist(self):
code, body = self.get('notExist')
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
def test_getOne(self):
self.create_d()
code, body = self.get(self.req_d.name)
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assert_body(body)
def test_list(self):
class TestCaseUpdate(TestCaseBase):
def test_noBody(self):
code, _ = self.update(case='noBody')
- self.assertEqual(code, constants.HTTP_BAD_REQUEST)
+ self.assertEqual(code, httplib.BAD_REQUEST)
def test_notFound(self):
code, _ = self.update(self.update_e, 'notFound')
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
def test_newNameExist(self):
self.create_d()
self.create_e()
code, body = self.update(self.update_e, self.req_d.name)
- self.assertEqual(code, constants.HTTP_FORBIDDEN)
+ self.assertEqual(code, httplib.FORBIDDEN)
self.assertIn("already exists", body)
def test_noUpdate(self):
self.create_d()
code, body = self.update(self.update_d, self.req_d.name)
- self.assertEqual(code, constants.HTTP_FORBIDDEN)
+ self.assertEqual(code, httplib.FORBIDDEN)
self.assertIn("Nothing to update", body)
def test_success(self):
_id = body._id
code, body = self.update(self.update_e, self.req_d.name)
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assertEqual(_id, body._id)
self.assert_update_body(self.req_d, body, self.update_e)
update = copy.deepcopy(self.update_d)
update.description = {'2. change': 'dollar change'}
code, body = self.update(update, self.req_d.name)
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
class TestCaseDelete(TestCaseBase):
def test_notFound(self):
code, body = self.delete('notFound')
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
def test_success(self):
self.create_d()
code, body = self.delete(self.req_d.name)
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
self.assertEqual(body, '')
code, body = self.get(self.req_d.name)
- self.assertEqual(code, constants.HTTP_NOT_FOUND)
+ self.assertEqual(code, httplib.NOT_FOUND)
if __name__ == '__main__':
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
+import httplib
import unittest
from tornado import web
import fake_pymongo
-from opnfv_testapi.common import constants
from opnfv_testapi.resources import project_models
from opnfv_testapi.router import url_mappings
import test_base as base
def test_projectCreateTokenInvalid(self):
self.headers['X-Auth-Token'] = '1234'
code, body = self.create_d()
- self.assertEqual(code, constants.HTTP_FORBIDDEN)
+ self.assertEqual(code, httplib.FORBIDDEN)
self.assertIn('Invalid Token.', body)
def test_projectCreateTokenUnauthorized(self):
self.headers.pop('X-Auth-Token')
code, body = self.create_d()
- self.assertEqual(code, constants.HTTP_UNAUTHORIZED)
+ self.assertEqual(code, httplib.UNAUTHORIZED)
self.assertIn('No Authentication Header.', body)
def test_projectCreateTokenSuccess(self):
self.headers['X-Auth-Token'] = '12345'
code, body = self.create_d()
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
class TestTokenDeleteProject(TestToken):
self.create_d()
self.headers['X-Auth-Token'] = '1234'
code, body = self.delete(self.req_d.name)
- self.assertEqual(code, constants.HTTP_FORBIDDEN)
+ self.assertEqual(code, httplib.FORBIDDEN)
self.assertIn('Invalid Token.', body)
def test_projectDeleteTokenUnauthorized(self):
self.create_d()
self.headers.pop('X-Auth-Token')
code, body = self.delete(self.req_d.name)
- self.assertEqual(code, constants.HTTP_UNAUTHORIZED)
+ self.assertEqual(code, httplib.UNAUTHORIZED)
self.assertIn('No Authentication Header.', body)
def test_projectDeleteTokenSuccess(self):
self.headers['X-Auth-Token'] = '12345'
self.create_d()
code, body = self.delete(self.req_d.name)
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
class TestTokenUpdateProject(TestToken):
self.headers['X-Auth-Token'] = '1234'
req = project_models.ProjectUpdateRequest('newName', 'new description')
code, body = self.update(req, self.req_d.name)
- self.assertEqual(code, constants.HTTP_FORBIDDEN)
+ self.assertEqual(code, httplib.FORBIDDEN)
self.assertIn('Invalid Token.', body)
def test_projectUpdateTokenUnauthorized(self):
self.headers.pop('X-Auth-Token')
req = project_models.ProjectUpdateRequest('newName', 'new description')
code, body = self.update(req, self.req_d.name)
- self.assertEqual(code, constants.HTTP_UNAUTHORIZED)
+ self.assertEqual(code, httplib.UNAUTHORIZED)
self.assertIn('No Authentication Header.', body)
def test_projectUpdateTokenSuccess(self):
code, body = self.get(self.req_d.name)
req = project_models.ProjectUpdateRequest('newName', 'new description')
code, body = self.update(req, self.req_d.name)
- self.assertEqual(code, constants.HTTP_OK)
+ self.assertEqual(code, httplib.OK)
if __name__ == '__main__':
unittest.main()