コード例 #1
0
def test_model_update_match_gamblers(match1, g1):
    # freeze_time() 须为 utc 时间

    # 盘口未定 不能投注
    with freeze_time('2018-03-31 03:59:59'):
        model.update_match_gamblers(match1.id, 'a', g1)
        match_found = model.find_match_by_id(match1.id)
        assert 'g1' not in match_found.a[
            'gamblers'] and 'g1' not in match_found.b['gamblers']

    # 盘口已定 开赛前 第一次投注
    with freeze_time('2018-03-31 04:00:01'):
        model.update_match_gamblers(match1.id, 'a', g1)
        match_found = model.find_match_by_id(match1.id)
        assert 'g1' in match_found.a['gamblers'] and 'g1' not in match_found.b[
            'gamblers']

    # 盘口已定 开赛前 改注
    with freeze_time('2018-03-31 04:00:03'):
        model.update_match_gamblers(match1.id, 'b', g1)
        match_found = model.find_match_by_id(match1.id)
        assert 'g1' not in match_found.a['gamblers'] and 'g1' in match_found.b[
            'gamblers']

    # 开赛后 投注结果不再改变
    with freeze_time('2018-03-31 11:30:01'):
        model.update_match_gamblers(match1.id, 'a', g1)
        match_found = model.find_match_by_id(match1.id)
        assert 'g1' not in match_found.a['gamblers'] and 'g1' in match_found.b[
            'gamblers']
コード例 #2
0
def test_model_update_match_score(match1):
    model.update_match_score(match1.id, "1", "0")
    match_found = model.find_match_by_id(match1.id)
    assert match_found.a['score'] == 1 and match_found.b['score'] == 0

    model.update_match_score(match1.id, "2", "3")
    match_found = model.find_match_by_id(match1.id)
    assert match_found.a['score'] == 2 and match_found.b['score'] == 3
コード例 #3
0
def test_model_update_match_time(match1):
    orig_time = match1.match_time

    next_time = orig_time + datetime.timedelta(hours=1)
    next_id = model._generate_match_id(match_time=next_time,
                                       team_a=match1.a['team'],
                                       team_b=match1.b['team'])

    assert model.find_match_by_id(match_id=next_id) is None

    model.update_match_time(match_id=match1.id, match_time=next_time)

    assert model.find_match_by_id(match_id=next_id).match_time == next_time
コード例 #4
0
def test_model_update_match_handicap(match1):
    # freeze_time() 须为 utc 时间

    with freeze_time('2018-03-31 04:00:01'):
        model.update_match_handicap(match1.id, '半球/一球')
        match_found = model.find_match_by_id(match1.id)
        assert match_found.handicap_display == '受一球' and match_found.handicap == (
            -1, -1)

    with freeze_time('2018-03-31 03:59:59'):
        model.update_match_handicap(match1.id, '半球/一球', cutoff_check=False)
        match_found = model.find_match_by_id(match1.id)
        assert match_found.handicap_display == '半球/一球' and match_found.handicap == (
            0.5, 1)
コード例 #5
0
def test_Match_update_profit_and_loss_with_self_auction(
        choice_a, choice_b, no_choice, handicap, score_a, score_b, expected,
        auction2):
    # prepare gamblers
    choice_a = [model.insert_gambler(g) for g in choice_a]
    choice_b = [model.insert_gambler(g) for g in choice_b]
    no_choice = [model.insert_gambler(g) for g in no_choice]

    # prepare match
    match = model.insert_match('硬糙', datetime.datetime(2018, 4, 1, 20, 30),
                               '平手', '水宫', '纽尔联', 1.01, 1.39, 0, 1)

    # prepare bet choice
    for g in choice_a:
        model.update_match_gamblers(match.id, 'a', g, cutoff_check=False)

    for g in choice_b:
        model.update_match_gamblers(match.id, 'b', g, cutoff_check=False)

    # prepare match score
    model.update_match_score(match.id, score_a, score_b)

    # prepare match handicap
    model.update_match_handicap(match.id, handicap, cutoff_check=False)

    # calculate PNL
    match = model.find_match_by_id(match.id)
    result = match.update_profit_and_loss_result(
        required_gamblers=model.find_gamblers())

    for k, v in expected.items():
        assert result.get(k) == v
コード例 #6
0
def test_model_update_match_weight(match1):
    model.update_match_weight(match1.id, 4)
    match_found = model.find_match_by_id(match1.id)
    assert match_found.weight == 4
コード例 #7
0
def test_model_find_match_by_id(match1):
    found = model.find_match_by_id(match1.id)
    assert found == match1