Fix location of unit test files

Have unit test files be in the correct subdirectories.

Change two imports to not use: from ...

Change-Id: Ie93382f52c2ebe63a2b6f1af338ce3573014c4b1
This commit is contained in:
John L. Villalovos 2016-12-13 13:07:39 -08:00
parent 0fd581adf1
commit d6db2ec288
4 changed files with 39 additions and 54 deletions

View File

@ -13,17 +13,17 @@
# under the License.
import json
from unittest import TestCase
import unittest
from flask import Flask
import flask
from valence.common import utils
class TestMakeResponse(TestCase):
class TestMakeResponse(unittest.TestCase):
def setUp(self):
app = Flask(__name__)
app = flask.Flask(__name__)
self.app_context = app.test_request_context()
self.app_context.push()
@ -53,3 +53,38 @@ class TestMakeResponse(TestCase):
def test_make_response_with_wrong_headers(self):
with self.assertRaises(ValueError):
utils.make_response(200, headers=("header", "header_value"))
class TestUtils(unittest.TestCase):
def test_match_conditions(self):
filter_condition = {"Id": "1"}
json_content_pass = {"Name": "Pass",
"Id": "1"}
result = utils.match_conditions(json_content_pass,
filter_condition)
self.assertTrue(result)
json_content_fail = {"Name": "Fail",
"Id": "2"}
result = utils.match_conditions(json_content_fail,
filter_condition)
self.assertFalse(result)
json_content_fail_2 = {"Name": "Fail2"}
result = utils.match_conditions(json_content_fail_2,
filter_condition)
self.assertFalse(result)
def test_extract_val(self):
data = {"Name": "NoMembers", "Id": 1, "Path": {
"Level1": {"Level2": "L2"}}}
result = utils.extract_val(data, "Id")
self.assertEqual(result, 1)
result = utils.extract_val(data, "Id1")
self.assertEqual(result, None)
result = utils.extract_val(data, "Path/Level1/Level2")
self.assertEqual(result, "L2")
result = utils.extract_val(data, "Id1", "DEFAULTID")
self.assertEqual(result, "DEFAULTID")

View File

View File

@ -1,50 +0,0 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from unittest import TestCase
from valence.common import utils
class TestUtils(TestCase):
def test_match_conditions(self):
filter_condition = {"Id": "1"}
json_content_pass = {"Name": "Pass",
"Id": "1"}
result = utils.match_conditions(json_content_pass,
filter_condition)
self.assertTrue(result)
json_content_fail = {"Name": "Fail",
"Id": "2"}
result = utils.match_conditions(json_content_fail,
filter_condition)
self.assertFalse(result)
json_content_fail_2 = {"Name": "Fail2"}
result = utils.match_conditions(json_content_fail_2,
filter_condition)
self.assertFalse(result)
def test_extract_val(self):
data = {"Name": "NoMembers", "Id": 1, "Path": {
"Level1": {"Level2": "L2"}}}
result = utils.extract_val(data, "Id")
self.assertEqual(result, 1)
result = utils.extract_val(data, "Id1")
self.assertEqual(result, None)
result = utils.extract_val(data, "Path/Level1/Level2")
self.assertEqual(result, "L2")
result = utils.extract_val(data, "Id1", "DEFAULTID")
self.assertEqual(result, "DEFAULTID")