"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "monasca_api/tests/test_helpers.py" between
monasca-api-3.0.0.tar.gz and monasca-api-3.1.0.tar.gz

About: OpenStack Monasca API is a RESTful API server that is designed with a layered architecture and supports Monitoring as a Service (MONaaS).
The "Train" series (latest release).

test_helpers.py  (monasca-api-3.0.0):test_helpers.py  (monasca-api-3.1.0)
skipping to change at line 15 skipping to change at line 15
# a copy of the License at # a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from falcon import errors
from falcon import testing from falcon import testing
from monasca_common.policy import policy_engine as policy
from oslo_policy import policy as os_policy from oslo_policy import policy as os_policy
from monasca_api.api.core import request from monasca_api.api.core import request
from monasca_api.common.policy import policy_engine as policy
from monasca_api.tests import base from monasca_api.tests import base
import monasca_api.v2.reference.helpers as helpers import monasca_api.v2.reference.helpers as helpers
from monasca_common.rest import utils as rest_utils
class TestHelpersFunction(base.BaseTestCase):
def test_from_json(self):
body_json = {'test_body': 'test'}
req = request.Request(
testing.create_environ(
body=rest_utils.as_json(body_json),
)
)
response = helpers.from_json(req)
self.assertEqual(body_json, response)
def test_from_json_incorrect_message(self):
req = request.Request(
testing.create_environ(
body='incorrect message',
)
)
self.assertRaises(errors.HTTPBadRequest, helpers.from_json, req)
def test_to_json(self):
test_dict = {'test_body': 'test'}
expected_json = '{"test_body":"test"}'
response = helpers.to_json(test_dict)
self.assertEqual(expected_json, response)
def test_validate_json_content_type(self):
req = request.Request(
testing.create_environ(
headers={'Content-Type': 'application/json'}
)
)
helpers.validate_json_content_type(req)
def test_validate_json_content_type_incorrect_content_type(self):
req = request.Request(
testing.create_environ(
headers={'Content-Type': 'multipart/form-data'}
)
)
self.assertRaises(errors.HTTPBadRequest, helpers.validate_json_content_t
ype, req)
def test_validate_json_content_type_missing_content_type(self):
req = request.Request(testing.create_environ())
self.assertRaises(errors.HTTPBadRequest, helpers.validate_json_content_t
ype, req)
class TestGetXTenantOrTenantId(base.BaseApiTestCase): class TestGetXTenantOrTenantId(base.BaseApiTestCase):
def setUp(self): def setUp(self):
super(TestGetXTenantOrTenantId, self).setUp() super(TestGetXTenantOrTenantId, self).setUp()
rules = [ rules = [
os_policy.RuleDefault("example:allowed", "@"), os_policy.RuleDefault("example:allowed", "@"),
os_policy.RuleDefault("example:denied", "!"), os_policy.RuleDefault("example:denied", "!"),
os_policy.RuleDefault("example:authorized", os_policy.RuleDefault("example:authorized",
"role:role_1 or role:role_2") "role:role_1 or role:role_2")
] ]
policy.reset() policy.reset()
 End of changes. 4 change blocks. 
1 lines changed or deleted 52 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)