diff --git a/.travis.yml b/.travis.yml index 8270811..36a4ed8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Makefile b/Makefile index 3d0a644..b06e161 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ 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 @@ -29,8 +29,7 @@ unittests: lint 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 @@ -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 diff --git a/README-dev.md b/README-dev.md index e7026cb..5936732 100644 --- a/README-dev.md +++ b/README-dev.md @@ -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 @@ -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` @@ -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 @@ -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. diff --git a/README.md b/README.md index a58ac74..5d2c9aa 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/stat_key_browser/templates/app_template.html b/stat_key_browser/templates/app_template.html index f116a52..01150d4 100644 --- a/stat_key_browser/templates/app_template.html +++ b/stat_key_browser/templates/app_template.html @@ -47,7 +47,7 @@

EMC | Isilon OneFS Statistics

{% endfor %} - + diff --git a/test1 b/tests/__init__.py similarity index 100% rename from test1 rename to tests/__init__.py diff --git a/tests/functional/__init__.py b/tests/functional/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/test_categorizer.py b/tests/unit/test_categorizer.py index 366c60c..97f93ed 100644 --- a/tests/unit/test_categorizer.py +++ b/tests/unit/test_categorizer.py @@ -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) diff --git a/tests/unit/test_cluster_config.py b/tests/unit/test_cluster_config.py index 4203cd6..db4fc7a 100644 --- a/tests/unit/test_cluster_config.py +++ b/tests/unit/test_cluster_config.py @@ -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' diff --git a/tests/unit/test_tagger.py b/tests/unit/test_tagger.py index 96e414e..e223240 100644 --- a/tests/unit/test_tagger.py +++ b/tests/unit/test_tagger.py @@ -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']} diff --git a/web_app/js/app.js b/web_app/js/app.js index 1996541..ef12030 100644 --- a/web_app/js/app.js +++ b/web_app/js/app.js @@ -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']) + } }); diff --git a/web_app/js/app_lib.js b/web_app/js/app_lib.js index 02bec88..6527340 100644 --- a/web_app/js/app_lib.js +++ b/web_app/js/app_lib.js @@ -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]) } } diff --git a/web_app/js/app_papi_link.js b/web_app/js/app_papi_link.js index e858aca..cbd3f1a 100644 --- a/web_app/js/app_papi_link.js +++ b/web_app/js/app_papi_link.js @@ -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) @@ -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 } diff --git a/web_app/js/tests/smoke.js b/web_app/js/tests/smoke.js new file mode 100644 index 0000000..0fe1676 --- /dev/null +++ b/web_app/js/tests/smoke.js @@ -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(); + }); +}); diff --git a/web_app/js/tests/unit_app_filter_lib.js b/web_app/js/tests/unit_app_filter_lib.js new file mode 100644 index 0000000..9f40547 --- /dev/null +++ b/web_app/js/tests/unit_app_filter_lib.js @@ -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(); +}); diff --git a/web_app/js/tests/unit_app_lib.js b/web_app/js/tests/unit_app_lib.js new file mode 100644 index 0000000..0b06826 --- /dev/null +++ b/web_app/js/tests/unit_app_lib.js @@ -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(); + +}); diff --git a/web_app/js/tests/unit_app_papi_link.js b/web_app/js/tests/unit_app_papi_link.js new file mode 100644 index 0000000..b094401 --- /dev/null +++ b/web_app/js/tests/unit_app_papi_link.js @@ -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(); +});