From 090d5d1f1e4dec57f76671e5b1ab5a3cf4b9eeaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Fran=C3=A7oise?= Date: Fri, 16 Sep 2016 15:51:09 +0200 Subject: [PATCH] Added Tempest API tests for /scoring_engines In this changeset, I added tempest tests for the scoring engine endpoint. Change-Id: I7f36250eb9df437b518d20fd4f2e1feb223f3c82 --- .../services/infra_optim/v1/json/client.py | 21 ++++++ .../tests/api/admin/test_goal.py | 6 +- .../tests/api/admin/test_scoring_engine.py | 66 +++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 watcher_tempest_plugin/tests/api/admin/test_scoring_engine.py diff --git a/watcher_tempest_plugin/services/infra_optim/v1/json/client.py b/watcher_tempest_plugin/services/infra_optim/v1/json/client.py index be3446839..c2f132ac0 100644 --- a/watcher_tempest_plugin/services/infra_optim/v1/json/client.py +++ b/watcher_tempest_plugin/services/infra_optim/v1/json/client.py @@ -280,6 +280,27 @@ class InfraOptimClientJSON(base.BaseInfraOptimClient): """ return self._show_request('/strategies', strategy) + # ### SCORING ENGINE ### # + + @base.handle_errors + def list_scoring_engines(self, **kwargs): + """List all existing scoring_engines""" + return self._list_request('/scoring_engines', **kwargs) + + @base.handle_errors + def list_scoring_engines_detail(self, **kwargs): + """Lists details of all existing scoring_engines""" + return self._list_request('/scoring_engines/detail', **kwargs) + + @base.handle_errors + def show_scoring_engine(self, scoring_engine): + """Gets a specific scoring_engine + + :param scoring_engine: UUID or Name of the scoring_engine + :return: Serialized scoring_engine as a dictionary + """ + return self._show_request('/scoring_engines', scoring_engine) + # ### SERVICES ### # @base.handle_errors diff --git a/watcher_tempest_plugin/tests/api/admin/test_goal.py b/watcher_tempest_plugin/tests/api/admin/test_goal.py index 1d6a7cbb5..194dcac27 100644 --- a/watcher_tempest_plugin/tests/api/admin/test_goal.py +++ b/watcher_tempest_plugin/tests/api/admin/test_goal.py @@ -40,7 +40,11 @@ class TestShowListGoal(base.BaseInfraOptimTest): _, goal = self.client.show_goal(self.DUMMY_GOAL) self.assertEqual(self.DUMMY_GOAL, goal['name']) - self.assertIn("display_name", goal.keys()) + expected_fields = { + 'created_at', 'deleted_at', 'display_name', + 'efficacy_specification', 'links', 'name', + 'updated_at', 'uuid'} + self.assertEqual(expected_fields, set(goal.keys())) @test.attr(type='smoke') def test_show_goal_with_links(self): diff --git a/watcher_tempest_plugin/tests/api/admin/test_scoring_engine.py b/watcher_tempest_plugin/tests/api/admin/test_scoring_engine.py new file mode 100644 index 000000000..600a24b5e --- /dev/null +++ b/watcher_tempest_plugin/tests/api/admin/test_scoring_engine.py @@ -0,0 +1,66 @@ +# -*- encoding: utf-8 -*- +# Copyright (c) 2016 b<>com +# +# 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 __future__ import unicode_literals + +from tempest import test + +from watcher_tempest_plugin.tests.api.admin import base + + +class TestShowListScoringEngine(base.BaseInfraOptimTest): + """Tests for scoring engines""" + + DUMMY_SCORING_ENGINE = "dummy_scorer" + + @classmethod + def resource_setup(cls): + super(TestShowListScoringEngine, cls).resource_setup() + + def assert_expected(self, expected, actual, + keys=('created_at', 'updated_at', 'deleted_at')): + super(TestShowListScoringEngine, self).assert_expected( + expected, actual, keys) + + @test.attr(type='smoke') + def test_show_scoring_engine(self): + _, scoring_engine = self.client.show_scoring_engine( + self.DUMMY_SCORING_ENGINE) + + self.assertEqual(self.DUMMY_SCORING_ENGINE, scoring_engine['name']) + + expected_fields = {'metainfo', 'description', 'name', 'uuid', 'links'} + self.assertEqual(expected_fields, set(scoring_engine.keys())) + + @test.attr(type='smoke') + def test_show_scoring_engine_with_links(self): + _, scoring_engine = self.client.show_scoring_engine( + self.DUMMY_SCORING_ENGINE) + self.assertIn('links', scoring_engine.keys()) + self.assertEqual(2, len(scoring_engine['links'])) + self.assertIn(scoring_engine['uuid'], + scoring_engine['links'][0]['href']) + + @test.attr(type="smoke") + def test_list_scoring_engines(self): + _, body = self.client.list_scoring_engines() + self.assertIn(self.DUMMY_SCORING_ENGINE, + [i['name'] for i in body['scoring_engines']]) + + # Verify self links. + for scoring_engine in body['scoring_engines']: + self.validate_self_link('scoring_engines', scoring_engine['uuid'], + scoring_engine['links'][0]['href'])