# Path: rolf/rolf_main/models.py
# class Category(models.Model):
#     name = models.CharField(max_length=256)
# 
#     class Meta:
#         ordering = ('name',)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return "/category/%d/" % self.id
# 
# class Stage(models.Model):
#     name = models.CharField(max_length=256)
#     deployment = models.ForeignKey(Deployment)
#     recipe = models.ForeignKey(Recipe)
# 
#     class Meta:
#         order_with_respect_to = "deployment"
# 
#     def get_absolute_url(self):
#         return "/stage/%d/" % self.id
# 
#     def all_recipes(self):
#         """ helper to make this available in generic templates """
#         return Recipe.objects.all().exclude(name="").exclude(id=self.recipe.id)
# 
# Path: rolf/rolf_main/tests/mixins.py
# class LoggedInTestMixin(TestCase):
#     def setUp(self):
#         self.u = User.objects.create(username='testuser')
#         self.u.set_password('test')
#         self.u.save()
#         self.client.login(username='testuser', password='test')


from urlparse import urlparse
from django.contrib.auth.models import Group
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
from factories import UserFactory, CategoryFactory, ApplicationFactory
from factories import DeploymentFactory, StageFactory
from rolf.rolf_main.models import Category, Stage
from rolf.rolf_main.tests.mixins import LoggedInTestMixin
    def test_root(self):
        self.c = Client()
        self.u = UserFactory()
        self.u.set_password("test")
        self.u.save()

        self.c.login(username=self.u.username, password="test")
        response = self.c.get("/")
        self.assertEquals(response.status_code, 200)


class CrudTest(TestCase):
    def setUp(self):
        self.c = Client()
        self.u = UserFactory(is_staff=True)
        self.u.set_password("test")
        self.u.save()
        # need to make the user have at least one group
        g = Group.objects.create(name=self.u.username)
        g.user_set.add(self.u)
        g.save()
        self.c.login(username=self.u.username, password="test")

    def test_category_crud(self):
        r = self.c.get("/")
        self.assertFalse("test category" in r.content)
        r = self.c.post("/category/add/", {'name': 'test category'})
        self.assertEqual(r.status_code, 302)
        r = self.c.get("/")
        self.assertTrue("test category" in r.content)

# Path: rolf/rolf_main/models.py
# class Category(models.Model):
#     name = models.CharField(max_length=256)
# 
#     class Meta:
#         ordering = ('name',)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return "/category/%d/" % self.id
# 
# class Stage(models.Model):
#     name = models.CharField(max_length=256)
#     deployment = models.ForeignKey(Deployment)
#     recipe = models.ForeignKey(Recipe)
# 
#     class Meta:
#         order_with_respect_to = "deployment"
# 
#     def get_absolute_url(self):
#         return "/stage/%d/" % self.id
# 
#     def all_recipes(self):
#         """ helper to make this available in generic templates """
#         return Recipe.objects.all().exclude(name="").exclude(id=self.recipe.id)
# 
# Path: rolf/rolf_main/tests/mixins.py
# class LoggedInTestMixin(TestCase):
#     def setUp(self):
#         self.u = User.objects.create(username='testuser')
#         self.u.set_password('test')
#         self.u.save()
#         self.client.login(username='testuser', password='test')


# Path: rolf/rolf_main/tests/test_views.py
from urlparse import urlparse
from django.contrib.auth.models import Group
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import Client
from factories import UserFactory, CategoryFactory, ApplicationFactory
from factories import DeploymentFactory, StageFactory
from rolf.rolf_main.models import Category, Stage
from rolf.rolf_main.tests.mixins import LoggedInTestMixin

    def test_root(self):
        self.c = Client()
        self.u = UserFactory()
        self.u.set_password("test")
        self.u.save()

        self.c.login(username=self.u.username, password="test")
        response = self.c.get("/")
        self.assertEquals(response.status_code, 200)


class CrudTest(TestCase):
    def setUp(self):
        self.c = Client()
        self.u = UserFactory(is_staff=True)
        self.u.set_password("test")
        self.u.save()
        # need to make the user have at least one group
        g = Group.objects.create(name=self.u.username)
        g.user_set.add(self.u)
        g.save()
        self.c.login(username=self.u.username, password="test")

    def test_category_crud(self):
        r = self.c.get("/")
        self.assertFalse("test category" in r.content)
        r = self.c.post("/category/add/", {'name': 'test category'})
        self.assertEqual(r.status_code, 302)
        r = self.c.get("/")
        self.assertTrue("test category" in r.content)

        category = Category.objects.get(name="test category")