diff options
-rw-r--r-- | testapi/3rd_party/static/testapi-ui/assets/css/style.css | 2 | ||||
-rw-r--r-- | testapi/docker/Dockerfile | 2 | ||||
-rw-r--r-- | testapi/docs/developer/devguide/images/CAS-sequence.jpg | bin | 0 -> 11785 bytes | |||
-rw-r--r-- | testapi/docs/developer/devguide/web-portal.rst | 114 | ||||
-rw-r--r-- | testapi/opnfv_testapi/tests/UI/e2e/testCasesControllerSpec.js | 25 | ||||
-rw-r--r-- | testapi/opnfv_testapi/ui/components/projects/project/testCases/testCases.html | 16 | ||||
-rw-r--r-- | testapi/opnfv_testapi/ui/components/projects/project/testCases/testCasesController.js | 68 | ||||
-rw-r--r-- | testapi/testapi-client/testapiclient/tests/unit/test_app.py | 50 | ||||
-rw-r--r-- | testapi/testapi-client/testapiclient/tests/unit/utils.py | 4 |
9 files changed, 233 insertions, 48 deletions
diff --git a/testapi/3rd_party/static/testapi-ui/assets/css/style.css b/testapi/3rd_party/static/testapi-ui/assets/css/style.css index 222911c..2b20d6b 100644 --- a/testapi/3rd_party/static/testapi-ui/assets/css/style.css +++ b/testapi/3rd_party/static/testapi-ui/assets/css/style.css @@ -303,7 +303,7 @@ json-tree .leaf-value{ border-radius: 10px; padding: 16px; position: fixed; - z-index: 1; + z-index: 9999; left: 50%; bottom: 30px; } diff --git a/testapi/docker/Dockerfile b/testapi/docker/Dockerfile index bbf12fc..86999d9 100644 --- a/testapi/docker/Dockerfile +++ b/testapi/docker/Dockerfile @@ -40,7 +40,7 @@ python-pip \ crudini \ --no-install-recommends -RUN pip install --upgrade pip requests +RUN pip install --upgrade requests RUN git config --global http.sslVerify false RUN git clone https://gerrit.opnfv.org/gerrit/releng-testresults /home/releng-testresults diff --git a/testapi/docs/developer/devguide/images/CAS-sequence.jpg b/testapi/docs/developer/devguide/images/CAS-sequence.jpg Binary files differnew file mode 100644 index 0000000..a624871 --- /dev/null +++ b/testapi/docs/developer/devguide/images/CAS-sequence.jpg diff --git a/testapi/docs/developer/devguide/web-portal.rst b/testapi/docs/developer/devguide/web-portal.rst index 62b2f17..8c4bc6c 100644 --- a/testapi/docs/developer/devguide/web-portal.rst +++ b/testapi/docs/developer/devguide/web-portal.rst @@ -6,5 +6,115 @@ Web portal ========== -.. toctree:: - :maxdepth: 2 +**Web-portal of OPNFV Testapi**: + +This project aims to provide the web interface for the Testapi framework. It uses the Restful APIs +of the testapi framework to provide front-end functionalities. + +If you are interested in how TestAPI looks like, please visit OPNFV's official `TestAPI Server`__ + +.. __: http://testresults.opnfv.org/test + +Pre-requsites +============= + +In the web portal, we are using AngularJS(1.3.15) as the frontend framework with Bootstrap(v3) CSS. + +Running locally +=============== + +Installation +^^^^^^^^^^^^ + +Web portal will be installed with the testapi framework. No extra installation. + +.. code-block:: shell + + python setup.py install + +Start Server +^^^^^^^^^^^^ + +.. code-block:: shell + + *opnfv-testapi [--config-file <config.ini>]* + +If --config-file is provided, the specified configuration file will be employed +when starting the server, or else /etc/opnfv_testapi/config.ini will be utilized +by default. + +After executing the command successfully, a TestAPI server will be started on +port 8000, to visit web portal, please access http://hostname:8000 + +Test +=============== + +There are few external requirements for the testing. +They are + +1. npm : node package manager + you can get the installation package for nodejs from the official `website`__ + + .. __: https://nodejs.org/en/ + +2. grunt cli : Automation tool + +.. code-block:: shell + + npm install -g grunt-cli + +After installing global dependencies, you have to install the required local node modules. + +.. code-block:: shell + + npm install + +**Running tests** + +.. code-block:: shell + + grunt e2e + +Authentication +============== + +The web portal is using Linux identity server as the Central Authentication Service. The following +diagram will explain the authentication process. + +.. image:: /images/CAS-sequence.jpg + :width: 600 + :alt: Workflow of the Athentication + +When a new user initially logs into an application they won't have established a +session with the application. Instead of displaying a login form asking for the username and +password, the application (via the CAS Client) will redirect the browser to the linux foundation +login page. Linux foundation identity server then authenticates the user. If the authentication +fails, the Linux foundation login page is displayed again with an error message. So until +authentication succeeds, the user will not be returned to the application. + +Authorization +============= + +TestAPI has 3 level authorization layer. They are + +**Public** + +The public can view the resources(pod, project, testcase, result, deploy result, scenario). +They do not have the access to create, delete or modify the resources. + +**User - Contributors** + +Contributors level user can view all the resources(pod, project, testcase, result, deploy result, +scenario). They can create/delete/modify pod and scenario. + +They do not have the access to create project or testcase. + +**User - Submitter** + +Submitter level user can view all the resources(pod, project, testcase, result, deploy result, +scenario). They can create/delete/modify pod and scenario. + +If user want to create/modify/delete a project or testcase then user has to be in the Submitter +group for that specific project. + +Currently, we can't create/modify/delete results or deploy results from the web portal.
\ No newline at end of file diff --git a/testapi/opnfv_testapi/tests/UI/e2e/testCasesControllerSpec.js b/testapi/opnfv_testapi/tests/UI/e2e/testCasesControllerSpec.js index 53e7bdf..38e0f24 100644 --- a/testapi/opnfv_testapi/tests/UI/e2e/testCasesControllerSpec.js +++ b/testapi/opnfv_testapi/tests/UI/e2e/testCasesControllerSpec.js @@ -550,8 +550,11 @@ describe('testing the test cases page for user who is in submitter group', funct name.sendKeys('test'); var buttonOK = element(by.buttonText('Ok')); buttonOK.click(); - expect(element(by.cssContainingText(".alert","Testcase is successfully created.")) + browser.ignoreSynchronization = true; + expect(element(by.cssContainingText(".success.show","Testcase is successfully created.")) .isDisplayed()).toBe(true); + browser.sleep(500); + browser.ignoreSynchronization = false; }); it('Showing error when creating with a empty name ', function () { @@ -565,8 +568,11 @@ describe('testing the test cases page for user who is in submitter group', funct browser.wait(EC.visibilityOf(name), 5000); var buttonOK = element(by.buttonText('Ok')); buttonOK.click(); - expect(element(by.cssContainingText(".alert","Name is missing.")) + browser.ignoreSynchronization = true; + expect(element(by.cssContainingText(".error.show","Name is missing.")) .isDisplayed()).toBe(true); + browser.sleep(500); + browser.ignoreSynchronization = false; }); it('cancel the delete confimation modal of the test case ', function () { @@ -590,8 +596,11 @@ describe('testing the test cases page for user who is in submitter group', funct deleteOperation.click(); var buttonOK = element(by.buttonText('Ok')); buttonOK.click(); - expect(element(by.cssContainingText(".alert","Test case is successfully deleted")) + browser.ignoreSynchronization = true; + expect(element(by.cssContainingText(".success.show","Test case is successfully deleted")) .isDisplayed()).toBe(true); + browser.sleep(500); + browser.ignoreSynchronization = false; }); it('cancel the Edit modal of the test case ', function () { @@ -621,8 +630,11 @@ describe('testing the test cases page for user who is in submitter group', funct name.sendKeys('test1'); var buttonOK = element(by.buttonText('Ok')); buttonOK.click(); - expect(element(by.cssContainingText(".alert","Test case is successfully updated")) + browser.ignoreSynchronization = true; + expect(element(by.cssContainingText(".success.show","Test case is successfully updated")) .isDisplayed()).toBe(true); + browser.sleep(500); + browser.ignoreSynchronization = false; }); it('view the test case ', function () { @@ -646,7 +658,10 @@ describe('testing the test cases page for user who is in submitter group', funct buttonDelete.click(); var buttonOK = element(by.buttonText('Ok')); buttonOK.click(); - expect(element(by.cssContainingText(".alert","Test case is successfully deleted")) + browser.ignoreSynchronization = true; + expect(element(by.cssContainingText(".success.show","Test case is successfully deleted")) .isDisplayed()).toBe(true); + browser.sleep(500); + browser.ignoreSynchronization = false; }); }) diff --git a/testapi/opnfv_testapi/ui/components/projects/project/testCases/testCases.html b/testapi/opnfv_testapi/ui/components/projects/project/testCases/testCases.html index 395db03..04baa9c 100644 --- a/testapi/opnfv_testapi/ui/components/projects/project/testCases/testCases.html +++ b/testapi/opnfv_testapi/ui/components/projects/project/testCases/testCases.html @@ -11,16 +11,12 @@ <i class="fa fa-plus"></i> Create</button> </div> </div> - <div class='clo-md-12'> - <div ng-show="testCasesCtrl.showError" class="alert alert-danger" role="alert"> - <span class="pull-right"> {{testCasesCtrl.error}}</span> - <span class="glyphicon glyphicon-exclamation-sign pull-right" aria-hidden="true" >Error:</span> - </div> - <div ng-show="testCasesCtrl.showSuccess" class="alert alert-success" role="alert"> - <span class="pull-right"> {{testCasesCtrl.successMessage}}</span> - <span class="glyphicon glyphicon-ok pull-right" aria-hidden="true"></span> - </div> - </div> + <div ng-class="{'show': testCasesCtrl.showError}" id="toast" class="error"> + <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true" ></span> + {{testCasesCtrl.error}}</div> + <div ng-class="{'show': testCasesCtrl.showSuccess}" id="toast" class="success"> + <span class="glyphicon glyphicon-ok" aria-hidden="true"></span> + {{testCasesCtrl.success}}</div> <div class='clo-md-12' style="padding-right:0px"> <div class="table-responsive"> <table class="table table-bordered table-hover" ng-data="testCasesCtrl.data.testcases"> diff --git a/testapi/opnfv_testapi/ui/components/projects/project/testCases/testCasesController.js b/testapi/opnfv_testapi/ui/components/projects/project/testCases/testCasesController.js index 4d6153e..ea0498a 100644 --- a/testapi/opnfv_testapi/ui/components/projects/project/testCases/testCasesController.js +++ b/testapi/opnfv_testapi/ui/components/projects/project/testCases/testCasesController.js @@ -21,7 +21,7 @@ TestCasesController.$inject = [ '$scope', '$http', '$filter', '$state', '$window', '$uibModal', 'testapiApiUrl','raiseAlert', - 'confirmModal', 'authenticate' + 'confirmModal', 'authenticate', '$timeout' ]; /** @@ -31,7 +31,7 @@ * in them. */ function TestCasesController($scope, $http, $filter, $state, $window, $uibModal, testapiApiUrl, - raiseAlert, confirmModal, authenticate) { + raiseAlert, confirmModal, authenticate, $timeout) { var ctrl = this; ctrl.loadDetails = loadDetails; ctrl.name = $state.params['name']; @@ -49,29 +49,40 @@ ctrl.checkBox = []; ctrl.checkBoxList = []; + ctrl.toastError = toastError + ctrl.toastSuccess = toastSuccess + + function toastError() { + ctrl.showError = true + $timeout(function(){ ctrl.showError = false;}, 3000); + } + + function toastSuccess() { + ctrl.showSuccess = true + $timeout(function(){ ctrl.showSuccess = false;}, 3000); + } /** * This will contact the TestAPI to create a new test case. */ function createTestCase(name, testcase) { - ctrl.showError = false; - ctrl.showSuccess = false; if(testcase.name != "" && testcase.name!=null){ var testCase_url = ctrl.requestUrl; - ctrl.testCasesRequest = - $http.post(testCase_url, testcase).success(function (data){ - ctrl.showSuccess = true ; - ctrl.successMessage = "Testcase is successfully created." + ctrl.testCasesRequest = $http.post(testCase_url, testcase) + ctrl.testCasesRequest.success(function (data){ + ctrl.success = "Testcase is successfully created." loadDetails(); + ctrl.toastSuccess() }) .catch(function (data) { - ctrl.showError = true; ctrl.error = data.statusText; + ctrl.toastError(); }); + return ctrl.testCasesRequest; } else{ - ctrl.showError = true; ctrl.error = 'Name is missing.' + ctrl.toastError(); } } @@ -114,24 +125,23 @@ * This will contact the TestAPI to update an existing test case. */ function updateTestCase(name, testCase) { - ctrl.showError = false; - ctrl.showSuccess = false; if(testCase.name != ""){ var testCase_url = ctrl.requestUrl + '/' + name; - ctrl.testCasesRequest = - $http.put(testCase_url, testCase).success(function (data){ - ctrl.showSuccess = true ; - ctrl.successMessage = "Test case is successfully updated" + ctrl.testCasesRequest = $http.put(testCase_url, testCase) + ctrl.testCasesRequest.success(function (data){ + ctrl.success = "Test case is successfully updated" loadDetails(); + ctrl.toastSuccess(); }) .catch(function (data) { - ctrl.showError = true; ctrl.error = data.statusText; + ctrl.toastError() }); + return ctrl.testCasesRequest; } else{ - ctrl.showError = true; ctrl.error = 'Name is missing.' + ctrl.toastError() } } @@ -139,16 +149,14 @@ * This will contact the TestAPI to delete an existing test case. */ function deleteTestCase(name) { - ctrl.showError = false; - ctrl.showSuccess = false; ctrl.testCasesRequest = $http.delete(ctrl.requestUrl+"/"+name).success(function (data) { loadDetails(); - ctrl.showSuccess = true ; - ctrl.successMessage = "Test case is successfully deleted" + ctrl.success = "Test case is successfully deleted"; + ctrl.toastSuccess(); }).catch(function (error) { - ctrl.showError = true; - ctrl.error = data.statusText; + ctrl.error = error.statusText; + ctrl.toastError(); }); } @@ -218,8 +226,8 @@ ctrl.data = data; }).catch(function (error) { ctrl.data = null; - ctrl.showError = true; ctrl.error = error.statusText; + ctrl.toastError() }); } ctrl.loadDetails(); @@ -271,9 +279,15 @@ * inputs. */ function confirm() { - $uibModalInstance.close(); if (angular.isDefined(ctrl.data.successHandler)) { - ctrl.data.successHandler(ctrl.name, ctrl.testcase); + if(ctrl.testcase.name){ + ctrl.data.successHandler(ctrl.name, ctrl.testcase).success( function(){ + $uibModalInstance.close(); + }) + } + else{ + ctrl.data.successHandler(ctrl.name, ctrl.testcase) + } } } diff --git a/testapi/testapi-client/testapiclient/tests/unit/test_app.py b/testapi/testapi-client/testapiclient/tests/unit/test_app.py new file mode 100644 index 0000000..c20b27f --- /dev/null +++ b/testapi/testapi-client/testapiclient/tests/unit/test_app.py @@ -0,0 +1,50 @@ +import urllib + +from mock import mock + +from testapiclient import main +from testapiclient.tests.unit import utils +from testapiclient.tests.unit import fakes + + +class MainTest(utils.TestCommand): + def setUp(self): + super(MainTest, self).setUp() + self.app = main.TestAPIClient() + self.cas_sever = '{}{}{}'.format( + self.env_variables['testapi_cas_auth_url'], + urllib.quote(self.env_variables['testapi_url']), + self.env_variables['testapi_cas_signin_return']) + self.headers = { + 'Content-type': 'application/json', + 'Accept': 'text/plain'} + + def test_auth_success(self): + self.post_mock.return_value = fakes.FakeResponse( + data={'text': "success"}) + self.app.run( + ['-u', 'user', '-p', 'pass', 'pod', 'create', + '{"name": "asfad"}']) + self.post_mock.assert_called_with( + 'http://localhost:8000/api/v1/pods', + data='{"name": "asfad"}', + headers=self.headers) + + def test_auth_failure(self): + self.post_mock.return_value = fakes.FakeResponse( + data={'text': "login"}) + self.app.run( + ['-u', 'user', '-p', 'pass', 'pod', 'create', + '{"name": "asfad"}']) + self.post_mock.assert_called_once_with( + self.cas_sever, + {'pass': 'pass', 'name': 'user', 'form_id': 'user_login'} + ) + + def test_auth_not_called(self): + self.auth_post = mock.patch( + 'testapiclient.utils.clientmanager.ClientManager.auth').start() + self.app.run(['pod', 'get']) + self.auth_post.assert_not_called() + self.get_mock.assert_called_once_with( + 'http://localhost:8000/api/v1/pods', headers=self.headers) diff --git a/testapi/testapi-client/testapiclient/tests/unit/utils.py b/testapi/testapi-client/testapiclient/tests/unit/utils.py index 21f98c4..c59aadd 100644 --- a/testapi/testapi-client/testapiclient/tests/unit/utils.py +++ b/testapi/testapi-client/testapiclient/tests/unit/utils.py @@ -19,7 +19,7 @@ class TestCommand(testtools.TestCase): def setUp(self): super(TestCommand, self).setUp() - env_variables = { + self.env_variables = { 'testapi_url': 'http://localhost:8000/api/v1', 'testapi_cas_auth_url': ( @@ -29,7 +29,7 @@ class TestCommand(testtools.TestCase): 'testapi_cas_signin_return': '/auth/signin_return' } self.config_mock = mock.patch.dict( - 'os.environ', env_variables).start() + 'os.environ', self.env_variables).start() self.fake_stdout = fakes.FakeStdout() self.fake_log = fakes.FakeLog() self.app = fakes.FakeApp(self.fake_stdout, self.fake_log) |