From cb84351270041449ee8a8984758e7e3ef86ea590 Mon Sep 17 00:00:00 2001 From: nico Date: Thu, 12 Dec 2019 23:15:45 +0100 Subject: test code and small init corrections + added pytest test cases * fixed TSGroupAssigner module init file --- tests/__init__.py | 0 tests/test_group_assign.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_group_assign.py (limited to 'tests') diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 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() -- cgit v1.2.3-54-g00ecf