示例#1
0
def test_submit(model: Model, mocker: MockFixture):
    mock_ttg = mocker.patch('usc_lr_timer.model.talk_to_google.talk_to_google')
    mock_ttg.return_value = Results.success, None
    model._name = None
    assert model.submit(True) == SubmitResult(None, 'Name not chosen')
    model._name = 'Vincent'
    assert model.submit(True) == SubmitResult(None, 'Category not chosen')
    model._categories = ['', 'testing']
    model.set_category_index(1)
    model.set_manual_minutes(61)
    model.set_manual_seconds(61)
    result = SubmitResult(None, 'Minutes must be between 0 and 60')
    assert model.submit(True) == result
    model.set_manual_minutes(0)
    result = SubmitResult(None, 'Seconds must be between 0 and 60')
    assert model.submit(True) == result
    model.set_manual_seconds(0)
    assert model.submit(True) == SubmitResult(None, 'No time recorded')
    model.set_manual_seconds(42)
    assert model.submit(True) == SubmitResult(Results.success, None)
    mock_ttg.assert_called_with(
        google_sheets.add_time,
        spreadsheet_id='abc123',
        name='Vincent',
        semester='Fall',
        duration=timedelta(seconds=42),
        category='testing',
    )
    assert model.submit(False) == SubmitResult(None, 'No time recorded')
    model.increment_duration(24)
    assert model.submit(False) == SubmitResult(Results.success, None)
    mock_ttg.assert_called_with(
        google_sheets.add_time,
        spreadsheet_id='abc123',
        name='Vincent',
        semester='Fall',
        duration=timedelta(seconds=24),
        category='testing',
    )
示例#2
0
def test_sync(
    view: View, window: MainWindow, model: Model, model_mock_ttg: Mock
):
    model_mock_ttg.return_value = Results.success, ['a', 'b']
    model._semesters = ['Summer', 'Darkness']
    model.set_manual_hours(1)
    model.set_manual_minutes(2)
    model.set_manual_seconds(3)
    view.sync()
    sems = [
        window.semesters_cb.itemText(i)
        for i in range(window.semesters_cb.count())
    ]
    assert sems == ['Summer', 'Darkness']
    cats = [
        window.categories_cb.itemText(i)
        for i in range(window.categories_cb.count())
    ]
    assert cats == ['', 'a', 'b']
    assert window.hours_input.text() == '1'
    assert window.minutes_input.text() == '2'
    assert window.seconds_input.text() == '3'
    assert window.duration_field.text() == '00:00:00'
示例#3
0
def test_set_manual_minutes(model: Model):
    assert model.manual_minutes == 0
    model.set_manual_minutes(1)
    assert model.manual_minutes == 1