# Path: organization/models.py
# class Organization(models.Model):
#     name = models.CharField(_('Name'), max_length=100)
#     slug = AutoSlugField(populate_from='name', overwrite=True,
#                          max_length=200, unique=True, db_index=True)
#     about = models.TextField(
#         _('About'), max_length=10000, blank=True)
# 
#     # relations
#     created_by = models.ForeignKey(
#         to=settings.AUTH_USER_MODEL, related_name='organizations'
#     )
# 
#     def __str__(self):
#         return six.text_type(self.name)


from django.core.urlresolvers import reverse
from django.test import Client, TestCase
from django.contrib.auth import get_user_model
from organization.models import Organization



class OrganizationTest(TestCase):
    fixtures = ['user.json']

    def setUp(self):
        User = get_user_model()
        self.user = User.objects.get(username='user')
        self.client = Client()
        self.client.login(username='user', password='user')

    def test_create_organization(self):
        url = reverse('create_organization')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        data = {'name': 'Speakerfight Corp', 'about': 'Cool company'}
        url = reverse('create_organization')
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(
            response,
            reverse('update_organization', kwargs={'slug': 'speakerfight-corp'})
        )

# Path: organization/models.py
# class Organization(models.Model):
#     name = models.CharField(_('Name'), max_length=100)
#     slug = AutoSlugField(populate_from='name', overwrite=True,
#                          max_length=200, unique=True, db_index=True)
#     about = models.TextField(
#         _('About'), max_length=10000, blank=True)
# 
#     # relations
#     created_by = models.ForeignKey(
#         to=settings.AUTH_USER_MODEL, related_name='organizations'
#     )
# 
#     def __str__(self):
#         return six.text_type(self.name)


# Path: organization/tests/test_functional.py
from django.core.urlresolvers import reverse
from django.test import Client, TestCase
from django.contrib.auth import get_user_model
from organization.models import Organization




class OrganizationTest(TestCase):
    fixtures = ['user.json']

    def setUp(self):
        User = get_user_model()
        self.user = User.objects.get(username='user')
        self.client = Client()
        self.client.login(username='user', password='user')

    def test_create_organization(self):
        url = reverse('create_organization')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        data = {'name': 'Speakerfight Corp', 'about': 'Cool company'}
        url = reverse('create_organization')
        response = self.client.post(url, data)
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(
            response,
            reverse('update_organization', kwargs={'slug': 'speakerfight-corp'})
        )

        self.assertEqual(Organization.objects.count(), 1)