Skip to content

Commit 68e45cd

Browse files
author
rightlag
committed
Added more unit tests
1 parent 1d0fd36 commit 68e45cd

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/test_timely.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import datetime
33
import unittest
44

5+
from time import sleep
56
from timely import Timely
67

78

@@ -47,5 +48,48 @@ def test_exception_if_start_time_is_greater_than_equal_to_end_time(self):
4748
self.timely.set(weekdays=['*'], start_time='9:00 AM',
4849
end_time='9:00 AM')
4950

51+
def test_unset_method(self):
52+
self.timely.set(weekdays=['*'], start_time='9:00 AM',
53+
end_time='5:00 PM')
54+
try:
55+
instance = self.conn.get_only_instances()[0]
56+
times = self.timely.all()[instance.id]
57+
# First - set times for all days of the week
58+
self.assertEqual(len(times), 7)
59+
# Second - unset times for all days of the week
60+
self.timely.unset(weekdays=['*'])
61+
times = self.timely.all()[instance.id]
62+
self.assertEqual(len(times), 0)
63+
except IndexError:
64+
pass
65+
66+
def test_check_method_stops_instance_if_should_not_be_running(self):
67+
try:
68+
instance = self.conn.get_only_instances()[0]
69+
if instance.state == 'stopped':
70+
# Start the instance to ensure it is running
71+
instance.start()
72+
weekday = self.timely.weekdays[self.now.weekday()]
73+
# Automatically sets `start_time` and `end_time` to `None`
74+
self.timely.set(weekdays=[weekday])
75+
# Ensure that the instance is being stopped
76+
self.timely.check()
77+
stopped = False
78+
instance = None
79+
while not stopped:
80+
try:
81+
# Need to remake a connection to AWS to get the updated
82+
# instance status
83+
instance = self.conn.get_only_instances()[0]
84+
if instance.state == 'stopped':
85+
stopped = True
86+
else:
87+
sleep(1)
88+
except IndexError:
89+
pass
90+
self.assertEqual(instance.state, 'stopped')
91+
except IndexError:
92+
pass
93+
5094
def tearDown(self):
5195
del self.timely

0 commit comments

Comments
 (0)