Пример #1
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
Пример #2
0
def test_model_drop_user(auction2, match1, match2, g1):
    model.update_match_gamblers(match1.id, 'a', g1, cutoff_check=False)
    model.update_match_gamblers(match2.id, 'b', g1, cutoff_check=False)

    # drop user by name
    model.drop_user(g1.name)
    # user dropped successfully
    assert not model.find_user_by_name(g1.name)

    # match / auction remains untouched
    assert db.match.find({'a.gamblers': g1.name}).count() == 1
    assert db.match.find({'b.gamblers': g1.name}).count() == 1
    assert db.auction.find({'gambler': g1.name}).count() == 2
Пример #3
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']
Пример #4
0
def test_model_update_user_name(auction2, match1, match2, g1, g2):
    G1_NEW = '巨型钻'

    model.update_match_gamblers(match1.id, 'a', g1, cutoff_check=False)
    model.update_match_gamblers(match2.id, 'b', g1, cutoff_check=False)

    model.update_user_name(current=g1.name, new=G1_NEW)
    # gambler
    assert model.find_user_by_name(G1_NEW)
    # match
    assert db.match.find({'a.gamblers': G1_NEW}).count() == 1
    assert db.match.find({'b.gamblers': G1_NEW}).count() == 1
    # auction
    assert db.auction.find({'gambler': G1_NEW}).count() == 2

    G2_NEW = '小型钻'

    model.update_match_gamblers(match1.id, 'b', g2, cutoff_check=False)
    model.update_match_gamblers(match2.id, 'b', g2, cutoff_check=False)

    model.update_user_name(current=g2.name, new=G2_NEW)
    # gambler
    assert model.find_user_by_name(G2_NEW)
    # match
    assert db.match.find({'a.gamblers': G2_NEW}).count() == 0
    assert db.match.find({'b.gamblers': G2_NEW}).count() == 2
    # auction
    assert db.auction.find({'gambler': G2_NEW}).count() == 2
Пример #5
0
def test_model_update_match_gamblers_signup(match1, u0):
    assert model.find_gamblers() == []
    model.update_match_gamblers(match1.id, 'a', u0, cutoff_check=False)
    assert model.find_gamblers() == [u0]