aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornico <nico@magicbroccoli.de>2019-12-12 23:15:45 +0100
committernico <nico@magicbroccoli.de>2019-12-12 23:15:45 +0100
commitcb84351270041449ee8a8984758e7e3ef86ea590 (patch)
tree00b2b16ae1e04be98f5b20540e7d0fc793f8acdc
parent97f48129518ed507bd29280703fe79e74bf90536 (diff)
test code and small init corrections
+ added pytest test cases * fixed TSGroupAssigner module init file
-rw-r--r--TSGroupAssigner/__init__.py3
-rw-r--r--setup.py1
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/test_group_assign.py56
4 files changed, 58 insertions, 2 deletions
diff --git a/TSGroupAssigner/__init__.py b/TSGroupAssigner/__init__.py
index a41cd05..04fc467 100644
--- a/TSGroupAssigner/__init__.py
+++ b/TSGroupAssigner/__init__.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
-from TSGroupAssigner.group_assign import GroupAssigner
+from .group_assign import GroupAssigner
+from .group_assign import DateException
diff --git a/setup.py b/setup.py
index f296015..6136fdc 100644
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,6 @@ from setuptools import setup, find_packages
with open("README.md", "r") as fh:
long_description = fh.read()
-
setup(
name='TSGroupAssigner',
version='0.0.1',
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/test_group_assign.py b/tests/test_group_assign.py
new file mode 100644
index 0000000..1f86574
--- /dev/null
+++ b/tests/test_group_assign.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+import datetime as dt
+
+import pytest
+
+from TSGroupAssigner import GroupAssigner, DateException
+
+# sample input
+creds = {
+ 'host': 'localhost',
+ 'port': 10011,
+ 'user': 'serveradmin',
+ 'password': '5up3r_53cr37',
+ 'sid': 1,
+ 'gid': 24
+}
+
+
+class TestGroupAssigner:
+ def test_missing_input(self):
+ """
+ this should fail due to missing arguments
+ """
+ with pytest.raises(TypeError):
+ GroupAssigner().start()
+
+ def test_sleepstart_startdate(self):
+ # startdate is too far in the future sleepstart should produce a DateException
+
+ # start date 3 days in the future
+ startdate = dt.date.today() + dt.timedelta(days=3)
+ duration = dt.timedelta()
+
+ with pytest.raises(DateException):
+ GroupAssigner(date=startdate, delta=duration,**creds).start()
+
+ def test_datecheck_enddate(self):
+ # this should produce a exit code 0 SystemExit as the end date is in the past
+
+ # start date 2 days in the past
+ startdate = dt.date.today() + dt.timedelta(days=-2)
+ duration = dt.timedelta()
+
+ with pytest.raises(SystemExit):
+ GroupAssigner(date=startdate, delta=duration,**creds).start()
+
+ def test_connect_noconnection(self):
+ # connect should fail with ConnectionRefusedError
+
+ # start date is today
+ startdate = dt.date.today()
+ duration = dt.timedelta()
+
+ with pytest.raises(ConnectionRefusedError):
+ GroupAssigner(date=startdate, delta=duration,**creds).start()