Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS unit tests and smoke test #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ virtualenv:
system_site_packages: false

install:
- npm install casperjs
- pip install -r requirements-dev.txt
- git clone https://github.com/Isilon/isilon_sdk_7_2_python.git
- cd isilon_sdk_7_2_python
Expand Down
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ tags:
$(HEXAPARSE) stat_key_browser/data/key_cats.hexa > stat_key_browser/data/key_cats.json

lint:
$(PYLINT) -E -f colorized -r n stat_key_browser bin/ tests/
$(PYLINT) -E -f colorized -r n stat_key_browser build_stat_browser.py tests/

unittests: lint
$(PYTHON) -m pytest -v tests/unit/ *.py

coverage: lint
$(PYTHON) -m pytest -v --cov=stat_key_browser --cov-report term-missing --cov-config tests/unit/.coveragerc tests/unit/ *.py

travis-ci: tags lint
$(PYTHON) -m pytest -v tests/unit/ hexaparse.py
travis-ci: tags unittests jsunittests

check_cluster:
if [ -z $$BUILD_BROWSER_ARGS ]; then echo BUILD_BROWSER_ARGS not set, builder will pause for input; fi
Expand All @@ -47,3 +46,12 @@ dist: check_cluster clean unittests tags
cp -r stat_key_browser $(DIST_DIR)
cp -r web_app $(DIST_DIR)
zip -r isilon_stat_browser_$(BROWSER_VERS_STRING).zip dist/*

jsunittests:
casperjs test web_app/js/tests/unit_app_filter_lib.js \
--includes=web_app/js/app_filter_lib.js,web_app/js/app_lib.js
casperjs test web_app/js/tests/unit_app_lib.js --includes=web_app/js/app_lib.js
casperjs test web_app/js/tests/unit_app_papi_link.js --includes=web_app/js/app_papi_link.js

jstests: dist jsunittests
casperjs test web_app/js/tests/smoke.js
18 changes: 12 additions & 6 deletions README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Python: 2.7, 3.3, 3.4, 3.5

Dependencies listed in requirements-dev.txt

Isilon SDK Python language bindings
Isilon SDK [Python language bindings](https://github.com/isilon)

[`https://github.com/isilon/`](https://github.com/isilon)
[CasperJS](http://casperjs.org) 1.1 or later

##Development getting started

Expand All @@ -27,6 +27,13 @@ Isilon SDK Python language bindings

`pip install -r requirements-dev.txt`

#### Install CasperJS 1.1 or later
`npm install -g casperjs`

Or on Mac:

`brew install casperjs --devel`

### Run unit tests:

`make unittests`
Expand All @@ -35,10 +42,9 @@ Isilon SDK Python language bindings

`make coverage`

### Run functional tests:
The functional tests are only a stub currently.
### Run JavaScript tests:

`make functional_tests`
`make jstests`

###Run the page building tool
First, convert the tagging data to JSON. This step creates stat\_key\_browser/data/key\_tags.json and stat\_key\_browser/data/key\_cats.json
Expand Down Expand Up @@ -133,4 +139,4 @@ Contains a template representing a single key and all of its info, including its

* `web_app/index.html`

This is the file opened by the user to view the stat browser. This file is rendered by build_stat_browser.py from the templates, the definitions in key_tags.json and from the PAPI supplied list of keys.
This is the file opened by the user to view the stat browser. This file is rendered by build\_stat\_browser.py from the templates, the definitions in key_tags.json and from the PAPI supplied list of keys.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ The script will prompt you for a username and password, and will create the brow
You can use the SDK Python language bindings to automate the configuration, maintenance, and monitoring of your Isilon cluster. For information on how to install the Python language bindings and write Python scripts to access the OneFS API, refer to the following Github sites:

[`https://github.com/Isilon/isilon_sdk_7_2_python`](https://github.com/Isilon/isilon_sdk_7_2_python)

[`https://github.com/Isilon/isilon_sdk_8_0_python`](https://github.com/Isilon/isilon_sdk_8_0_python)


Expand Down
2 changes: 1 addition & 1 deletion stat_key_browser/templates/app_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h1 class="col-md-12">EMC | Isilon OneFS Statistics</h1>
{% endfor %}
</ul>
</div>
<input class="btn btn-default" type="reset" value="Reset" onclick="reset_search()">
<input id="resetButton" class="btn btn-default" type="reset" value="Reset" onclick="reset_search()">
</div>
</form>
</div>
Expand Down
File renamed without changes.
Empty file added tests/functional/__init__.py
Empty file.
Empty file added tests/unit/__init__.py
Empty file.
25 changes: 10 additions & 15 deletions tests/unit/test_categorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,18 @@ def cat(self):
@pytest.fixture
def key_dict(self):
"""Return a key_dict."""
key_dict_3= {
"node.sensor.power.A": {},
"node.sensor.power.B": {},
"node.sensor.altitude.A": {},
"node.sensor.altitude.B": {},
"node.protostats.smb1": {},
"node.protostats.smb2": {},
"node.protostats.smb3": {},
"node.sensor.walrus.tusk": {}
}
key_dict_3 = {
"node.sensor.power.A": {},
"node.sensor.power.B": {},
"node.sensor.altitude.A": {},
"node.sensor.altitude.B": {},
"node.protostats.smb1": {},
"node.protostats.smb2": {},
"node.protostats.smb3": {},
"node.sensor.walrus.tusk": {}
}
return key_dict_3


def assert_is_string(self, subject):
assert isinstance(subject, (str, unicode))


def test_categorizer_init_00(self, cat):
categorizer = Categorizer(cat)
assert len(categorizer.cat_defs) == len(cat)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_cluster_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
class TestClusterConfig(object):

@patch('stat_key_browser.cluster_config._get_cluster_version')
def test_0_get_cluster_release(self, get_cluster_version):
def test_0_get_cluster_release_1(self, get_cluster_version):
get_cluster_version.return_value = '2.0'
results = cluster_config.get_release('4.3.2.1', 'u', 'p')
assert results == '2.0'

@patch('stat_key_browser.cluster_config._get_cluster_version')
def test_0_get_cluster_release(self, get_cluster_version):
def test_0_get_cluster_release_2(self, get_cluster_version):
get_cluster_version.return_value = '1.0'
results = cluster_config.get_release('4.3.2.1', 'u', 'p')
assert results == '1.0'
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_tagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def test_get_arb_attrs_01(self):

defin = {'re-keys': ['g', 'h'], 'tags': ['a', 'b'], 'arb': ['arbarb']}
result = tg._get_extra_attrs(defin)
assert result == {'arb': 'arbarb'}
assert result == {'arb': ['arbarb']}

def test_get_arb_attrs_01(self):
def test_get_arb_attrs_02(self):
tg = Tagger([{'re-keys': ['g', 'h'], 'tags': ['a', 'b']}])

defin = {'re-keys': ['g', 'h'], 'tags': ['a', 'b'], 'arb': ['arbarb', 'arbTWO']}
Expand Down
10 changes: 10 additions & 0 deletions web_app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ $( document ).ready(function() {
captureLength: 2
}
$('#text_filter').typeWatch(options)

// Setup PAPI links
$('.papi_demo').click(papi_link_clicked)
$('#modal_cluster_save').click(save_cluster_ip)
$('#modal_cluster').on('shown.bs.modal', function () {$('#text_cluster').focus()})
cluster_ip = keyDict['cluster']['host']
if (cluster_ip != null) {
// Populate PAPI links if IP is known
update_papi_links(keyDict['cluster']['host'])
}
});
2 changes: 1 addition & 1 deletion web_app/js/app_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function dedupe_array(a) {
var deduped = [];
for (var i=0; i< a.length; i++) {
if (!hashes[a[i]]) {
hashes[a] = true
hashes[a[i]] = true
deduped.push(a[i])
}
}
Expand Down
13 changes: 1 addition & 12 deletions web_app/js/app_papi_link.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
var cluster_ip = null
var clicked_link = null

$(document).ready(function () {
$('.papi_demo').click(papi_link_clicked)
$('#modal_cluster_save').click(save_cluster_ip)
$('#modal_cluster').on('shown.bs.modal', function () {$('#text_cluster').focus()})
cluster_ip = keyDict['cluster']['host']
if (cluster_ip != null) {
// Populate PAPI links if IP is known
update_papi_links(keyDict['cluster']['host'])
}
});

function papi_link_clicked() {
if (cluster_ip == null) {
clicked_link = $(this)
Expand Down Expand Up @@ -52,7 +41,7 @@ function update_papi_link(endpoint) {
function antisquash_key(key) {
// If a key ends in .N, convert the N to 1
if (key.endsWith('.N')) {
key = key.replace(/\.N$/, '.1')
key = key.replace(/\.N$/, '.1')
}
return key
}
Expand Down
32 changes: 32 additions & 0 deletions web_app/js/tests/smoke.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Smoke tests for Isilon Stat Browser
//
// Loads index.html into a phantomjs browser
// verify page title is set
// verify title text is displayed
// verify search box is displayed
// Verfiy reset button is displayed
// verify tags button is displayed
// verify top-level categories are visible
// verify category sub-contents are not visible
// verify individual keys are not visible

/*
To run the tests:
casperjs test web_app/js/tests/smoke.js
*/

