# Path: foosball/games/forms.py
# class GameForm(SuperForm):
#     game = ModelFormField(GameModelForm)
#     team1 = ModelFormField(TeamModelForm)
#     team2 = ModelFormField(TeamModelForm)
# 
#     def is_valid(self):
#         return super().is_valid() & clean_team_forms(self.forms['team1'], self.forms['team2'])


import pytest
from django.utils.translation import ugettext_lazy as _
from foosball.games.forms import GameForm

@pytest.mark.django_db
def test_game_form_smoke_test(game_form_data, four_users):
    form = GameForm(data=game_form_data)
    assert form.is_valid()


@pytest.mark.django_db
def test_game_form_player_limit(game_form_data, four_users):
    game_form_data.update({
        'form-team1-players': [1, 2, 3],
        'form-team2-players': [4]
    })
    form = GameForm(data=game_form_data)
    assert not form.is_valid()
    assert _('Maximum number of players is two.') in form.forms['team1'].errors['players']


@pytest.mark.parametrize('team1, team2', [
    ([1, 2], [1, 2]),
    ([1, 2], [2, 3]),
    ([1], [1, 2]),
    ([1], [1])
])
@pytest.mark.django_db
def test_game_form_overlapping_players(game_form_data, four_users, team1, team2):
    game_form_data.update({
        'form-team1-players': team1,
        'form-team2-players': team2
    })

# Path: foosball/games/forms.py
# class GameForm(SuperForm):
#     game = ModelFormField(GameModelForm)
#     team1 = ModelFormField(TeamModelForm)
#     team2 = ModelFormField(TeamModelForm)
# 
#     def is_valid(self):
#         return super().is_valid() & clean_team_forms(self.forms['team1'], self.forms['team2'])


# Path: foosball/games/tests/test_forms.py
import pytest
from django.utils.translation import ugettext_lazy as _
from foosball.games.forms import GameForm


@pytest.mark.django_db
def test_game_form_smoke_test(game_form_data, four_users):
    form = GameForm(data=game_form_data)
    assert form.is_valid()


@pytest.mark.django_db
def test_game_form_player_limit(game_form_data, four_users):
    game_form_data.update({
        'form-team1-players': [1, 2, 3],
        'form-team2-players': [4]
    })
    form = GameForm(data=game_form_data)
    assert not form.is_valid()
    assert _('Maximum number of players is two.') in form.forms['team1'].errors['players']


@pytest.mark.parametrize('team1, team2', [
    ([1, 2], [1, 2]),
    ([1, 2], [2, 3]),
    ([1], [1, 2]),
    ([1], [1])
])
@pytest.mark.django_db
def test_game_form_overlapping_players(game_form_data, four_users, team1, team2):
    game_form_data.update({
        'form-team1-players': team1,
        'form-team2-players': team2
    })

    form = GameForm(data=game_form_data)