Пример #1
0
def test_get_latest_save(reset_db):
    base_date = datetime.today().timestamp()
    # Programs that ran on a past date
    program1_a = TrackedProgram("test1", 100, 200, 300, 0)
    program2_a = TrackedProgram("test2", 100, 300, 375, 25)

    # Tests that the most current program from the current day is retrieved
    time_offset = 100
    program1_b = TrackedProgram("test1", 100, base_date, base_date + 50, 50)
    program1_c = TrackedProgram("test1", 100, base_date + time_offset,
                                base_date + time_offset + 75, 25)
    program2_b = TrackedProgram("test2", 100, base_date + 2 * time_offset,
                                base_date + 2 * time_offset + 100, 0)

    programs = [program1_a, program2_a, program1_b, program2_b, program1_c]
    DataManager.store_many(*programs)

    program1_blank = TrackedProgram.min_init("test1", 100)
    program2_blank = TrackedProgram.min_init("test2", 100)

    latest_1 = DataManager.get_latest_save(program1_blank)
    latest_2 = DataManager.get_latest_save(program2_blank)

    assert latest_1 == program1_c
    assert latest_2 == program2_b
Пример #2
0
def test_store_many(reset_db, default_init, row_num):
    DataManager.store_many(default_init, default_init)

    result = DataManager.query("SELECT * FROM program_log")
    result = result[row_num]

    assert result['start_time'] == default_init.start_time
    assert result['end_time'] == default_init.end_time
    assert result['time_left'] == default_init.time_left
    assert result['max_time'] == default_init.max_time
    assert result['name'] == default_init.name
    assert result['id'] is row_num + 1
Пример #3
0
def test_get_latest_save_empty(reset_db):
    base_date = datetime.today().timestamp()
    # Programs that ran on a past date
    program1_a = TrackedProgram("test1", 100, 200, 300, 0)
    program2_a = TrackedProgram("test2", 100, 300, 375, 25)

    programs = [program1_a, program2_a]
    DataManager.store_many(*programs)

    program1_blank = TrackedProgram.min_init("test1", 100)
    program2_blank = TrackedProgram.min_init("test2", 100)

    latest_1 = DataManager.get_latest_save(program1_blank)
    latest_2 = DataManager.get_latest_save(program2_blank)

    assert latest_1 == None
    assert latest_2 == None
Пример #4
0
def date_fixture(create_db):
    base = datetime(2020, 11, 1)
    date1 = base + timedelta(days=1)
    date2 = base + timedelta(days=2)
    date3 = base + timedelta(days=3)
    offset = 1000

    test1 = TrackedProgram("test1", 10, base.timestamp(),
                           base.timestamp() + offset, 100)
    test2 = TrackedProgram("test2", 10, date1.timestamp(),
                           date1.timestamp() + offset, 100)
    test3 = TrackedProgram("test2", 10, date2.timestamp(),
                           date2.timestamp() + offset, 100)
    test4 = TrackedProgram("test4", 10, date3.timestamp(),
                           date3.timestamp() + offset, 100)
    DataManager.store_many(test1, test2, test3, test4)

    date_values = {
        "test_objs": (test1, test2, test3, test4),
        "date_objs": (base, date1, date2, date3)
    }

    return date_values
Пример #5
0
def test_get_many(reset_db, default_init):
    DataManager.store_many(default_init, default_init)
    result = DataManager.get_many(name=default_init.name)
    assert result[0] == default_init
    assert result[1] == default_init
Пример #6
0
def test_store_many_none(reset_db, default_init):
    # Testing for bug where if no object is given to store_many it shows that an error occured with the db
    DataManager.store_many()

    result = DataManager.query("SELECT * FROM program_log")
    assert result == []