from django.core import mail
from django.test import TestCase

from core.models import Event, User
from core.forms import AddOrganizerForm


class TestAddOrganizerForm(TestCase):

    def setUp(self):
        self.event = Event.objects.create(name='Test',
                                          city='Test',
                                          country='Test')
        self.user = User.objects.create_user('test')

    def test_notify_new_user(self):
        form = AddOrganizerForm({'event': str(self.event),
                                 'organizer': 'Test',
                                 'email': 'test@test.com'})
        if form.is_valid():
            form.notify_new_user(self.user)
            self.assertEqual(len(mail.outbox), 1)
            self.assertEqual(mail.outbox[0].content_type, 'text/html')

    def test_notify_exisiting_user(self):
        form = AddOrganizerForm({'event': str(self.event),
                                 'organizer': 'Test',
                                 'email': 'test@test.com'})
        if form.is_valid():
            form.notify_existing_user(self.user)
            self.assertEqual(len(mail.outbox), 1)
            self.assertEqual(mail.outbox[0].content_type, 'text/html')

@@ -365,24 +365,26 @@
 st')%0A       
+ #
  self.user =
@@ -415,16 +415,43 @@
 r('test'
+, password='SecretPassword'
 )%0A%0A    d
@@ -505,32 +505,37 @@
 ddOrganizerForm(
+data=
 %7B'event': str(se
@@ -520,36 +520,32 @@
 (data=%7B'event': 
-str(
 self.event),%0A   
@@ -530,35 +530,39 @@
 ent': self.event
-)
 ,%0A
+     
                 
@@ -584,39 +584,44 @@
   'organizer': '
-T
+t
 est',%0A
+     
                 
@@ -666,33 +666,33 @@
 om'%7D)%0A        if
- 
+(
 form.is_valid():
@@ -682,34 +682,66 @@
 (form.is_valid()
+)
 :%0A
+            user = form.save()%0A
             form
@@ -753,29 +753,24 @@
 fy_new_user(
-self.
 user)%0A      
@@ -973,12 +973,8 @@
 t': 
-str(
 self
@@ -979,17 +979,16 @@
 lf.event
-)
 ,%0A      
@@ -1105,17 +1105,17 @@
       if
- 
+(
 form.is_
@@ -1121,18 +1121,50 @@
 _valid()
+)
 :%0A
+            user = form.save()%0A
         
@@ -1193,21 +1193,16 @@
 ng_user(
-self.
 user)%0A  

Improve forms tests