summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authornico <nico@magicbroccoli.de>2019-12-22 04:20:29 +0100
committernico <nico@magicbroccoli.de>2019-12-22 04:20:29 +0100
commit150002e1434bcc69694232436b9894358bed8826 (patch)
treeeec64ff2aab0c8e414375b7d078e78d2c09e8980 /tests
parent37dbae346af1507accecf62ccec3e45912ed70f5 (diff)
parent3a25e6234e62574096379782622743d57d9a53ec (diff)
code cleanup and pypi setup0.1
+ add MANIFEST.in file + add pytest / flake8 tests + add automated github action * update setup.py to build properly * code corrections
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/test_group_assign.py55
2 files changed, 55 insertions, 0 deletions
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..150aa7b
--- /dev/null
+++ b/tests/test_group_assign.py
@@ -0,0 +1,55 @@
+#!/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):
+ # the main class is missing arguments and should fail with a TypeError
+
+ 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()