# Path: wbc/core/forms.py
# class LoginForm(forms.Form):
#     username = forms.CharField(max_length=255, required=True)
#     password = forms.CharField(widget=forms.PasswordInput, required=True)
# 
#     def clean(self):
#         username = self.cleaned_data.get('username')
#         password = self.cleaned_data.get('password')
#         user = authenticate(username=username, password=password)
#         if not user:
#             raise forms.ValidationError(
#                 "Benutzername und/oder Passwort ist falsch.")
#         return self.cleaned_data
# 
#     def login(self, request):
#         username = self.cleaned_data.get('username')
#         password = self.cleaned_data.get('password')
#         user = authenticate(username=username, password=password)
#         return user
# 
# Path: wbc/region/models.py
# class District(Entity):
#     muncipality = models.ForeignKey(Muncipality, related_name='districts')
# 
#     class Meta:
#         verbose_name = 'Bezirk'
#         verbose_name_plural = 'Bezirke'
# 
# Path: wbc/region/models.py
# class Muncipality(Entity):
# 
#     class Meta:
#         verbose_name = 'Gemeinde'
#         verbose_name_plural = 'Gemeinden'


from django.test import TestCase
from django.test import Client
from django.contrib.auth.models import User
from django.test.client import RequestFactory
from django.core.urlresolvers import reverse
from wbc.core.forms import LoginForm
from wbc.region.models import District
from wbc.region.models import Muncipality
            '', {'username': 'john', 'password': 'johnpassword'})
        form = LoginForm(request.POST)
        self.assertTrue(form.is_valid())

    def test_invalid_form(self):
        request = self.factory.post(
            '', {'username': 'john', 'password': ''})
        form = LoginForm(request.POST)
        self.assertFalse(form.is_valid())

    def test_form_login(self):
        request = self.factory.post('', {'username': 'john', 'password': 'johnpassword'})
        form = LoginForm(request.POST)
        self.assertTrue(form.is_valid())
        user = form.login(request)
        self.assertTrue(user, self.user)

# view tests

class CoreViewTestCase(TestCase):

    def setUp(self):
        Muncipality(name='Berlin').save()

        self.d1 = District(
            name='Mitte',
            muncipality=Muncipality.objects.get(name='Berlin')
        )
        self.d1.save()


# Path: wbc/core/forms.py
# class LoginForm(forms.Form):
#     username = forms.CharField(max_length=255, required=True)
#     password = forms.CharField(widget=forms.PasswordInput, required=True)
# 
#     def clean(self):
#         username = self.cleaned_data.get('username')
#         password = self.cleaned_data.get('password')
#         user = authenticate(username=username, password=password)
#         if not user:
#             raise forms.ValidationError(
#                 "Benutzername und/oder Passwort ist falsch.")
#         return self.cleaned_data
# 
#     def login(self, request):
#         username = self.cleaned_data.get('username')
#         password = self.cleaned_data.get('password')
#         user = authenticate(username=username, password=password)
#         return user
# 
# Path: wbc/region/models.py
# class District(Entity):
#     muncipality = models.ForeignKey(Muncipality, related_name='districts')
# 
#     class Meta:
#         verbose_name = 'Bezirk'
#         verbose_name_plural = 'Bezirke'
# 
# Path: wbc/region/models.py
# class Muncipality(Entity):
# 
#     class Meta:
#         verbose_name = 'Gemeinde'
#         verbose_name_plural = 'Gemeinden'


# Path: wbc/core/tests.py
from django.test import TestCase
from django.test import Client
from django.contrib.auth.models import User
from django.test.client import RequestFactory
from django.core.urlresolvers import reverse
from wbc.core.forms import LoginForm
from wbc.region.models import District
from wbc.region.models import Muncipality

            '', {'username': 'john', 'password': 'johnpassword'})
        form = LoginForm(request.POST)
        self.assertTrue(form.is_valid())

    def test_invalid_form(self):
        request = self.factory.post(
            '', {'username': 'john', 'password': ''})
        form = LoginForm(request.POST)
        self.assertFalse(form.is_valid())

    def test_form_login(self):
        request = self.factory.post('', {'username': 'john', 'password': 'johnpassword'})
        form = LoginForm(request.POST)
        self.assertTrue(form.is_valid())
        user = form.login(request)
        self.assertTrue(user, self.user)

# view tests

class CoreViewTestCase(TestCase):

    def setUp(self):
        Muncipality(name='Berlin').save()

        self.d1 = District(
            name='Mitte',
            muncipality=Muncipality.objects.get(name='Berlin')
        )
        self.d1.save()


        self.d2 = District(