def test_result(): fake = faker.Faker() competitor1 = helpers.create_competitor_entity() competitor2 = helpers.create_competitor_entity() competitor3 = helpers.create_competitor_entity() competitors = [competitor1, competitor2, competitor3] phase = helpers.create_phase_entity(competitors=competitors) random.shuffle(competitors) result = [ phase_entities.Result( competitor=competitor, result={fake.word(): fake.random_int()}, ) for competitor in competitors ] phase.results = result assert phase.results == result
def test_tournament_validator_raises(fields, expected_exception): fake = faker.Faker() with pytest.raises(expected_exception): entities.Tournament( name=fields.get('name', fake.word()), start_date=fields.get('start_date', datetime.date(2018, 1, 1)), end_date=fields.get('end_date', datetime.date(2018, 1, 2)), competitors=fields.get('competitors', [helpers.create_competitor_entity()]), )
def test_competitor_validator_raises(values, expected_exception): fake = faker.Faker() phase_id = values.get('phase_id', fake.random_int(0, 10000)) round = values.get('round', fake.random_int(1, 10)) position = values.get('position', fake.random_int(0, 3)) pool = values.get('pool', fake.random_int(0, 4)) competitors = values.get( 'competitors', [ helpers.create_competitor_entity(), helpers.create_competitor_entity(), ], ) with pytest.raises(expected_exception): match.Match( phase_id=phase_id, round=round, position=position, pool=pool, competitors=competitors, )
def test_match_result(): fake = faker.Faker() competitor1 = helpers.create_competitor_entity() competitor2 = helpers.create_competitor_entity() match = helpers.create_match_entity(competitors=[competitor1, competitor2]) result1 = { fake.word(): fake.random_int(), fake.word(): fake.random_int(), } result2 = { fake.word(): fake.random_int(), fake.word(): fake.random_int(), } match.set_result(competitor1, result1) match.set_result(competitor2, result2) assert match.result[0].competitor == competitor1 assert match.result[0].result == result1 assert match.result[1].competitor == competitor2 assert match.result[1].result == result2
def test_competitor_exists(): fake = faker.Faker() name = fake.word() start_date = fake.date_object() end_date = start_date + datetime.timedelta(days=2) competitors = [ helpers.create_competitor_entity(), helpers.create_competitor_entity(), ] tournament = entities.Tournament( name=name, start_date=start_date, end_date=end_date, competitors = competitors, ) assert tournament.name == name assert tournament.start_date == start_date assert tournament.end_date == end_date assert tournament.competitors == competitors
def test_match_exists(): fake = faker.Faker() phase_id = fake.random_int(0, 10000) round = fake.random_int(1, 10) position = fake.random_int(0, 3) pool = fake.random_int(0, 4) competitors = [ helpers.create_competitor_entity(), helpers.create_competitor_entity(), ] entity = match.Match( phase_id=phase_id, round=round, position=position, pool=pool, competitors=competitors, ) assert entity.phase_id == phase_id assert entity.round == round assert entity.position == position assert entity.pool == pool assert entity.competitors == competitors
def test_pools(phase_entity): competitors_pool_1 = [helpers.create_competitor_entity()] competitors_pool_3 = [ helpers.create_competitor_entity(), helpers.create_competitor_entity(), ] for competitor in competitors_pool_3: phase_entity.competitors.append(competitor, pool=3) for competitor in competitors_pool_1: phase_entity.competitors.append(competitor, pool=1) assert len(phase_entity.pools) == 2 assert phase_entity.pools[0].id == 1 expected_competitors = {c.id for c in competitors_pool_1} actual_competitors = {c.id for c in phase_entity.pools[0].competitors} assert expected_competitors == actual_competitors assert phase_entity.pools[1].id == 3 expected_competitors = {c.id for c in competitors_pool_3} actual_competitors = {c.id for c in phase_entity.pools[1].competitors} assert expected_competitors == actual_competitors
def competitor_entity(): return helpers.create_competitor_entity()
def test_match_result_order(): match = helpers.create_match_entity(competitors=[ helpers.create_competitor_entity() for _ in range(0, 2) ], ) assert [r.competitor for r in match.result] == match.competitors