Пример #1
0
    def test_edit_alarm(self):
        """ Creates an alarm and edits it. """
        adh = AlarmDb(self.db_name)
        adh.delete_all_alarms()
        alarm_test = AlarmItem(
            13, 35, days=(False, False, False, False, False, False, False),
            enabled=True, label='')

        # Check the timestamp changes on add_alarm
        original_timestamp = alarm_test.timestamp
        alarm_test.id_ = adh.add_alarm(alarm_test)
        self.assertNotEqual(alarm_test.timestamp, original_timestamp)

        # Edit alarm, check new data and different timestamp
        original_timestamp = alarm_test.timestamp
        time.sleep(1)
        edit_success = adh.edit_alarm(
            alarm_test.id_, 11, 22, enabled=False, label='New label',
            days=(True, True, True, True, True, True, True))
        self.assertEqual(edit_success, True)
        edited_alarm = adh.get_alarm(alarm_test.id_)
        self.assertGreater(edited_alarm.timestamp, original_timestamp)
        self.assertEqual(edited_alarm.hour, 11)
        self.assertEqual(edited_alarm.minute, 22)
        self.assertTrue(edited_alarm.monday)
        self.assertTrue(edited_alarm.tuesday)
        self.assertTrue(edited_alarm.wednesday)
        self.assertTrue(edited_alarm.thursday)
        self.assertTrue(edited_alarm.friday)
        self.assertTrue(edited_alarm.saturday)
        self.assertTrue(edited_alarm.sunday)
        self.assertFalse(edited_alarm.enabled)
        self.assertEqual(edited_alarm.label, 'New label')
Пример #2
0
 def test_empty_table_zero_alarms(self):
     """ Check that an empty table returns a 0 length list of items """
     adh = AlarmDb(self.db_name)
     adh.delete_all_alarms()
     number_of_alarms = adh.get_number_of_alarms()
     all_alarms = adh.get_all_alarms()
     self.assertEqual(number_of_alarms, 0)
     self.assertEqual(len(all_alarms), 0)
Пример #3
0
 def test_empty_table_zero_alarms(self):
     """ Check that an empty table returns a 0 length list of items """
     adh = AlarmDb(self.db_name)
     adh.delete_all_alarms()
     number_of_alarms = adh.get_number_of_alarms()
     all_alarms = adh.get_all_alarms()
     self.assertEqual(number_of_alarms, 0)
     self.assertEqual(len(all_alarms), 0)
Пример #4
0
    def test_update_alarm(self):
        """ Creates an alarm and update it. """
        adh = AlarmDb(self.db_name)
        adh.delete_all_alarms()
        alarm_test = AlarmItem(13,
                               35,
                               days=(False, False, False, False, False, False,
                                     False),
                               enabled=True,
                               label='')
        original_timestamp = alarm_test.timestamp

        # Add the alarm to the database and check the timestamp has been set
        alarm_test.id_ = adh.add_alarm(alarm_test)
        self.assertNotEqual(alarm_test.timestamp, original_timestamp)
        original_timestamp = alarm_test.timestamp

        # Create a new AlarmItem with the same id and timestamp to update the db
        alarm_updated = AlarmItem(21,
                                  12,
                                  days=(True, True, True, True, True, True,
                                        True),
                                  enabled=False,
                                  label='new label',
                                  alarm_id=alarm_test.id_,
                                  timestamp=original_timestamp)
        time.sleep(1)
        update_success = adh.update_alarm(alarm_updated)
        self.assertEqual(update_success, True)
        self.assertNotEqual(alarm_updated.timestamp, original_timestamp)

        # Check the new data has replaced the old,
        retrieved_alarm = adh.get_alarm(alarm_test.id_)
        self.assertEqual(retrieved_alarm.hour, 21)
        self.assertEqual(retrieved_alarm.minute, 12)
        self.assertTrue(retrieved_alarm.monday)
        self.assertTrue(retrieved_alarm.tuesday)
        self.assertTrue(retrieved_alarm.wednesday)
        self.assertTrue(retrieved_alarm.thursday)
        self.assertTrue(retrieved_alarm.friday)
        self.assertTrue(retrieved_alarm.saturday)
        self.assertTrue(retrieved_alarm.sunday)
        self.assertFalse(retrieved_alarm.enabled)
        self.assertEqual(retrieved_alarm.label, 'new label')
        self.assertEqual(retrieved_alarm.timestamp, alarm_updated.timestamp)
        self.assertGreater(retrieved_alarm.timestamp, original_timestamp)
