|
2 | 2 | import datetime |
3 | 3 | import unittest |
4 | 4 |
|
| 5 | +from time import sleep |
5 | 6 | from timely import Timely |
6 | 7 |
|
7 | 8 |
|
@@ -47,5 +48,48 @@ def test_exception_if_start_time_is_greater_than_equal_to_end_time(self): |
47 | 48 | self.timely.set(weekdays=['*'], start_time='9:00 AM', |
48 | 49 | end_time='9:00 AM') |
49 | 50 |
|
| 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 | + |
50 | 94 | def tearDown(self): |
51 | 95 | del self.timely |
0 commit comments