lock.py
class Lock(): def __init__(self, door, location,securitylevel): self.door=door self.location=location self.securitylevel=securitylevel self.status='locked' def setStatus(self, status): self.status=status def getStatus(self): return self.status def getDoor(self): return self.door def getLoction(self): return self.location def getSecurityLevel(self): return self.securitylevel def __str__(self): return str(self.door) + " " + self.status
scan.py
from lock import Lock import datetime class Scan(): def __init__(self, door, location, securitylevel, card): self.lock=Lock(door,location,securitylevel) self.card=card self.scantime=datetime.datetime.now() def getLock(self): return self.lock def getCard(self): return self.card def getScanTime(self): return self.scantime
The Tests: test.py
import unittest from lock import Lock from scan import Scan class LockTest(unittest.TestCase): def setUp(self): self.lock=Lock('3176','BE', 'normal') def test_lockstring(self): self.assertEqual(str(self.lock), '3176 locked') def test_getStatus(self): self.assertEqual(self.lock.getStatus(), 'locked') def test_setStatus(self): self.lock.setStatus('unlocked') self.assertEqual(self.lock.getStatus(), 'unlocked') def test_GetDoor(self): self.assertEqual(self.lock.getDoor(), '3176') class ScanTest(unittest.TestCase): def setUp(self): self.scan=Scan('3176', 'BE', 'normal', 315643) def test_GetCard(self): self.assertEqual(self.scan.getCard(), 315643)