import pytest
from AcadeMeData.forms import UserRegistrationForm
from AcadeMeData.models import User


@pytest.fixture
def user_example():
    user_data = {'username': "shlomi", 'email': "<EMAIL>", 'password1': "<PASSWORD>",
                 'password2': "<PASSWORD>"}
    return user_data


@pytest.fixture
def user_bad_example():
    # username can't be none
    users_data = [
        {'username': "", 'email': "<EMAIL>", 'password1': "<PASSWORD>", 'password2': "<PASSWORD>"},
        # invalid email
        {'username': "good username", 'email': "user", 'password1': "<PASSWORD>", 'password2': "<PASSWORD>"},
        # passqords don't match
        {'username': "good username", 'email': "<EMAIL>", 'password1': "<PASSWORD>",
         'password2': "<PASSWORD>"}]
    return users_data


@pytest.mark.django_db
class TestSignUp:
    def test_sign_up_invalid(self, user_bad_example):
        for user_data in user_bad_example:
            invalid = False
            form = UserRegistrationForm(data=user_data)
            try:
                form.save()
            except ValueError:
                invalid = True
            assert invalid

    def test_sign_up_valid(self, user_example):
        form = UserRegistrationForm(data=user_example)
        if form.is_valid():
            user = form.save()
            assert User.objects.filter(user=user.user).exists()
        else:
            assert False

import pytest
from AcadeMeData.forms import UserRegistrationForm
from AcadeMeData.models import User


@pytest.fixture
def user_example():
    user_data = {'username': "shlomi", 'email': "<EMAIL>", 'password1': "<PASSWORD>",
                 'password2': "<PASSWORD>"}
    return user_data


@pytest.fixture
def user_bad_example():
    # username can't be none
    users_data = [
        {'username': "", 'email': "<EMAIL>", 'password1': "<PASSWORD>", 'password2': "<PASSWORD>"},
        # invalid email
        {'username': "good username", 'email': "user", 'password1': "<PASSWORD>", 'password2': "<PASSWORD>"},
        # passqords don't match
        {'username': "good username", 'email': "<EMAIL>", 'password1': "<PASSWORD>",
         'password2': "<PASSWORD>"}]
    return users_data


@pytest.mark.django_db
class TestSignUp:
    def test_sign_up_invalid(self, user_bad_example):
        for user_data in user_bad_example:
            invalid = False
            form = UserRegistrationForm(data=user_data)
            try:
                form.save()
            except ValueError:
                invalid = True
            assert invalid

    def test_sign_up_valid(self, user_example):
        form = UserRegistrationForm(data=user_example)
        if form.is_valid():
            user = form.save()
            assert User.objects.filter(user=user.user).exists()
        else:
            assert False

# username can't be none # invalid email # passqords don't match