Пример #5
0
 def test_get_all_enable_alarms(self):
     """
     Adds 5 alarms into the database, 3 enabled and 2 disabled. Checks the
     enabled and disabled getters are working.
     """
     adh = AlarmDb(self.db_name)
     adh.delete_all_alarms()
     adh.add_alarm(AlarmItem(13, 35, days=self.random_days,
                             enabled=True))  # id 1
     adh.add_alarm(AlarmItem(14, 36, days=self.random_days,
                             enabled=False))  # id 2
     adh.add_alarm(AlarmItem(15, 37, days=self.random_days,
                             enabled=True))  # id 3
     adh.add_alarm(AlarmItem(16, 38, days=self.random_days,
                             enabled=False))  # id 4
     adh.add_alarm(AlarmItem(17, 39, days=self.random_days,
                             enabled=True))  # id 5
     enabled_alarms = adh.get_all_enabled_alarms()
     disabled_alarms = adh.get_all_disabled_alarms()
     self.assertEqual(len(enabled_alarms), 3)
     self.assertEqual(len(disabled_alarms), 2)
Пример #6
0
 def test_get_all_enable_alarms(self):
     """
     Adds 5 alarms into the database, 3 enabled and 2 disabled. Checks the
     enabled and disabled getters are working.
     """
     adh = AlarmDb(self.db_name)
     adh.delete_all_alarms()
     adh.add_alarm(
         AlarmItem(13, 35, days=self.random_days, enabled=True))   # id 1
     adh.add_alarm(
         AlarmItem(14, 36, days=self.random_days, enabled=False))  # id 2
     adh.add_alarm(
         AlarmItem(15, 37, days=self.random_days, enabled=True))   # id 3
     adh.add_alarm(
         AlarmItem(16, 38, days=self.random_days, enabled=False))  # id 4
     adh.add_alarm(
         AlarmItem(17, 39, days=self.random_days, enabled=True))   # id 5
     enabled_alarms = adh.get_all_enabled_alarms()
     disabled_alarms = adh.get_all_disabled_alarms()
     self.assertEqual(len(enabled_alarms), 3)
     self.assertEqual(len(disabled_alarms), 2)
Пример #7
0
    def test_edit_alarm(self):
        """ Creates an alarm and edits it. """
        adh = AlarmDb(self.db_name)
        adh.delete_all_alarms()
        alarm_test = AlarmItem(13,
                               35,
                               days=(False, False, False, False, False, False,
                                     False),
                               enabled=True,
                               label='')

        # Check the timestamp changes on add_alarm
        original_timestamp = alarm_test.timestamp
        alarm_test.id_ = adh.add_alarm(alarm_test)
        self.assertNotEqual(alarm_test.timestamp, original_timestamp)

        # Edit alarm, check new data and different timestamp
        original_timestamp = alarm_test.timestamp
        time.sleep(1)
        edit_success = adh.edit_alarm(alarm_test.id_,
                                      11,
                                      22,
                                      enabled=False,
                                      label='New label',
                                      days=(True, True, True, True, True, True,
                                            True))
        self.assertEqual(edit_success, True)
        edited_alarm = adh.get_alarm(alarm_test.id_)
        self.assertGreater(edited_alarm.timestamp, original_timestamp)
        self.assertEqual(edited_alarm.hour, 11)
        self.assertEqual(edited_alarm.minute, 22)
        self.assertTrue(edited_alarm.monday)
        self.assertTrue(edited_alarm.tuesday)
        self.assertTrue(edited_alarm.wednesday)
        self.assertTrue(edited_alarm.thursday)
        self.assertTrue(edited_alarm.friday)
        self.assertTrue(edited_alarm.saturday)
        self.assertTrue(edited_alarm.sunday)
        self.assertFalse(edited_alarm.enabled)
        self.assertEqual(edited_alarm.label, 'New label')
