from events.forms import EventForm
from datetime import datetime
import pytest
from users.models import User

pytestmark = pytest.mark.django_db

@pytest.fixture(scope='function')
def user():
    user = User.objects.create(username="test", email="test@test.be", first_name="Test", last_name="Test")
    return user.id

def test_only_title_and_state_required():
    form_data = {
        'title': 'wtf',
        'status': 'j',
        'organizer': user,
    }
    form = EventForm(data=form_data)

    assert form.is_valid(), form.errors


def test_no_stop_but_start():
    form_data = {
        'title': 'wtf',
        'status': 'j',
        'start': datetime(2000, 1, 1),
        'organizer': user,
    }
    form = EventForm(data=form_data)

    assert form.is_valid(), form.errors
    assert form.cleaned_data['start'] == form.cleaned_data['stop']
    assert form.cleaned_data['start'].year == 2000


def test_ready_must_have_date():
    form_data = {
        'title': 'wtf',
        'status': 'r',
    }
    form = EventForm(data=form_data)

    assert not form.is_valid(), form.errors
    assert 'Un événement prêt ou planifié doit avoir une date de début' in form.errors['__all__']


def test_stop_must_be_after_start():
    form_data = {
        'title': 'wtf',
        'status': 'j',
        'start': datetime(2100, 1, 1),
        'stop': datetime(2000, 1, 1)
    }
    form = EventForm(data=form_data)

    assert not form.is_valid()
    assert 'La date de fin ne peut être avant la date de début' in form.errors['__all__']

@@ -139,16 +139,17 @@
 ngo_db%0A%0A
+%0A
 @pytest.
@@ -313,16 +313,17 @@
 ser.id%0A%0A
+%0A
 def test
@@ -409,33 +409,33 @@
      'status': '
-j
+i
 ',%0A        'orga
@@ -617,33 +617,33 @@
      'status': '
-j
+i
 ',%0A        'star
@@ -1119,20 +1119,8 @@
 r%C3%AAt 
-ou planifi%C3%A9 
 doit
@@ -1271,17 +1271,17 @@
 atus': '
-j
+i
 ',%0A     

Fix failing event tests