casper.test.begin('Smoke Test', 8, function suite(test) {
casper.start('web_app/index.html', function() {
test.assertTitle('EMC | Isilon OneFS Statistics', 'page title is set')
test.assertSelectorHasText('h1.col-md-12', 'EMC | Isilon OneFS Statistics', 'title text is displayed');
test.assertVisible('#text_filter', 'search box is displayed')
test.assertVisible('#resetButton', 'reset button is displayed')
test.assertVisible('#tagDropdown', 'tags dropdown is displayed')
test.assertVisible('div.category_main', 'top-level categories are visible')
test.assertNotVisible('div.subcontents', 'category sub-contents are not visible')
test.assertNotVisible('div.key_main', 'individual keys are not visible')

}).run(function() {
test.done();
});
});
64 changes: 64 additions & 0 deletions web_app/js/tests/unit_app_filter_lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// unit tests for app_filter_lib.js

/*
To run the tests:
casperjs test web_app/js/tests/unit_app_filter_lib.js \
--includes=web_app/js/app_filter_lib.js,web_app/js/app_lib.js
*/

casper.test.begin('app_filter_lib', 18, function suite(test) {

// parse_search_terms //
var results = parse_search_terms('one two')
test.assertEquals(results.length, 2, 'two terms are parsed');

var results = parse_search_terms(' one two ')
test.assertEquals(results.length, 2, 'excess whitespace is discarded');
test.assertEquals(results[0], 'one', 'first term is parsed')
test.assertEquals(results[1], 'two', 'seconds term is parsed')

var results = parse_search_terms('or and not')
test.assertEquals(results.length, 3, 'logical operators are not discarded');

var results = parse_search_terms('AbCd')
test.assertEquals(results[0], 'abcd', 'case is normalized');


// match_key //
var key = new Object()
key.search_terms = ['a', 'b', 'c']

test.assert(match_key(key, ['a']), 'match a single search term')
test.assert(match_key(key, ['a', 'b']), 'match two search terms')
test.assert(match_key(key, ['a', 'b', 'c']), 'match three search terms')

test.assertFalsy(match_key(key, ['z']), 'non-match a single search term')
test.assertFalsy(match_key(key, ['z', 'y']), 'non-match two search term')
test.assertFalsy(match_key(key, ['a', 'y']), 'partial matches returns false')


// parse_subsearches //
results = parse_subsearches(['a', 'or', 'b'])
test.assertEquals(results.length, 2, 'a or b is split into 2 subsearches')

results = parse_subsearches(['a', 'and', 'b'])
test.assertEquals(results.length, 1, 'a and b is left as single subsearch')

results = parse_subsearches(['a', 'and', 'b'])
test.assertEquals(results.length, 1, 'a b is left as single subsearch')


// list_matching_keys //
keys = {'aaa': {'search_terms': ['aaa']}, 'bbb': {'search_terms': ['bbb']}}

results = list_matching_keys('aaa', keys)
test.assertEqual(results[0], 'aaa', 'aaa: key match single term')

results = list_matching_keys('aaa or bbb', keys)
test.assertEqual(results.length, 2, 'aaa or bbb: keys match 2 terms')

results = list_matching_keys('aaa and bbb', keys)
test.assertEqual(results.length, 0, 'aaa and bbb: match neither term')

test.done();
});
28 changes: 28 additions & 0 deletions web_app/js/tests/unit_app_lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// unit tests for app_lib.js

