Skip to content

Commit

Permalink
Fix regression
Browse files Browse the repository at this point in the history
Add test to add 100 items and remove them
  • Loading branch information
bitonio committed Aug 18, 2022
1 parent 91382c1 commit 4dac7db
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 275 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ __pycache__
/venv*/
*.pyc
.DS_Store
.vscode
.vscode
test/report.html
2 changes: 1 addition & 1 deletion bin/akamai-etp
Original file line number Diff line number Diff line change
Expand Up @@ -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')))
Expand Down
2 changes: 1 addition & 1 deletion test/nose2.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ plugins = nose2_html_report.html_report

[html-report]
always-on = True
path = test_results/my_custom_report_file.html
path = report.html
269 changes: 0 additions & 269 deletions test/report.html

This file was deleted.

41 changes: 38 additions & 3 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
"""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit 4dac7db

Please sign in to comment.