Пример #1
0
def test_insert_alarms():
    repo = AlarmRepository()
    alarm = Alarm(name="Alarm 1", hour=6, minute=0)
    repo.insert(alarm)
    result = repo.find_all()
    assert len(result) is 1
    assert result[0].id is 1
Пример #2
0
def setup_alarm():
    ConnectorFactory().build_connector().clear_db()
    now = datetime.now()
    yesterday = now - timedelta(1)

    repo = AlarmRepository()
    alarm = Alarm(name="Alarm 1",
                  hour=now.hour,
                  minute=now.minute,
                  last_activated=yesterday)
    repo.insert(alarm)
Пример #3
0
def test_find_alarms():
    repo = AlarmRepository()

    for i in range(10):
        repo.insert(Alarm("Alarm {}".format(i), hour=i + 1, minute=i))

    result = repo.find_all()
    assert len(result) is 10

    for i in range(len(result)):
        assert result[i].id is i + 1
Пример #4
0
def test_delete():
    repo = AlarmRepository()

    for i in range(10):
        repo.update(Alarm(name="Alarm {}".format(i), hour=i + 1, minute=i))

    result = repo.find_all()
    assert len(result) is 10

    for i in range(len(result)):
        assert result[i].id is i + 1
        repo.delete(result[i])

    result = repo.find_all()
    assert len(result) is 0
Пример #5
0
    def convert_dict_to_alarm(self, alarm_as_dict):
        entity = Alarm()

        if "hour" in alarm_as_dict:
            entity.hour = alarm_as_dict["hour"]
        if "minute" in alarm_as_dict:
            entity.minute = alarm_as_dict["minute"]
        if "name" in alarm_as_dict:
            entity.name = alarm_as_dict["name"]
        if "id" in alarm_as_dict:
            entity.id = alarm_as_dict["id"]

        return entity
Пример #6
0
 def convert_cursor_result_to_alarm(self, cursor_alarm_result) -> Alarm:
     return Alarm(id=cursor_alarm_result[0],
                  name=cursor_alarm_result[1],
                  hour=cursor_alarm_result[2],
                  minute=cursor_alarm_result[3],
                  last_activated=cursor_alarm_result[4])