Пример #8
0
    def test_update_alarm(self):
        """ Creates an alarm and update it. """
        adh = AlarmDb(self.db_name)
        adh.delete_all_alarms()
        alarm_test = AlarmItem(
            13, 35, days=(False, False, False, False, False, False, False),
            enabled=True, label='')
        original_timestamp = alarm_test.timestamp

        # Add the alarm to the database and check the timestamp has been set
        alarm_test.id_ = adh.add_alarm(alarm_test)
        self.assertNotEqual(alarm_test.timestamp, original_timestamp)
        original_timestamp = alarm_test.timestamp

        # Create a new AlarmItem with the same id and timestamp to update the db
        alarm_updated = AlarmItem(
            21, 12, days=(True, True, True, True, True, True, True),
            enabled=False, label='new label', alarm_id=alarm_test.id_,
            timestamp=original_timestamp)
        time.sleep(1)
        update_success = adh.update_alarm(alarm_updated)
        self.assertEqual(update_success, True)
        self.assertNotEqual(alarm_updated.timestamp, original_timestamp)

        # Check the new data has replaced the old,
        retrieved_alarm = adh.get_alarm(alarm_test.id_)
        self.assertEqual(retrieved_alarm.hour, 21)
        self.assertEqual(retrieved_alarm.minute, 12)
        self.assertTrue(retrieved_alarm.monday)
        self.assertTrue(retrieved_alarm.tuesday)
        self.assertTrue(retrieved_alarm.wednesday)
        self.assertTrue(retrieved_alarm.thursday)
        self.assertTrue(retrieved_alarm.friday)
        self.assertTrue(retrieved_alarm.saturday)
        self.assertTrue(retrieved_alarm.sunday)
        self.assertFalse(retrieved_alarm.enabled)
        self.assertEqual(retrieved_alarm.label, 'new label')
        self.assertEqual(retrieved_alarm.timestamp, alarm_updated.timestamp)
        self.assertGreater(retrieved_alarm.timestamp, original_timestamp)
Пример #9
0
 def test_get_alarm_and_delete(self):
     """
     Adds 5 alarms into the database, then it removes one, and then all the
     rest.
     """
     adh = AlarmDb(self.db_name)
     self.only_five_entries(adh)
     retrieved_alarm = adh.get_alarm(3)  # AlarmItem(15, 37) id=3
     self.assertEqual(retrieved_alarm.hour, 15)
     self.assertEqual(retrieved_alarm.minute, 37)
     delete_success = adh.delete_alarm(3)
     self.assertTrue(delete_success)
     retrieved_alarm = adh.get_alarm(3)  # AlarmItem(15, 37) id=3
     self.assertIsNone(retrieved_alarm)
     delete_success = adh.delete_all_alarms()
     self.assertTrue(delete_success)
Пример #10
0
 def test_get_alarm_and_delete(self):
     """
     Adds 5 alarms into the database, then it removes one, and then all the
     rest.
     """
     adh = AlarmDb(self.db_name)
     self.only_five_entries(adh)
     retrieved_alarm = adh.get_alarm(3)  # AlarmItem(15, 37) id=3
     self.assertEqual(retrieved_alarm.hour, 15)
     self.assertEqual(retrieved_alarm.minute, 37)
     delete_success = adh.delete_alarm(3)
     self.assertTrue(delete_success)
     retrieved_alarm = adh.get_alarm(3)  # AlarmItem(15, 37) id=3
     self.assertIsNone(retrieved_alarm)
     delete_success = adh.delete_all_alarms()
     self.assertTrue(delete_success)