From f8907f0c4fc0ba4bb97a1d636a50c5b40c2642f2 Mon Sep 17 00:00:00 2001 From: Edan Binshtok Date: Wed, 4 Oct 2017 09:33:23 +0300 Subject: Initial seed Initial upload of django test framework Change-Id: I643a7f4efc52cfafe4cc6d92e3178f36a0c1837c Issue-Id: VVP-1 Signed-off-by: Edan Binshtok --- tests/signalTests/__init__.py | 38 +++ .../__pycache__/__init__.cpython-36.pyc | Bin 0 -> 145 bytes .../test_checklist_signal.cpython-36.pyc | Bin 0 -> 1392 bytes .../__pycache__/test_git_signal.cpython-36.pyc | Bin 0 -> 7892 bytes .../__pycache__/test_signal_base.cpython-36.pyc | Bin 0 -> 2218 bytes tests/signalTests/test_checklist_signal.py | 68 +++++ tests/signalTests/test_git_signal.py | 320 +++++++++++++++++++++ tests/signalTests/test_signal_base.py | 103 +++++++ 8 files changed, 529 insertions(+) create mode 100644 tests/signalTests/__init__.py create mode 100644 tests/signalTests/__pycache__/__init__.cpython-36.pyc create mode 100644 tests/signalTests/__pycache__/test_checklist_signal.cpython-36.pyc create mode 100644 tests/signalTests/__pycache__/test_git_signal.cpython-36.pyc create mode 100644 tests/signalTests/__pycache__/test_signal_base.cpython-36.pyc create mode 100644 tests/signalTests/test_checklist_signal.py create mode 100644 tests/signalTests/test_git_signal.py create mode 100644 tests/signalTests/test_signal_base.py (limited to 'tests/signalTests') diff --git a/tests/signalTests/__init__.py b/tests/signalTests/__init__.py new file mode 100644 index 0000000..30d7152 --- /dev/null +++ b/tests/signalTests/__init__.py @@ -0,0 +1,38 @@ + +# ============LICENSE_START========================================== +# org.onap.vvp/test-engine +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the “License”); +# you may not use this software 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. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# 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. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. diff --git a/tests/signalTests/__pycache__/__init__.cpython-36.pyc b/tests/signalTests/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..6b41906 Binary files /dev/null and b/tests/signalTests/__pycache__/__init__.cpython-36.pyc differ diff --git a/tests/signalTests/__pycache__/test_checklist_signal.cpython-36.pyc b/tests/signalTests/__pycache__/test_checklist_signal.cpython-36.pyc new file mode 100644 index 0000000..ef7bbfe Binary files /dev/null and b/tests/signalTests/__pycache__/test_checklist_signal.cpython-36.pyc differ diff --git a/tests/signalTests/__pycache__/test_git_signal.cpython-36.pyc b/tests/signalTests/__pycache__/test_git_signal.cpython-36.pyc new file mode 100644 index 0000000..7fc5eb1 Binary files /dev/null and b/tests/signalTests/__pycache__/test_git_signal.cpython-36.pyc differ diff --git a/tests/signalTests/__pycache__/test_signal_base.cpython-36.pyc b/tests/signalTests/__pycache__/test_signal_base.cpython-36.pyc new file mode 100644 index 0000000..4713d12 Binary files /dev/null and b/tests/signalTests/__pycache__/test_signal_base.cpython-36.pyc differ diff --git a/tests/signalTests/test_checklist_signal.py b/tests/signalTests/test_checklist_signal.py new file mode 100644 index 0000000..ae22578 --- /dev/null +++ b/tests/signalTests/test_checklist_signal.py @@ -0,0 +1,68 @@ + +# ============LICENSE_START========================================== +# org.onap.vvp/test-engine +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the “License”); +# you may not use this software 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. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# 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. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +''' +Created on 16 Nov 2016 +''' +from django.conf import settings + +from iceci.decorator.exception_decor import exception +from services.constants import Constants +from services.logging_service import LoggingServiceFactory +from services.types import API, DB +from tests.signalTests.test_signal_base import TestSignalBase + + +logger = LoggingServiceFactory.get_logger() + + +class TestChecklistSignal(TestSignalBase): + + @exception() + def test_archive_checklist_after_editing_files(self): + if settings.DATABASE_TYPE == 'local': + logger.debug("Local environment, skipping test...") + else: + user_content = API.VirtualFunction.create_engagement() + API.GitLab.git_clone_push(user_content, yaml=True) + token = "token " + API.User.login_user(user_content['el_email']) + user_content['session_token'] = token + cl_content = API.Checklist.retrieve_heat_checklist(user_content) + API.GitLab.git_push_commit(user_content, yaml=True) + DB.Checklist.state_changed( + "uuid", cl_content['uuid'], Constants.ChecklistStates.Archive.TEXT) diff --git a/tests/signalTests/test_git_signal.py b/tests/signalTests/test_git_signal.py new file mode 100644 index 0000000..d008787 --- /dev/null +++ b/tests/signalTests/test_git_signal.py @@ -0,0 +1,320 @@ + +# ============LICENSE_START========================================== +# org.onap.vvp/test-engine +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the “License”); +# you may not use this software 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. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# 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. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +''' +Created on 16 Nov 2016 + +''' +from django.conf import settings +from iceci.decorator.exception_decor import exception +from services.api.api_virtual_function import APIVirtualFunction +from services.constants import Constants, ServiceProvider +from services.logging_service import LoggingServiceFactory +from services.types import API +from tests.signalTests.test_signal_base import TestSignalBase +from services.helper import Helper + + +logger = LoggingServiceFactory.get_logger() + + +class TestGitSignal(TestSignalBase): + + @exception() + def test_create_eng(self): + + if settings.DATABASE_TYPE == 'local': + logger.debug("Local environment, skipping test...") + else: + user_content = API.VirtualFunction.create_engagement() + path_with_namespace = user_content[ + 'engagement_manual_id'] + "%2F" + user_content['vfName'] + API.GitLab.get_git_project(path_with_namespace) + if not API.GitLab.validate_git_project_members(path_with_namespace, user_content['el_email']): + logger.error("Couldn't find user in GitLab response.") + raise + logger.debug( + "Project was created successfully on GitLab. ELs included") + try: + job_name = user_content[ + 'vfName'] + "_" + user_content['engagement_manual_id'] + API.Jenkins.get_jenkins_job(job_name) + except Exception as e: + logger.error( + "_-_-_-_-_- Unexpected error in test_create_eng: " + str(e)) + raise Exception("Job wasnt created on APIJenkins." + str(e)) + + @exception() + def test_update_account(self): + + if settings.DATABASE_TYPE == 'local': + logger.debug("Local environment, skipping test...") + else: + user_content = API.VirtualFunction.create_engagement() + sshKey = API.User.update_account(user_content) + git_user = API.GitLab.get_git_user(user_content['email']) + git_user_pub_key = API.GitLab.get_git_user_ssh_key(git_user['id']) + if sshKey != git_user_pub_key: + logger.error( + "The SSH Key received does not equal to the one provided! The key from GitLab:\n" + git_user_pub_key) + raise + logger.debug( + "SSH Key for user " + user_content['full_name'] + " added to GitLab.") + + @exception() + def test_set_ssh(self): + + if settings.DATABASE_TYPE == 'local': + logger.debug("Local environment, skipping test...") + else: + user_content = API.VirtualFunction.create_engagement() + sshKey = API.User.set_ssh(user_content) + git_user = API.GitLab.get_git_user(user_content['email']) + git_user_pub_key = API.GitLab.get_git_user_ssh_key(git_user['id']) + if sshKey != git_user_pub_key: + logger.error( + "The SSH Key received does not equal to the one provided! The key from GitLab:\n" + git_user_pub_key) + raise + logger.debug( + "SSH Key for user " + user_content['full_name'] + " added to GitLab.") + + @exception() + def test_invite_member(self): + if settings.DATABASE_TYPE == 'local': + logger.debug("Local environment, skipping test...") + else: + user_content = API.VirtualFunction.create_engagement() + invited_email, invite_token, invite_url = API.VirtualFunction.invite_team_member( + user_content) + second_user = API.User.signup_invited_user( + user_content[ + 'vendor'], invited_email, invite_token, invite_url, + user_content, activate=True) + APIVirtualFunction.set_eng_stage( + user_content, Constants.EngagementStages.ACTIVE) + path_with_namespace = user_content[ + 'engagement_manual_id'] + "%2F" + user_content['vfName'] + if not API.GitLab.validate_git_project_members(path_with_namespace, user_content['email']): + raise Exception( + "Couldn't find the inviter user (%s) in GitLab." % user_content['email']) + if not API.GitLab.validate_git_project_members(path_with_namespace, second_user['email']): + raise Exception( + "Couldn't find the inviter user (%s) in GitLab." % second_user['email']) + logger.debug( + "Inviter and invited users were created successfully on GitLab!") + + @exception() + def test_add_contact(self): + if settings.DATABASE_TYPE == 'local': + logger.debug("Local environment, skipping test...") + else: + user_content = API.VirtualFunction.create_engagement() + APIVirtualFunction.set_eng_stage( + user_content, Constants.EngagementStages.ACTIVE) + path_with_namespace = user_content[ + 'engagement_manual_id'] + "%2F" + user_content['vfName'] + API.GitLab.get_git_project(path_with_namespace) + if not API.GitLab.validate_git_project_members(path_with_namespace, user_content['email']): + raise Exception( + "Couldn't find the inviter user (%s) in GitLab." % user_content['email']) + second_user_email, invite_token, invite_url = API.VirtualFunction.add_contact( + user_content) + second_user = API.User.signup_invited_user(ServiceProvider.MainServiceProvider, second_user_email, invite_token, invite_url, + user_content, "true", True) + if API.GitLab.validate_git_project_members(path_with_namespace, second_user_email): + logger.debug( + "Invited contact user " + second_user['full_name'] + " found in GitLab.") + else: + raise Exception("Couldn't find the invited user in GitLab.") + logger.debug( + "Inviter and invited users were created successfully on GitLab!") + + @exception() + def test_join_of_staff_users_to_new_gitlab_repo(self): + if settings.DATABASE_TYPE == 'local': + logger.debug("Local environment, skipping test...") + else: + user_content = API.VirtualFunction.create_engagement() + path_with_namespace = user_content[ + 'engagement_manual_id'] + "%2F" + user_content['vfName'] + eng_team_users_emails = [ + user_content['el_email'], user_content['pr_email'], Constants.Users.Admin.EMAIL] + API.GitLab.are_all_list_users_registered_as_project_members( + eng_team_users_emails, path_with_namespace) + logger.debug("Staff users were added successfully to GitLab repo!") + + @exception() + def test_join_of_stn_users_to_new_rep_after_active(self): + if settings.DATABASE_TYPE == 'local': + logger.debug("Local environment, skipping test...") + else: + user_content = API.VirtualFunction.create_engagement() + path_with_namespace = user_content[ + 'engagement_manual_id'] + "%2F" + user_content['vfName'] + # invite 2 new users in order to join standard users in the eng + # team + invited_email_address, invite_token, invite_url = API.VirtualFunction.invite_team_member( + user_content) + invited_email_address = API.User.signup_invited_user(user_content['vendor'], invited_email_address, + invite_token, invite_url, user_content) + + second_invited_email, second_invite_token, second_invite_url = API.VirtualFunction.invite_team_member( + user_content) + second_invited_email = API.User.signup_invited_user(user_content['vendor'], second_invited_email, + second_invite_token, second_invite_url, user_content) + + API.VirtualFunction.set_eng_stage( + user_content, Constants.EngagementStages.ACTIVE) + eng_team_users_emails = [invited_email_address['email'], second_invited_email['email'], + user_content['email'], user_content[ + 'el_email'], user_content['pr_email'], + Constants.Users.Admin.EMAIL] + + API.GitLab.are_all_list_users_registered_as_project_members( + eng_team_users_emails, path_with_namespace) + logger.debug( + "Staff, Inviter and invited users were added successfully to GitLab repo!") + + @exception() + def test_rem_users_from_repo_after_active_and_validated(self): + if settings.DATABASE_TYPE == 'local': + logger.debug("Local environment, skipping test...") + else: + user_content = API.VirtualFunction.create_engagement() + # invite 2 new users in order to join standard users in the eng + # team + invited_email_address, invite_token, invite_url = API.VirtualFunction.invite_team_member( + user_content) + invited_email_address = API.User.signup_invited_user( + user_content['vendor'], invited_email_address, invite_token, invite_url, user_content) + + second_invited_email, second_invite_token, second_invite_url = API.VirtualFunction.invite_team_member( + user_content) + second_invited_email = API.User.signup_invited_user( + user_content['vendor'], second_invited_email, second_invite_token, second_invite_url, user_content) + + # change eng stage in order to include all standard users in the + # eng git lab repo + API.VirtualFunction.set_eng_stage( + user_content, Constants.EngagementStages.ACTIVE) + API.VirtualFunction.set_eng_stage( + user_content, Constants.EngagementStages.VALIDATED) + path_with_namespace = user_content[ + 'engagement_manual_id'] + "%2F" + user_content['vfName'] + + # check that all standard users, staff users and admin are in the + # git lab repo + API.GitLab.get_git_project(path_with_namespace) + eng_team_users_emails = [user_content['el_email'], + user_content['pr_email'], Constants.Users.Admin.EMAIL] + should_not_be_in_repo_users_list = [ + invited_email_address['email'], user_content['email']] + for email in eng_team_users_emails: + if not API.GitLab.validate_git_project_members(path_with_namespace, email): + if email not in should_not_be_in_repo_users_list: + raise Exception( + "Couldn't find the invited users: " + email + " in GitLab.") + + logger.debug( + "Invited user: " + email + " and" + second_invited_email['full_name'] + " found in GitLab.") + logger.debug( + "Inviter and invited users were created successfully on GitLab!") + + @exception() + def test_rem_users_from_repo_after_completed(self): + if settings.DATABASE_TYPE == 'local': + logger.debug("Local environment, skipping test...") + else: + user_content = API.VirtualFunction.create_engagement() + # invite 2 new users in order to join standard users in the eng + # team + invited_email, invite_token, invite_url = API.VirtualFunction.invite_team_member( + user_content) + invited_email = API.User.signup_invited_user( + user_content['vendor'], invited_email, invite_token, invite_url, user_content) + + second_invited_email, second_invite_token, second_invite_url = API.VirtualFunction.invite_team_member( + user_content) + second_invited_email = API.User.signup_invited_user( + user_content['vendor'], second_invited_email, second_invite_token, second_invite_url, user_content) + + # change eng stage in order to include all standard users in the + # eng git lab repo + API.VirtualFunction.set_eng_stage( + user_content, Constants.EngagementStages.ACTIVE) + API.VirtualFunction.set_eng_stage( + user_content, Constants.EngagementStages.VALIDATED) + API.VirtualFunction.set_eng_stage( + user_content, Constants.EngagementStages.COMPLETED) + path_with_namespace = user_content[ + 'engagement_manual_id'] + "%2F" + user_content['vfName'] + + # check that all standard users, staff users and admin are in the + # git lab repo + API.GitLab.get_git_project(path_with_namespace) + eng_team_users_emails = [user_content['el_email'], + user_content['pr_email'], Constants.Users.Admin.EMAIL] + should_not_be_in_repo_users_list = [ + invited_email['email'], user_content['email']] + for email in eng_team_users_emails: + if not API.GitLab.validate_git_project_members(path_with_namespace, email): + if email not in should_not_be_in_repo_users_list: + raise Exception( + "Couldn't find the user: " + email + " in GitLab.") + + logger.debug( + "Invited user: " + email + " and" + second_invited_email['full_name'] + " found in GitLab.") + logger.debug( + "Inviter and invited users were created successfully on GitLab!") + + @exception() + def test_push_yaml_files_to_repo_check_decline_of_cl(self): + + if settings.DATABASE_TYPE == 'local': + logger.debug("Local environment, skipping test...") + else: + user_content = API.VirtualFunction.create_engagement() + token = "token " + API.User.login_user(user_content['el_email']) + user_content['session_token'] = token + cl_content_before_push_and_decline = API.Checklist.retrieve_heat_checklist( + user_content) + API.GitLab.git_clone_push(user_content, yaml=True) + cl_content_after_push_and_decline = API.Checklist.retrieve_heat_checklist( + user_content) + Helper.internal_not_equal( + cl_content_before_push_and_decline, cl_content_after_push_and_decline) diff --git a/tests/signalTests/test_signal_base.py b/tests/signalTests/test_signal_base.py new file mode 100644 index 0000000..6caade4 --- /dev/null +++ b/tests/signalTests/test_signal_base.py @@ -0,0 +1,103 @@ + +# ============LICENSE_START========================================== +# org.onap.vvp/test-engine +# =================================================================== +# Copyright © 2017 AT&T Intellectual Property. All rights reserved. +# =================================================================== +# +# Unless otherwise specified, all software contained herein is licensed +# under the Apache License, Version 2.0 (the “License”); +# you may not use this software 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. +# +# +# +# Unless otherwise specified, all documentation contained herein is licensed +# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# you may not use this documentation except in compliance with the License. +# You may obtain a copy of the License at +# +# https://creativecommons.org/licenses/by/4.0/ +# +# Unless required by applicable law or agreed to in writing, documentation +# 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. +# +# ============LICENSE_END============================================ +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +''' +Created on 15 Nov 2016 + +@author: tomerc +''' +import sys +from timeit import default_timer as timer +import unittest +import logging +import requests +from requests.packages.urllib3.exceptions import InsecureRequestWarning + +from iceci.decorator.logFuncEntry import logFuncEntry +from services.database.db_general import DBGeneral +from services.helper import Helper +from services.logging_service import LoggingServiceFactory +from services.session import session + + +requests.packages.urllib3.disable_warnings(InsecureRequestWarning) + + +logger = LoggingServiceFactory.get_logger() +stream_handler = logging.StreamHandler(sys.stdout) + + +class TestSignalBase(unittest.TestCase, Helper): + + def setUp(self): + logger.addHandler(stream_handler) + self.fullClassName = __name__ + self.className = self.__class__.__name__ + logger.debug("---------------------- TestCase " + + self.className + " ----------------------") + + self.startTime = timer() + self.funcName = self._testMethodName + self.testName = self.funcName + + def tearDown(self): + self.endTime = timer() + self.testDuration = str(self.endTime - self.startTime) + self.results() + logger.debug("---------------------- TestCase " + + self.className + " ----------------------\n\n") + try: + logging.getLogger().info("BB") + finally: + logger.removeHandler(stream_handler) + session.errorList = "" + session.errorCounter = 0 + + @logFuncEntry + def results(self): + params = {"testType": "E2E Test", "testFeature": self.className, + "testResult": "PASS", "testName": self.funcName, "duration": self.testDuration} + if (session.errorCounter == 0): + DBGeneral.insert_results(params["testType"], params["testFeature"], params[ + "testResult"], params["testName"], params['duration']) + else: + params["testResult"] = "FAIL" # Mark test as fail. + # Add the errors to notes column in table. + params["notes"] = session.errorList + DBGeneral.insert_results(params["testType"], params["testFeature"], params[ + "testResult"], params["testName"], params['duration'], params["notes"]) -- cgit 1.2.3-korg