Exemplo n.º 1
0
    def test_edit_alarm_single(self):
        """
        Adds an alarm, edits a single value and checks all the others remain the
        same.
        """
        adh = AlarmDb(self.db_name)
        alarm_test = AlarmItem(13,
                               35,
                               enabled=True,
                               label='yes',
                               days=(True, False, True, False, True, False,
                                     True))

        # 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_, minute=0)
        self.assertTrue(edit_success)
        edited_alarm = adh.get_alarm(alarm_test.id_)
        self.assertGreater(edited_alarm.timestamp, original_timestamp)
        self.assertEqual(edited_alarm.hour, 13)
        self.assertEqual(edited_alarm.minute, 0)
        self.assertTrue(edited_alarm.monday)
        self.assertFalse(edited_alarm.tuesday)
        self.assertTrue(edited_alarm.wednesday)
        self.assertFalse(edited_alarm.thursday)
        self.assertTrue(edited_alarm.friday)
        self.assertFalse(edited_alarm.saturday)
        self.assertTrue(edited_alarm.sunday)
        self.assertTrue(edited_alarm.enabled)
        self.assertEqual(edited_alarm.label, 'yes')

        # Test with opposite initial values
        alarm_test = AlarmItem(10,
                               20,
                               enabled=False,
                               label='no',
                               days=(False, True, False, True, False, True,
                                     False))
        alarm_test.id_ = adh.add_alarm(alarm_test)
        edit_success = adh.edit_alarm(alarm_test.id_, hour=0)
        self.assertTrue(edit_success)
        edited_alarm = adh.get_alarm(alarm_test.id_)
        self.assertEqual(edited_alarm.hour, 0)
        self.assertEqual(edited_alarm.minute, 20)
        self.assertFalse(edited_alarm.monday)
        self.assertTrue(edited_alarm.tuesday)
        self.assertFalse(edited_alarm.wednesday)
        self.assertTrue(edited_alarm.thursday)
        self.assertFalse(edited_alarm.friday)
        self.assertTrue(edited_alarm.saturday)
        self.assertFalse(edited_alarm.sunday)
        self.assertFalse(edited_alarm.enabled)
        self.assertEqual(edited_alarm.label, 'no')
Exemplo n.º 2
0
    def test_edit_alarm_single(self):
        """
        Adds an alarm, edits a single value and checks all the others remain the
        same.
        """
        adh = AlarmDb(self.db_name)
        alarm_test = AlarmItem(
            13, 35, enabled=True, label='yes',
            days=(True, False, True, False, True, False, True))

        # 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_, minute=0)
        self.assertTrue(edit_success)
        edited_alarm = adh.get_alarm(alarm_test.id_)
        self.assertGreater(edited_alarm.timestamp, original_timestamp)
        self.assertEqual(edited_alarm.hour, 13)
        self.assertEqual(edited_alarm.minute, 0)
        self.assertTrue(edited_alarm.monday)
        self.assertFalse(edited_alarm.tuesday)
        self.assertTrue(edited_alarm.wednesday)
        self.assertFalse(edited_alarm.thursday)
        self.assertTrue(edited_alarm.friday)
        self.assertFalse(edited_alarm.saturday)
        self.assertTrue(edited_alarm.sunday)
        self.assertTrue(edited_alarm.enabled)
        self.assertEqual(edited_alarm.label, 'yes')

        # Test with opposite initial values
        alarm_test = AlarmItem(
            10, 20, enabled=False, label='no',
            days=(False, True, False, True, False, True, False))
        alarm_test.id_ = adh.add_alarm(alarm_test)
        edit_success = adh.edit_alarm(alarm_test.id_, hour=0)
        self.assertTrue(edit_success)
        edited_alarm = adh.get_alarm(alarm_test.id_)
        self.assertEqual(edited_alarm.hour, 0)
        self.assertEqual(edited_alarm.minute, 20)
        self.assertFalse(edited_alarm.monday)
        self.assertTrue(edited_alarm.tuesday)
        self.assertFalse(edited_alarm.wednesday)
        self.assertTrue(edited_alarm.thursday)
        self.assertFalse(edited_alarm.friday)
        self.assertTrue(edited_alarm.saturday)
        self.assertFalse(edited_alarm.sunday)
        self.assertFalse(edited_alarm.enabled)
        self.assertEqual(edited_alarm.label, 'no')
Exemplo n.º 3
0
    def edit_alarm(self, alarm_id, hour=None, minute=None, days=None,
                   enabled=None, label=None):
        """
        Edits an alarm from the database with the input data.
        A new timestamp is set by the AlarmDb class if the edit is successful.
        :param alarm_id: Integer to indicate the ID of the alarm to be edited.
        :param hour: Integer to indicate the alarm hour.
        :param minute: Integer to indicate the alarm minute.
        :param days: 7-item list of booleans to indicate repeat weekdays.
        :param enabled: Boolean to indicate alarm enabled state.
        :param label: Strong to contain the alarm label.
        :return: Boolean indicating the success of the 'edit' operation.
        """
        db = AlarmDb()
        # As the default values for AlarmDb.edit_alarm are all None as well we
        # can send all through as is.
        success = db.edit_alarm(
            alarm_id,  hour=hour, minute=minute, days=days, enabled=enabled,
            label=label)

        # If a successful edit was carried, then make sure the alarm is launched
        if success is True:
            self.__set_alarm_thread(AlarmManager.get_alarm(alarm_id))

        return success
Exemplo n.º 4
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')
Exemplo n.º 5
0
    def edit_alarm(self,
                   alarm_id,
                   hour=None,
                   minute=None,
                   days=None,
                   enabled=None,
                   label=None):
        """
        Edits an alarm from the database with the input data.
        A new timestamp is set by the AlarmDb class if the edit is successful.
        :param alarm_id: Integer to indicate the ID of the alarm to be edited.
        :param hour: Integer to indicate the alarm hour.
        :param minute: Integer to indicate the alarm minute.
        :param days: 7-item list of booleans to indicate repeat weekdays.
        :param enabled: Boolean to indicate alarm enabled state.
        :param label: Strong to contain the alarm label.
        :return: Boolean indicating the success of the 'edit' operation.
        """
        db = AlarmDb()
        # As the default values for AlarmDb.edit_alarm are all None as well we
        # can send all through as is.
        success = db.edit_alarm(alarm_id,
                                hour=hour,
                                minute=minute,
                                days=days,
                                enabled=enabled,
                                label=label)

        # If a successful edit was carried, then make sure the alarm is launched
        if success is True:
            self.__set_alarm_thread(AlarmManager.get_alarm(alarm_id))

        return success
Exemplo n.º 6
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')