/*
To run the tests:
casperjs test web_app/js/tests/unit_app_lib.js --includes=web_app/js/app_lib.js
*/

casper.test.begin('app_lib.js', 5, function suite(test) {

// dedupe_array //
var results = dedupe_array(['a'])
test.assertEquals(results, ['a'], 'dedupe_array: single array item is returned');

var results = dedupe_array(['a', 'a'])
test.assertEquals(results, ['a'], 'dedupe_array: a, a');

var results = dedupe_array(['a', 'b'])
test.assertEquals(results, ['a', 'b'], 'dedupe_array: a, b');

var results = dedupe_array(['a', 'a', 'c'])
test.assertEquals(results, ['a', 'c'], 'dedupe_array: a, a, c');

var results = dedupe_array(['a', 'a', 'b', 'b'])
test.assertEquals(results, ['a', 'b'], 'dedupe_array: a, a, b, b');

test.done();

});
30 changes: 30 additions & 0 deletions web_app/js/tests/unit_app_papi_link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// unit tests for app_papi_link.js

/*
To run the tests:
casperjs test web_app/js/tests/unit_app_papi_link.js --includes=web_app/js/app_papi_link.js
*/

// Polyfill for phantomjs
if (!String.prototype.endsWith) {
String.prototype.endsWith = function(searchString, position) {
var subjectString = this.toString();
if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) {
position = subjectString.length;
}
position -= searchString.length;
var lastIndex = subjectString.indexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
};
}

casper.test.begin('app_papi_link.js', 4, function suite(test) {

// antisquash_key //
test.assertEquals(antisquash_key('abc'), 'abc', 'antisquash_key: non-squashed key is unmodified')
test.assertEquals(antisquash_key('abc.N'), 'abc.1', 'antisquash_key: squashed key .N is replaced with .1')
test.assertEquals(antisquash_key('a.N.b'), 'a.N.b', 'antisquash_key: embedded .N is unmodified')
test.assertEquals(antisquash_key('a a.b b'), 'a a.b b', 'antisquash_key: spaces are handled')

test.done();
});