# Path: wbc/news/models.py
# class Validation(Model):
#     email = models.EmailField(unique=True)
#     entities = models.CharField(max_length=256, blank=True, null=True)
#     code = models.SlugField(max_length=32)
#     action = models.CharField(max_length=16)
# 
#     def save(self, *args, **kwargs):
#         c = string.ascii_lowercase + string.ascii_uppercase + string.digits
#         self.code = ''.join(random.sample(c*32, 32))
#         super(Validation, self).save(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.email
# 
#     class Meta:
#         verbose_name = "Validierung"
#         verbose_name_plural = "Validierung"
# 
# Path: wbc/news/models.py
# class Subscriber(Model):
#     email = models.EmailField(unique=True)
#     entities = models.ManyToManyField(Entity, related_name='subscribers')
# 
#     def __unicode__(self):
#         return self.email
# 
#     class Meta:
#         verbose_name = "Abonnent"
#         verbose_name_plural = "Abonnenten"
# 
# Path: wbc/news/models.py
# class Newsletter(Model):
#     send = models.DateTimeField(verbose_name="Gesendet")
#     n = models.IntegerField(verbose_name="Anzahl Mails")
# 
#     def __unicode__(self):
#         return self.send.strftime("%d. %m. %Y, %H:%M:%S")
# 
#     class Meta:
#         verbose_name = "Newsletter"
#         verbose_name_plural = "Newsletter"
# 
# Path: wbc/region/models.py
# class Entity(Model):
#     name = models.CharField(max_length=256)
#     description = models.TextField(blank=True)
#     lat = models.FloatField(null=True, blank=True)
#     lon = models.FloatField(null=True, blank=True)
#     polygon = models.TextField(blank=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = 'Einheit'
#         verbose_name_plural = 'Einheiten'
# 
# class Muncipality(Entity):
# 
#     class Meta:
#         verbose_name = 'Gemeinde'
#         verbose_name_plural = 'Gemeinden'
# 
# class District(Entity):
#     muncipality = models.ForeignKey(Muncipality, related_name='districts')
# 
#     class Meta:
#         verbose_name = 'Bezirk'
#         verbose_name_plural = 'Bezirke'
# 
# Path: wbc/news/forms.py
# class SubscribeForm(forms.Form):
#     def __init__(self, *args, **kwargs):
#         if 'entities' in kwargs:
#             entities = kwargs.pop('entities')
# 
#         kwargs['label_suffix'] = ''
#         super(SubscribeForm, self).__init__(*args, **kwargs)
# 
#         for entity in entities:
#             field = forms.BooleanField(label=entity['name'],required=False);
#             self.fields[str(entity['id'])] = field
# 
#         self.fields['email'] = forms.EmailField(label='Email',
#                                                 widget=forms.TextInput(attrs={'class':'form-control'}))


from django.test import TestCase
from django.test import Client
from .models import Validation
from .models import Subscriber
from .models import Newsletter
from wbc.region.models import Entity, Muncipality, District
from .models import *
from .forms import SubscribeForm
from django.test.client import RequestFactory
from django.utils.timezone import now
from django.core.urlresolvers import reverse
        import json
# -*- coding: utf-8 -*-

# Test for Models


class NewsTestCase(TestCase):

    def create_validation(email='test@test.de', code='xyz', action='action'):
        return Validation.objects.create(email=email, code=code, action=action)

    def test_validation(self):
        v = self.create_validation()
        self.assertTrue(isinstance(v, Validation))
        self.assertEqual(
            v.__unicode__(), v.email)


class SubscriberTestCase(TestCase):

    def setUp(self):
        self.entity = Entity(name='München').save()
        self.entity2 = Entity(name='Hamburg').save()
        Muncipality(name='Berlin').save()

