mock object for tests Signed-off-by: Imesh Gunaratne <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/0c5b93cf Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/0c5b93cf Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/0c5b93cf Branch: refs/heads/stratos-4.1.x Commit: 0c5b93cf480a2ab79dcbf02bebfba08d418d8761 Parents: 9e86406 Author: Milindu Sanoj Kumarage <[email protected]> Authored: Mon Aug 17 11:07:07 2015 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Tue Oct 13 16:32:50 2015 +0530 ---------------------------------------------------------------------- .../python/tests/test_printable_tree_print.py | 98 +++++++++++++++++--- 1 file changed, 87 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/0c5b93cf/components/org.apache.stratos.python.cli/src/main/python/tests/test_printable_tree_print.py ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.python.cli/src/main/python/tests/test_printable_tree_print.py b/components/org.apache.stratos.python.cli/src/main/python/tests/test_printable_tree_print.py index 2a38603..d22139b 100644 --- a/components/org.apache.stratos.python.cli/src/main/python/tests/test_printable_tree_print.py +++ b/components/org.apache.stratos.python.cli/src/main/python/tests/test_printable_tree_print.py @@ -15,8 +15,9 @@ # specific language governing permissions and limitations # under the License. -import sys -from cli import Utils +from cli import Stratos +from cli import Configs +import responses class TestClass: @@ -25,14 +26,89 @@ class TestClass: pass @staticmethod - def test_zero(): - i = 1 - assert i == 1 + @responses.activate + def test_http_get_handler_on_200(): + responses.add(responses.GET, Configs.stratos_api_url, + body='{"keyOne": "valueOne"}', status=200, + content_type='application/json') + + r = Stratos.get("") + + assert r == {"keyOne": "valueOne"} + + @staticmethod + @responses.activate + def test_http_get_handler_on_400(): + responses.add(responses.GET, Configs.stratos_api_url, + body='', status=400, + content_type='application/json') + + r = Stratos.get("") + + assert r == {"keyOne": "valueOne"} + + @staticmethod + @responses.activate + def test_http_get_handler_on_200(): + responses.add(responses.GET, Configs.stratos_api_url, + body='{"keyOne": "valueOne"}', status=200, + content_type='application/json') + + r = Stratos.get("") + + assert r == {"keyOne": "valueOne"} + + @staticmethod + @responses.activate + def test_http_get_handler_on_200(): + responses.add(responses.GET, Configs.stratos_api_url, + body='{"keyOne": "valueOne"}', status=200, + content_type='application/json') + + r = Stratos.get("") + + assert r == {"keyOne": "valueOne"} @staticmethod - def test_one(): - tree = Utils.PrintableTree( - """[{"id":"network-partition-2","partitions":[{"id":"partition-2","partitionMax":0,"property":[{"name":"region","value":"default"}],"public":false},{"id":"partition-3","partitionMax":0,"property":[{"name":"region","value":"default"}],"public":false}]},{"id":"network-partition-1","partitions":[{"id":"partition-1","partitionMax":0,"property":[{"name":"region","value":"default"}],"public":false}]}]""") - tree.print_tree() - output = sys.stdout.getline().strip() # because stdout is an StringIO instance - assert output == 'hello world!' + @responses.activate + def test_http_get_handler_on_200(): + responses.add(responses.GET, Configs.stratos_api_url, + body='{"keyOne": "valueOne"}', status=200, + content_type='application/json') + + r = Stratos.get("") + + assert r == {"keyOne": "valueOne"} + + @staticmethod + @responses.activate + def test_http_get_handler_on_200(): + responses.add(responses.GET, Configs.stratos_api_url, + body='{"keyOne": "valueOne"}', status=200, + content_type='application/json') + + r = Stratos.get("") + + assert r == {"keyOne": "valueOne"} + + @staticmethod + @responses.activate + def test_http_get_handler_on_200(): + responses.add(responses.GET, Configs.stratos_api_url, + body='{"keyOne": "valueOne"}', status=200, + content_type='application/json') + + r = Stratos.get("") + + assert r == {"keyOne": "valueOne"} + + @staticmethod + @responses.activate + def test_http_get_handler_on_200(): + responses.add(responses.GET, Configs.stratos_api_url, + body='{"keyOne": "valueOne"}', status=200, + content_type='application/json') + + r = Stratos.get("") + + assert r == {"keyOne": "valueOne"}
