From 880cc90c14f5d8ffa555d12f691785e79a3d6c54 Mon Sep 17 00:00:00 2001 From: Javier Sánchez Parra Date: Fri, 5 Jul 2019 12:40:06 +0200 Subject: #915 Improve test output using unittest discover * Call the tests with python module unittest. In particular, the discover function. * Rename tests files to meet the default requirements of discover function. --- tests/units/0001-get-clients.py | 19 ------------------- tests/units/0002-post-clients.py | 20 -------------------- tests/units/0003-post-wol.py | 21 --------------------- tests/units/0004-post-shell-run.py | 20 -------------------- tests/units/0005-post-shell-output.py | 20 -------------------- tests/units/0006-post-session.py | 21 --------------------- tests/units/test_0001_get_clients.py | 19 +++++++++++++++++++ tests/units/test_0002_post_clients.py | 20 ++++++++++++++++++++ tests/units/test_0003_post_wol.py | 21 +++++++++++++++++++++ tests/units/test_0004_post_shell_run.py | 20 ++++++++++++++++++++ tests/units/test_0005_post_shell_output.py | 20 ++++++++++++++++++++ tests/units/test_0006_post_session.py | 21 +++++++++++++++++++++ 12 files changed, 121 insertions(+), 121 deletions(-) delete mode 100644 tests/units/0001-get-clients.py delete mode 100644 tests/units/0002-post-clients.py delete mode 100644 tests/units/0003-post-wol.py delete mode 100644 tests/units/0004-post-shell-run.py delete mode 100644 tests/units/0005-post-shell-output.py delete mode 100644 tests/units/0006-post-session.py create mode 100644 tests/units/test_0001_get_clients.py create mode 100644 tests/units/test_0002_post_clients.py create mode 100644 tests/units/test_0003_post_wol.py create mode 100644 tests/units/test_0004_post_shell_run.py create mode 100644 tests/units/test_0005_post_shell_output.py create mode 100644 tests/units/test_0006_post_session.py (limited to 'tests/units') diff --git a/tests/units/0001-get-clients.py b/tests/units/0001-get-clients.py deleted file mode 100644 index 5571225..0000000 --- a/tests/units/0001-get-clients.py +++ /dev/null @@ -1,19 +0,0 @@ -import requests -import unittest - -class TestGetClientsMethods(unittest.TestCase): - - def setUp(self): - self.url = 'http://localhost:8888/clients' - self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} - - def test_get(self): - returned = requests.get(self.url, headers=self.headers) - self.assertEqual(returned.status_code, 200) - - def test_post(self): - returned = requests.post(self.url, headers=self.headers) - self.assertEqual(returned.status_code, 404) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/units/0002-post-clients.py b/tests/units/0002-post-clients.py deleted file mode 100644 index b1e60c9..0000000 --- a/tests/units/0002-post-clients.py +++ /dev/null @@ -1,20 +0,0 @@ -import requests -import unittest - -class TestPostClientsMethods(unittest.TestCase): - - def setUp(self): - self.url = 'http://localhost:8888/clients' - self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} - self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ] } - - def test_post(self): - returned = requests.post(self.url, headers=self.headers, json=self.json) - self.assertEqual(returned.status_code, 200) - - def test_get(self): - returned = requests.post(self.url, headers=self.headers) - self.assertEqual(returned.status_code, 404) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/units/0003-post-wol.py b/tests/units/0003-post-wol.py deleted file mode 100644 index cbb2fd1..0000000 --- a/tests/units/0003-post-wol.py +++ /dev/null @@ -1,21 +0,0 @@ -import requests -import unittest - -class TestPostWolMethods(unittest.TestCase): - - def setUp(self): - self.url = 'http://localhost:8888/wol' - self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} - self.json = { 'type' : 'broadcast', 'clients' : { 'addr' : '192.168.2.1', - 'mac' : '00AABBCCDD01' } } - - def test_post(self): - returned = requests.post(self.url, headers=self.headers, json=self.json) - self.assertEqual(returned.status_code, 200) - - def test_get(self): - returned = requests.post(self.url, headers=self.headers) - self.assertEqual(returned.status_code, 404) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/units/0004-post-shell-run.py b/tests/units/0004-post-shell-run.py deleted file mode 100644 index 7be1fa9..0000000 --- a/tests/units/0004-post-shell-run.py +++ /dev/null @@ -1,20 +0,0 @@ -import requests -import unittest - -class TestPostShellRunMethods(unittest.TestCase): - - def setUp(self): - self.url = 'http://localhost:8888/shell/run' - self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} - self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], 'run' : 'ls' } - - def test_post(self): - returned = requests.post(self.url, headers=self.headers, json=self.json) - self.assertEqual(returned.status_code, 200) - - def test_get(self): - returned = requests.post(self.url, headers=self.headers) - self.assertEqual(returned.status_code, 404) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/units/0005-post-shell-output.py b/tests/units/0005-post-shell-output.py deleted file mode 100644 index 622e482..0000000 --- a/tests/units/0005-post-shell-output.py +++ /dev/null @@ -1,20 +0,0 @@ -import requests -import unittest - -class TestPostShellOutputMethods(unittest.TestCase): - - def setUp(self): - self.url = 'http://localhost:8888/shell/output' - self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} - self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ] } - - def test_post(self): - returned = requests.post(self.url, headers=self.headers, json=self.json) - self.assertEqual(returned.status_code, 200) - - def test_get(self): - returned = requests.post(self.url, headers=self.headers) - self.assertEqual(returned.status_code, 404) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/units/0006-post-session.py b/tests/units/0006-post-session.py deleted file mode 100644 index d235179..0000000 --- a/tests/units/0006-post-session.py +++ /dev/null @@ -1,21 +0,0 @@ -import requests -import unittest - -class TestPostSessionMethods(unittest.TestCase): - - def setUp(self): - self.url = 'http://localhost:8888/shell/run' - self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} - self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], - 'disk' : '0', 'partition' : '1'} - - def test_post(self): - returned = requests.post(self.url, headers=self.headers, json=self.json) - self.assertEqual(returned.status_code, 200) - - def test_get(self): - returned = requests.post(self.url, headers=self.headers) - self.assertEqual(returned.status_code, 404) - -if __name__ == '__main__': - unittest.main() diff --git a/tests/units/test_0001_get_clients.py b/tests/units/test_0001_get_clients.py new file mode 100644 index 0000000..5571225 --- /dev/null +++ b/tests/units/test_0001_get_clients.py @@ -0,0 +1,19 @@ +import requests +import unittest + +class TestGetClientsMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/clients' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + + def test_get(self): + returned = requests.get(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 200) + + def test_post(self): + returned = requests.post(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 404) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/units/test_0002_post_clients.py b/tests/units/test_0002_post_clients.py new file mode 100644 index 0000000..b1e60c9 --- /dev/null +++ b/tests/units/test_0002_post_clients.py @@ -0,0 +1,20 @@ +import requests +import unittest + +class TestPostClientsMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/clients' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ] } + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_get(self): + returned = requests.post(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 404) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/units/test_0003_post_wol.py b/tests/units/test_0003_post_wol.py new file mode 100644 index 0000000..cbb2fd1 --- /dev/null +++ b/tests/units/test_0003_post_wol.py @@ -0,0 +1,21 @@ +import requests +import unittest + +class TestPostWolMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/wol' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'type' : 'broadcast', 'clients' : { 'addr' : '192.168.2.1', + 'mac' : '00AABBCCDD01' } } + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_get(self): + returned = requests.post(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 404) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/units/test_0004_post_shell_run.py b/tests/units/test_0004_post_shell_run.py new file mode 100644 index 0000000..7be1fa9 --- /dev/null +++ b/tests/units/test_0004_post_shell_run.py @@ -0,0 +1,20 @@ +import requests +import unittest + +class TestPostShellRunMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/shell/run' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], 'run' : 'ls' } + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_get(self): + returned = requests.post(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 404) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/units/test_0005_post_shell_output.py b/tests/units/test_0005_post_shell_output.py new file mode 100644 index 0000000..622e482 --- /dev/null +++ b/tests/units/test_0005_post_shell_output.py @@ -0,0 +1,20 @@ +import requests +import unittest + +class TestPostShellOutputMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/shell/output' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ] } + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_get(self): + returned = requests.post(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 404) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/units/test_0006_post_session.py b/tests/units/test_0006_post_session.py new file mode 100644 index 0000000..d235179 --- /dev/null +++ b/tests/units/test_0006_post_session.py @@ -0,0 +1,21 @@ +import requests +import unittest + +class TestPostSessionMethods(unittest.TestCase): + + def setUp(self): + self.url = 'http://localhost:8888/shell/run' + self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} + self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ], + 'disk' : '0', 'partition' : '1'} + + def test_post(self): + returned = requests.post(self.url, headers=self.headers, json=self.json) + self.assertEqual(returned.status_code, 200) + + def test_get(self): + returned = requests.post(self.url, headers=self.headers) + self.assertEqual(returned.status_code, 404) + +if __name__ == '__main__': + unittest.main() -- cgit v1.2.3-18-g5258