# Path: wbc/news/models.py
# class Validation(Model):
#     email = models.EmailField(unique=True)
#     entities = models.CharField(max_length=256, blank=True, null=True)
#     code = models.SlugField(max_length=32)
#     action = models.CharField(max_length=16)
# 
#     def save(self, *args, **kwargs):
#         c = string.ascii_lowercase + string.ascii_uppercase + string.digits
#         self.code = ''.join(random.sample(c*32, 32))
#         super(Validation, self).save(*args, **kwargs)
# 
#     def __unicode__(self):
#         return self.email
# 
#     class Meta:
#         verbose_name = "Validierung"
#         verbose_name_plural = "Validierung"
# 
# Path: wbc/news/models.py
# class Subscriber(Model):
#     email = models.EmailField(unique=True)
#     entities = models.ManyToManyField(Entity, related_name='subscribers')
# 
#     def __unicode__(self):
#         return self.email
# 
#     class Meta:
#         verbose_name = "Abonnent"
#         verbose_name_plural = "Abonnenten"
# 
# Path: wbc/news/models.py
# class Newsletter(Model):
#     send = models.DateTimeField(verbose_name="Gesendet")
#     n = models.IntegerField(verbose_name="Anzahl Mails")
# 
#     def __unicode__(self):
#         return self.send.strftime("%d. %m. %Y, %H:%M:%S")
# 
#     class Meta:
#         verbose_name = "Newsletter"
#         verbose_name_plural = "Newsletter"
# 
# Path: wbc/region/models.py
# class Entity(Model):
#     name = models.CharField(max_length=256)
#     description = models.TextField(blank=True)
#     lat = models.FloatField(null=True, blank=True)
#     lon = models.FloatField(null=True, blank=True)
#     polygon = models.TextField(blank=True)
# 
#     def __unicode__(self):
#         return self.name
# 
#     class Meta:
#         verbose_name = 'Einheit'
#         verbose_name_plural = 'Einheiten'
# 
# class Muncipality(Entity):
# 
#     class Meta:
#         verbose_name = 'Gemeinde'
#         verbose_name_plural = 'Gemeinden'
# 
# class District(Entity):
#     muncipality = models.ForeignKey(Muncipality, related_name='districts')
# 
#     class Meta:
#         verbose_name = 'Bezirk'
#         verbose_name_plural = 'Bezirke'
# 
# Path: wbc/news/forms.py
# class SubscribeForm(forms.Form):
#     def __init__(self, *args, **kwargs):
#         if 'entities' in kwargs:
#             entities = kwargs.pop('entities')
# 
#         kwargs['label_suffix'] = ''
#         super(SubscribeForm, self).__init__(*args, **kwargs)
# 
#         for entity in entities:
#             field = forms.BooleanField(label=entity['name'],required=False);
#             self.fields[str(entity['id'])] = field
# 
#         self.fields['email'] = forms.EmailField(label='Email',
#                                                 widget=forms.TextInput(attrs={'class':'form-control'}))


# Path: wbc/news/tests.py
from django.test import TestCase
from django.test import Client
from .models import Validation
from .models import Subscriber
from .models import Newsletter
from wbc.region.models import Entity, Muncipality, District
from .models import *
from .forms import SubscribeForm
from django.test.client import RequestFactory
from django.utils.timezone import now
from django.core.urlresolvers import reverse
        import json

# -*- coding: utf-8 -*-

# Test for Models


class NewsTestCase(TestCase):

    def create_validation(email='test@test.de', code='xyz', action='action'):
        return Validation.objects.create(email=email, code=code, action=action)

    def test_validation(self):
        v = self.create_validation()
        self.assertTrue(isinstance(v, Validation))
        self.assertEqual(
            v.__unicode__(), v.email)


class SubscriberTestCase(TestCase):

    def setUp(self):
        self.entity = Entity(name='München').save()
        self.entity2 = Entity(name='Hamburg').save()
        Muncipality(name='Berlin').save()

        self.muncipality = Muncipality.objects.get(name='Berlin')