diff options
author | Thomas Duval <thomas.duval@orange.com> | 2020-06-03 10:06:52 +0200 |
---|---|---|
committer | Thomas Duval <thomas.duval@orange.com> | 2020-06-03 10:06:52 +0200 |
commit | 7bb53c64da2dcf88894bfd31503accdd81498f3d (patch) | |
tree | 4310e12366818af27947b5e2c80cb162da93a4b5 /moon_manager/tests/performance_tests_policies/subjects.py | |
parent | cbea4e360e9bfaa9698cf7c61c83c96a1ba89b8c (diff) |
Update to new version 5.4HEADstable/jermamaster
Signed-off-by: Thomas Duval <thomas.duval@orange.com>
Change-Id: Idcd868133d75928a1ffd74d749ce98503e0555ea
Diffstat (limited to 'moon_manager/tests/performance_tests_policies/subjects.py')
-rw-r--r-- | moon_manager/tests/performance_tests_policies/subjects.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/moon_manager/tests/performance_tests_policies/subjects.py b/moon_manager/tests/performance_tests_policies/subjects.py new file mode 100644 index 00000000..cacf04c8 --- /dev/null +++ b/moon_manager/tests/performance_tests_policies/subjects.py @@ -0,0 +1,57 @@ +# Software Name: MOON + +# Version: 5.4 + +# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors +# SPDX-License-Identifier: Apache-2.0 + +# This software is distributed under the 'Apache License 2.0', +# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt' +# or see the "LICENSE" file for more details. + + +from locust import TaskSet, task +import json +import logging +from uuid import uuid4 +import utils + +LOGGER = logging.getLogger(__name__) + + +class SubjectRequests(TaskSet): + token = "" + + def on_start(self): + """ on_start is called when a Locust start before any task is scheduled """ + utils.login(self) + + def on_stop(self): + """ on_stop is called when the TaskSet is stopping """ + utils.logout(self) + + @task(10) + def subjects(self): + policy_id = utils.create_policy(self.client, self.token) + self.client.get("/subjects", headers={"X-Api-Key": self.token}) + perimeter_name = "test_subject_" + str(uuid4()) + req = self.client.post("/policies/{}/subjects".format(policy_id), + headers={"X-Api-Key": self.token}, + data={ + "name": perimeter_name, + "description": "locust test", + }) + content = json.loads(req.content.decode("utf-8")) + subject_id = None + for subject_id, subject_value in content.get("subjects", {}).items(): + if subject_value.get("name") == perimeter_name: + break + self.client.delete("/policies/{}/subjects/{}".format(policy_id, subject_id), + headers={"X-Api-Key": self.token}) + utils.delete_policy(self.client, self.token, policy_id) + + @task(1) + def status(self): + self.client.get("/status", headers={"X-Api-Key": self.token}) + + |