示例#1
0
def add_hofers(filename, data):
    check_hof_data(data)
    program = os.path.basename(filename)[:-4]
    HallOfFamer.objects.filter(program=program).delete()
    for hofer in data['names']:
        HallOfFamer.objects.create(
            program=program,
            name=hofer['name'],
            date=hofer['date'],
            url=hofer.get('url', ''),
        )
示例#2
0
def add_hofers(filename, data):
    check_hof_data(data)
    program = os.path.basename(filename)[:-4]
    HallOfFamer.objects.filter(program=program).delete()
    for hofer in data["names"]:
        HallOfFamer.objects.create(
            program=program,
            name=hofer["name"],
            date=hofer["date"],
            url=hofer.get("url", ""),
        )
示例#3
0
def test_check_hof_data():
    good_names = [{
        'name': 'El Dudarino',
        'date': date(2018, 3, 20),
    }]
    good_data = {'names': good_names * 200}
    # should not raise exception
    check_hof_data(good_data)

    # empty, expect ValueError
    with pytest.raises(ValueError):
        check_hof_data({})

    # wrong, expect ValueError
    with pytest.raises(ValueError):
        check_hof_data({'dude': 'abides'})

    # truncated, expect ValueError
    truncated_data = {'names': good_names * 50}
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)

    # no name, expect ValueError
    truncated_data = {'names': [{'date': date(2018, 3, 20)}] * 200}
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)

    # no date, expect ValueError
    truncated_data = {'names': [{'name': 'Donnie'}] * 200}
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)

    # date wrong format, expect ValueError
    truncated_data = {
        'names': [{
            'name': 'Donnie',
            'date': '2018-03-20'
        }] * 200
    }
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)

    # date too old, expect ValueError
    truncated_data = {
        'names': [{
            'name': 'Donnie',
            'date': date(1999, 12, 31)
        }] * 200
    }
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)
示例#4
0
def test_check_hof_data():
    good_names = [{
        'name': 'El Dudarino',
        'date': date(2018, 3, 20),
    }]
    good_data = {'names': good_names * 200}
    # should not raise exception
    check_hof_data(good_data)

    # empty, expect ValueError
    with pytest.raises(ValueError):
        check_hof_data({})

    # wrong, expect ValueError
    with pytest.raises(ValueError):
        check_hof_data({'dude': 'abides'})

    # truncated, expect ValueError
    truncated_data = {'names': good_names * 50}
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)

    # no name, expect ValueError
    truncated_data = {'names': [{'date': date(2018, 3, 20)}] * 200}
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)

    # no date, expect ValueError
    truncated_data = {'names': [{'name': 'Donnie'}] * 200}
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)

    # date wrong format, expect ValueError
    truncated_data = {'names': [{'name': 'Donnie', 'date': '2018-03-20'}] * 200}
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)

    # date too old, expect ValueError
    truncated_data = {'names': [{'name': 'Donnie', 'date': date(1999, 12, 31)}] * 200}
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)
示例#5
0
def test_check_hof_data():
    good_names = [{
        "name": "El Dudarino",
        "date": date(2018, 3, 20),
    }]
    good_data = {"names": good_names * 200}
    # should not raise exception
    check_hof_data(good_data)

    # empty, expect ValueError
    with pytest.raises(ValueError):
        check_hof_data({})

    # wrong, expect ValueError
    with pytest.raises(ValueError):
        check_hof_data({"dude": "abides"})

    # truncated, expect ValueError
    truncated_data = {"names": good_names * 50}
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)

    # no name, expect ValueError
    truncated_data = {"names": [{"date": date(2018, 3, 20)}] * 200}
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)

    # no date, expect ValueError
    truncated_data = {"names": [{"name": "Donnie"}] * 200}
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)

    # date wrong format, expect ValueError
    truncated_data = {
        "names": [{
            "name": "Donnie",
            "date": "2018-03-20"
        }] * 200
    }
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)

    # date too old, expect ValueError
    truncated_data = {
        "names": [{
            "name": "Donnie",
            "date": date(1999, 12, 31)
        }] * 200
    }
    with pytest.raises(ValueError):
        check_hof_data(truncated_data)