Beispiel #1
0
def test_create_from_input__no_static_data(hallo_getter, requests_mock):
    # Setup stuff
    command_name = "setup dailys field"
    command_args = "mood"
    hallo_obj, test_server, test_chan, test_user = hallo_getter({"dailys"})
    evt = EventMessage(
        test_server,
        test_chan,
        test_user,
        "{} {}".format(command_name, command_args),
    )
    evt.split_command_text(command_name, command_args)
    spreadsheet = DailysSpreadsheetMock(test_user, test_chan)
    requests_mock.get("{}/stats/mood/static/".format(spreadsheet.dailys_url),
                      json=[])

    # Try and create dailys field
    with pytest.raises(hallo.modules.dailys.dailys_field.DailysException) as e:
        DailysMoodField.create_from_input(evt, spreadsheet)
    assert "mood field static data has not been set up on dailys system" in str(
        e.value).lower()
Beispiel #2
0
def test_create_from_input(hallo_getter, requests_mock):
    dailys_times = ["WakeUpTime", "12:00:00", "SleepTime"]
    dailys_moods = ["happiness", "anger", "tiredness", "boisterousness"]
    # Setup stuff
    command_name = "setup dailys field"
    command_args = "mood"
    hallo_obj, test_server, test_chan, test_user = hallo_getter({"dailys"})
    evt = EventMessage(
        test_server,
        test_chan,
        test_user,
        "{} {}".format(command_name, command_args),
    )
    evt.split_command_text(command_name, command_args)
    spreadsheet = DailysSpreadsheetMock(test_user, test_chan)
    requests_mock.get("{}/stats/mood/static/".format(spreadsheet.dailys_url),
                      json=[{
                          "date": "static",
                          "source": "Mock test data",
                          "stat_name": "mood",
                          "data": {
                              "moods": dailys_moods,
                              "times": dailys_times
                          }
                      }])

    # Try and create dailys field
    field = DailysMoodField.create_from_input(evt, spreadsheet)

    assert field.spreadsheet == spreadsheet
    assert isinstance(field.times, list)
    assert len(field.times) == 3
    assert DailysMoodField.TIME_WAKE in field.times
    assert DailysMoodField.TIME_SLEEP in field.times
    assert time(12, 0, 0) in field.times
    assert isinstance(field.moods, list)
    assert len(field.moods) == 4
    assert field.moods == dailys_moods