summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Oliveira <18oliveira.charles@gmail.com>2020-01-28 09:49:42 -0300
committerCharles Oliveira <18oliveira.charles@gmail.com>2020-01-28 09:49:42 -0300
commit159b20e413bcbe51fed055492b36c78db923c2b8 (patch)
tree366c6bc285b96aa13985052b5ad64f6a43546c88 /tests
parentb4c37bb43e9777cffab0641a7f7b4e234c1bf98f (diff)
tests: add SquadApi tests and other edge cases
Diffstat (limited to 'tests')
-rw-r--r--tests/test_api.py35
-rwxr-xr-xtests/test_models.py8
-rw-r--r--tests/test_utils.py5
3 files changed, 48 insertions, 0 deletions
diff --git a/tests/test_api.py b/tests/test_api.py
index e69de29..54b63ab 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -0,0 +1,35 @@
+from unittest import TestCase
+
+
+from squad_client.api import SquadApi, ApiException
+
+
+def is_test_server_running():
+ import socket
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ result = sock.connect_ex(('localhost', 8000))
+ sock.close()
+ return result == 0
+
+
+class SquadApiTest(TestCase):
+
+ def setUp(self):
+ SquadApi.configure(url='http://localhost:8000')
+
+ def test_malformed_url(self):
+ with self.assertRaises(ApiException):
+ SquadApi.configure('http:/malformed/url')
+
+ def test_out_of_domain_object_url(self):
+ with self.assertRaises(ApiException):
+ SquadApi.get('http://some.other.url')
+
+ def test_server_response(self):
+ # will require automatic test server to shutdown, for now, just to it by hand before running this test
+ if not is_test_server_running():
+ with self.assertRaises(ApiException):
+ SquadApi.get('/api/groups')
+ else:
+ self.assertTrue(SquadApi.get('/api/groups') is not None)
+
diff --git a/tests/test_models.py b/tests/test_models.py
index 826a67b..427537c 100755
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -20,10 +20,18 @@ class SquadTest(unittest.TestCase):
groups = self.squad.groups()
self.assertTrue(True, len(groups))
+ def test_not_found_groups(self):
+ groups = self.squad.groups(name__startswith='no group with this name')
+ self.assertEqual(0, len(groups))
+
def test_groups_with_count(self):
four_groups = self.squad.groups(count=4)
self.assertEqual(4, len(four_groups))
+ def test_not_found_group(self):
+ not_found_group = self.squad.group('this-group-does-not-really-exist')
+ self.assertEqual(None, not_found_group)
+
def test_group(self):
lkft_group = self.squad.group('lkft')
self.assertTrue(lkft_group is not None)
diff --git a/tests/test_utils.py b/tests/test_utils.py
index e69de29..9d34e9f 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -0,0 +1,5 @@
+from unittest import TestCase
+
+
+class UtilsTest(TestCase):
+ pass