mirror of
https://github.com/ansible/awx.git
synced 2026-05-16 05:47:38 -02:30
Unit Testing
Looking at protractor as a possible option. It does end-to-end testing, which may be redundant with QA's work, but it may also be exactly what's needed.
This commit is contained in:
@@ -73,7 +73,7 @@ function($rootScope, $compile, CreateDialog, Store, LicenseUpdateForm, GenerateF
|
|||||||
else if (this.getRemainingDays(license.time_remaining) < 15) {
|
else if (this.getRemainingDays(license.time_remaining) < 15) {
|
||||||
title = "License Warning";
|
title = "License Warning";
|
||||||
html = "<div id=\"license-notification-body\"><div style=\"margin-top:5px; margin-bottom:25px;\"><p>Thank you for using Ansible Tower. The Ansible Tower license " +
|
html = "<div id=\"license-notification-body\"><div style=\"margin-top:5px; margin-bottom:25px;\"><p>Thank you for using Ansible Tower. The Ansible Tower license " +
|
||||||
"has " + this.getRemainingDays(license.time_remaining) + " remaining. Once the license expires you will no longer be able to add managed hosts or run playbooks.</p>" +
|
"has " + this.getRemainingDays(license.time_remaining) + " days remaining. Once the license expires you will no longer be able to add managed hosts or run playbooks.</p>" +
|
||||||
"<p>Extend your Ansible Tower license by visiting <a href=\"ansible.com/license\" target=\"_blank\">ansible.com/license</a>.";
|
"<p>Extend your Ansible Tower license by visiting <a href=\"ansible.com/license\" target=\"_blank\">ansible.com/license</a>.";
|
||||||
}
|
}
|
||||||
else if (license.free_instances <= 0) {
|
else if (license.free_instances <= 0) {
|
||||||
|
|||||||
23
awx/ui/tests/e2e/CheckLicense.js
Normal file
23
awx/ui/tests/e2e/CheckLicense.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/**********************************
|
||||||
|
* Copyright (c) 2014 AnsibleWorks, Inc.
|
||||||
|
*
|
||||||
|
* CheckLicense.js
|
||||||
|
*
|
||||||
|
* Tests the CheckLicense service- helpers/CheckLicense.js
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* global describe, it, expect, browser */
|
||||||
|
|
||||||
|
|
||||||
|
describe('E2E:CheckLicense', function() {
|
||||||
|
it('should present login dialog', function() {
|
||||||
|
browser.get('http://localhost:8013');
|
||||||
|
var msg = $('#login-modal .login-alert:eq(1)');
|
||||||
|
expect(msg.getText()).toMatch(/Please sign in/);
|
||||||
|
|
||||||
|
/*element(by.model('login_username')).sendKeys('admin');
|
||||||
|
element(by.model('login_password')).sendKeys('password');
|
||||||
|
element(by.id('login-button')).click();*/
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -9,6 +9,7 @@ module.exports = function(config) {
|
|||||||
// list of files / patterns to load in the browser
|
// list of files / patterns to load in the browser
|
||||||
conf.files = conf.files.concat([
|
conf.files = conf.files.concat([
|
||||||
'../static/lib/angular-mocks/angular-mocks.js',
|
'../static/lib/angular-mocks/angular-mocks.js',
|
||||||
|
'../../../node_modules/ng-midway-tester/src/ngMidwayTester.js',
|
||||||
'./unit/*'
|
'./unit/*'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
4
awx/ui/tests/protractor-e2e.conf
Normal file
4
awx/ui/tests/protractor-e2e.conf
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
exports.config = {
|
||||||
|
seleniumAddress: 'http://localhost:4444/wd/hub',
|
||||||
|
specs: ['e2e/*.js']
|
||||||
|
}
|
||||||
@@ -7,15 +7,59 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
describe('Unit:CheckLicense', function() {
|
/* global describe, it, beforeEach, expect, module, inject */
|
||||||
|
|
||||||
var scope;
|
var licenses = [{
|
||||||
|
desc: 'expired license with < 1 day grace period',
|
||||||
|
valid_key: true,
|
||||||
|
time_remaining: 0,
|
||||||
|
grace_period_remaining: 85000,
|
||||||
|
free_instances: 10,
|
||||||
|
expects: 'grace period has been exceeded'
|
||||||
|
}, {
|
||||||
|
desc: 'expired license with > 1 day grace period',
|
||||||
|
valid_key: true,
|
||||||
|
time_remaining: 0,
|
||||||
|
grace_period_remaining: (86400 * 2),
|
||||||
|
free_instances: 10,
|
||||||
|
expects: 'after 2 days'
|
||||||
|
}, {
|
||||||
|
desc: 'valid license with time remaining = 15 days',
|
||||||
|
valid_key: true,
|
||||||
|
time_remaining: (86400 * 15),
|
||||||
|
grace_period_remaining: 0,
|
||||||
|
free_instances: 10,
|
||||||
|
expects: 'license is valid'
|
||||||
|
}, {
|
||||||
|
desc: 'valid license with time remaining < 15 days',
|
||||||
|
valid_key: true,
|
||||||
|
time_remaining: (86400 * 10) ,
|
||||||
|
grace_period_remaining: 0,
|
||||||
|
free_instances: 10,
|
||||||
|
expects: 'license has 10 days remaining'
|
||||||
|
}, {
|
||||||
|
desc: 'valid license with time remaining > 15 days and remaining hosts > 0',
|
||||||
|
valid_key: true,
|
||||||
|
time_remaining: (86400 * 20),
|
||||||
|
free_instances: 10,
|
||||||
|
grace_period_remaining: 0,
|
||||||
|
expects: 'license is valid'
|
||||||
|
}, {
|
||||||
|
desc: 'valid license with time remaining > 15 days and remaining hosts = 0',
|
||||||
|
valid_key: true,
|
||||||
|
time_remaining: (86400 * 20) ,
|
||||||
|
grace_period_remaining: 0,
|
||||||
|
free_instances: 0,
|
||||||
|
expects: 'license has reached capacity'
|
||||||
|
}];
|
||||||
|
|
||||||
|
describe('Unit:CheckLicense', function() {
|
||||||
|
|
||||||
beforeEach(module('Tower'));
|
beforeEach(module('Tower'));
|
||||||
|
|
||||||
beforeEach(inject(function($rootScope) {
|
/*beforeEach(inject(function($rootScope) {
|
||||||
scope = $rootScope.$new();
|
scope = $rootScope.$new();
|
||||||
}));
|
}));*/
|
||||||
|
|
||||||
it('should contain CheckLicense service', inject(function(CheckLicense) {
|
it('should contain CheckLicense service', inject(function(CheckLicense) {
|
||||||
expect(CheckLicense).not.toBe(null);
|
expect(CheckLicense).not.toBe(null);
|
||||||
@@ -25,4 +69,34 @@ describe('Unit:CheckLicense', function() {
|
|||||||
expect(CheckLicense.getRemainingDays).not.toBe(null);
|
expect(CheckLicense.getRemainingDays).not.toBe(null);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('should have a getHTML method', inject(function(CheckLicense) {
|
||||||
|
expect(CheckLicense.getHTML).not.toBe(null);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should have a getAdmin method', inject(function(CheckLicense) {
|
||||||
|
expect(CheckLicense.getAdmin).not.toBe(null);
|
||||||
|
}));
|
||||||
|
|
||||||
|
licenses.forEach(function(lic) {
|
||||||
|
it(lic.desc, inject(function(CheckLicense) {
|
||||||
|
var r = new RegExp(lic.expects);
|
||||||
|
expect(CheckLicense.getHTML(lic).body).toMatch(r);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should recognize empty license as invalid', inject(function(CheckLicense) {
|
||||||
|
expect(CheckLicense.getHTML({}).title).toMatch(/license required/i);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should show license update form to admin users when license is invalid', inject(function(CheckLicense, $rootScope) {
|
||||||
|
$rootScope.current_user = {};
|
||||||
|
$rootScope.current_user.is_superuser = true;
|
||||||
|
expect(CheckLicense.getHTML({}).body).toMatch(/license\_license\_json/);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should not show license update form to non-admin users when license is invalid', inject(function(CheckLicense, $rootScope) {
|
||||||
|
$rootScope.current_user = {};
|
||||||
|
$rootScope.current_user.is_superuser = false;
|
||||||
|
expect(CheckLicense.getHTML({}).body).not.toMatch(/license\_license\_json/);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user