diff --git a/.gitignore b/.gitignore index b51d082..9aca1ef 100755 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ __pycache__ /venv*/ *.pyc .DS_Store -.vscode \ No newline at end of file +.vscode +test/report.html diff --git a/bin/akamai-etp b/bin/akamai-etp index f3de94c..8c68c32 100755 --- a/bin/akamai-etp +++ b/bin/akamai-etp @@ -530,7 +530,7 @@ def main(): exit_fromresponse(r) else: url = urljoin(baseurl, "/etp-config/v1/configs/%s/lists" % (config.etp_config_id)) - r = session.get(url, params=build_params(page=page_number), headers=headers) + r = session.get(url, params=build_params(), headers=headers) if r.status_code == 200: for list_item in r.json(): print("%s,%s" % (list_item.get("id"), list_item.get('name'))) diff --git a/test/nose2.cfg b/test/nose2.cfg index 7b3c35f..56b0fa1 100644 --- a/test/nose2.cfg +++ b/test/nose2.cfg @@ -3,4 +3,4 @@ plugins = nose2_html_report.html_report [html-report] always-on = True -path = test_results/my_custom_report_file.html \ No newline at end of file +path = report.html \ No newline at end of file diff --git a/test/report.html b/test/report.html deleted file mode 100644 index 0486210..0000000 --- a/test/report.html +++ /dev/null @@ -1,269 +0,0 @@ - - - - Report - - - - - - - -
-
-
-

Test Report

-
-
-
-
-

Summary

-
-
-
    - -
  • Total: 5
  • - -
  • Passed: 5
  • - -
-
-
-
-
-
-
-

Test Results

-
- - search -
- -
    - -
  • -
    - - - done - - - test.TestCliETP.test_cli_version -
    -
    - Description - -


    Ensure version of the CLI is displayed

    - - - Result: passed -
    - - Traceback -
    None
    -
    -
  • - -
  • -
    - - - done - - - test.TestCliETP.test_no_edgerc -
    -
    - Description - -


    Call CLI with a bogus edgerc file, help should be displayed.

    - - - Result: passed -
    - - Traceback -
    None
    -
    -
  • - -
  • -
    - - - done - - - test.TestEvents.test_event_aup -
    -
    - Description - -


    Fetch AUP events

    - - - Result: passed -
    - - Traceback -
    None
    -
    -
  • - -
  • -
    - - - done - - - test.TestEvents.test_event_aup_file -
    -
    - Description - -


    Fetch AUP events, export as a file

    - - - Result: passed -
    - - Traceback -
    None
    -
    -
  • - -
  • -
    - - - done - - - test.TestEvents.test_event_threat -
    -
    - Description - -


    Fetch threat events

    - - - Result: passed -
    - - Traceback -
    None
    -
    -
  • - -
-
-
-
- - - - - - \ No newline at end of file diff --git a/test/test.py b/test/test.py index 518e643..318d362 100644 --- a/test/test.py +++ b/test/test.py @@ -15,9 +15,15 @@ """ This module replaces the old test.bash script Tested with nose2: + ```bash + +# Optional +EDGERC_SECTION=mysection +# End Optional + cd test -nose2 +nose2 -v open report.html ``` """ @@ -45,10 +51,10 @@ def setUp(self): def cli_command(self, *args): command = shlex.split(f'python3 {self.maindir}/bin/akamai-etp') - if os.environ['EDGERC_SECTION']: + if os.environ.get('EDGERC_SECTION'): command.extend(["--section", os.environ['EDGERC_SECTION']]) command.extend(*args) - print("\nCOMMAND: ", command) + print("\nCOMMAND: ", " ".join(command)) return command def cli_run(self, *args): @@ -143,5 +149,34 @@ def test_cli_version(self): self.assertEqual(cmd.returncode, 0, 'return code must be 0') +class TestListETP(CliETPTest): + """ + TODO: add a create and remove list once implemented in the cli + """ + def test_add100_list(self): + test_fqdns = list("testhost-{}.cli-etp.unittest".format(i) for i in range(100)) + cmd = self.cli_run('list', 'add', '37591', *test_fqdns) + stdout, stderr = cmd.communicate() + if cmd.returncode != 0: + print(stdout, stderr) + self.assertEqual(cmd.returncode, 0, 'return code must be 0') + cmd = self.cli_run('list', 'remove', '37591', *test_fqdns) + cmd.communicate() + + self.assertEqual(cmd.returncode, 0, 'return code must be 0') + + def test_get_lists(self): + """ + Get the security lists configured in the tenant + """ + cmd = self.cli_run('list', 'get') + stdout, stderr = cmd.communicate() + output = stdout.decode(encoding) + line_count = len(output.splitlines()) + print(line_count) + self.assertGreater(line_count, 0, "We expect at least one list to be on this tenant/config_id") + self.assertEqual(cmd.returncode, 0, 'return code must be 0') + + if __name__ == '__main__': unittest.main()