# Path: sideloader/models.py
# class Project(models.Model):
#     name = models.CharField(max_length=255, unique=True)
#     github_url = models.CharField(max_length=255)
#     branch = models.CharField(max_length=255)
#     package_manager = models.CharField(max_length=64, default='deb')
#     deploy_type = models.CharField(max_length=64, default='virtualenv')
#     deploy_file = models.CharField(max_length=255, default='.deploy.yaml', blank=True)
#     package_name = models.CharField(max_length=255, default='', blank=True)
#     build_script = models.CharField(max_length=255, default='', blank=True)
#     postinstall_script = models.CharField(
#         max_length=255, default='', blank=True)
# 
#     created_by_user = models.ForeignKey(User, related_name="ProjectCreatedBy")
#     release_stream = models.ForeignKey(ReleaseStream, null=True)
#     idhash = models.CharField(max_length=48)
#     allowed_users = models.ManyToManyField(User, blank=True)
#     notifications = models.BooleanField(default=True)
#     slack_channel = models.CharField(max_length=255, default='', blank=True)
# 
# class ReleaseFlow(models.Model):
#     name = models.CharField(max_length=255)
#     project = models.ForeignKey(Project)
#     stream_mode = models.IntegerField(default=0)
#     stream = models.ForeignKey(ReleaseStream, null=True, blank=True)
#     require_signoff = models.BooleanField(default=False)
#     signoff_list = models.TextField(blank=True)
#     quorum = models.IntegerField(default=0)
#     notify = models.BooleanField(default=False)
#     notify_list = models.TextField(blank=True)
#     service_restart = models.BooleanField(default=True)
#     service_pre_stop = models.BooleanField(default=False)
#     puppet_run = models.BooleanField(default=True)
#     auto_release = models.BooleanField(default=False)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def __str__(self):
#         return self.__unicode__().encode('utf-8', 'replace')
# 
#     def email_list(self):
#         if not '@' in self.signoff_list:
#             return []
# 
#         return self.signoff_list.replace('\r', ' ').replace(
#             '\n', ' ').replace(',', ' ').strip().split()
# 
#     def last_release(self):
#         rs = self.release_set.filter(waiting=False).order_by('-release_date')
#         if rs:
#             return rs[0]
#         else:
#             return None
# 
#     def next_release(self):
#         rs = self.release_set.filter(waiting=True).order_by('-release_date')
#         if rs:
#             return rs[0]
#         else:
#             return None
# 
# class ReleaseStream(models.Model):
#     name = models.CharField(max_length=255)
#     push_command = models.CharField(max_length=255)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def __str__(self):
#         return self.__unicode__().encode('utf-8', 'replace')
# 
# class WebHook(models.Model):
#     flow = models.ForeignKey(ReleaseFlow)
#     description = models.CharField(max_length=255)
#     url = models.CharField(max_length=255)
#     method = models.CharField(max_length=4)
#     content_type = models.CharField(max_length=255)
#     payload = models.TextField(blank=True)
#     after = models.ForeignKey('self', null=True, blank=True)
#     last_response = models.TextField(blank=True)
# 
#     def __unicode__(self):
#         return self.description
# 
#     def __str__(self):
#         return self.__unicode__().encode('utf-8', 'replace')


from django.contrib.auth.models import User
from django.test import TestCase
from django.core.urlresolvers import reverse
from sideloader.models import Project, ReleaseFlow, ReleaseStream, WebHook
import pytest

    def test_new_project_default_flows(self):
        """
        When we create a new project, we get some default workflows.
        """
        prod_stream = ReleaseStream.objects.create(name="Production")
        qa_stream = ReleaseStream.objects.create(name="QA")
        self.client.login(username="root", password="pass")
        self.assertEqual(list(Project.objects.all()), [])
        self.assertEqual(list(ReleaseFlow.objects.all()), [])
        self.client.post(reverse("projects_create"), {
            "name": "My Project",
            "github_url": "foo.git",
            "branch": "develop",
            "deploy_type": "virtualenv",
            "package_manager": "deb",
        })
        [proj] = Project.objects.all()

        [prod_f, qa_f] = list(ReleaseFlow.objects.all().order_by("name"))
        self.assertEqual(prod_f.project, proj)
        self.assertEqual(prod_f.stream, prod_stream)
        self.assertEqual(qa_f.project, proj)
        self.assertEqual(qa_f.stream, qa_stream)


class TestReleaseFlow(TestCase):
    def setUp(self):
        self.root = User.objects.create_superuser(
            "root", "root@localhost", "pass")

# Path: sideloader/models.py
# class Project(models.Model):
#     name = models.CharField(max_length=255, unique=True)
#     github_url = models.CharField(max_length=255)
#     branch = models.CharField(max_length=255)
#     package_manager = models.CharField(max_length=64, default='deb')
#     deploy_type = models.CharField(max_length=64, default='virtualenv')
#     deploy_file = models.CharField(max_length=255, default='.deploy.yaml', blank=True)
#     package_name = models.CharField(max_length=255, default='', blank=True)
#     build_script = models.CharField(max_length=255, default='', blank=True)
#     postinstall_script = models.CharField(
#         max_length=255, default='', blank=True)
# 
#     created_by_user = models.ForeignKey(User, related_name="ProjectCreatedBy")
#     release_stream = models.ForeignKey(ReleaseStream, null=True)
#     idhash = models.CharField(max_length=48)
#     allowed_users = models.ManyToManyField(User, blank=True)
#     notifications = models.BooleanField(default=True)
#     slack_channel = models.CharField(max_length=255, default='', blank=True)
# 
# class ReleaseFlow(models.Model):
#     name = models.CharField(max_length=255)
#     project = models.ForeignKey(Project)
#     stream_mode = models.IntegerField(default=0)
#     stream = models.ForeignKey(ReleaseStream, null=True, blank=True)
#     require_signoff = models.BooleanField(default=False)
#     signoff_list = models.TextField(blank=True)
#     quorum = models.IntegerField(default=0)
#     notify = models.BooleanField(default=False)
#     notify_list = models.TextField(blank=True)
#     service_restart = models.BooleanField(default=True)
#     service_pre_stop = models.BooleanField(default=False)
#     puppet_run = models.BooleanField(default=True)
#     auto_release = models.BooleanField(default=False)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def __str__(self):
#         return self.__unicode__().encode('utf-8', 'replace')
# 
#     def email_list(self):
#         if not '@' in self.signoff_list:
#             return []
# 
#         return self.signoff_list.replace('\r', ' ').replace(
#             '\n', ' ').replace(',', ' ').strip().split()
# 
#     def last_release(self):
#         rs = self.release_set.filter(waiting=False).order_by('-release_date')
#         if rs:
#             return rs[0]
#         else:
#             return None
# 
#     def next_release(self):
#         rs = self.release_set.filter(waiting=True).order_by('-release_date')
#         if rs:
#             return rs[0]
#         else:
#             return None
# 
# class ReleaseStream(models.Model):
#     name = models.CharField(max_length=255)
#     push_command = models.CharField(max_length=255)
# 
#     def __unicode__(self):
#         return self.name
# 
#     def __str__(self):
#         return self.__unicode__().encode('utf-8', 'replace')
# 
# class WebHook(models.Model):
#     flow = models.ForeignKey(ReleaseFlow)
#     description = models.CharField(max_length=255)
#     url = models.CharField(max_length=255)
#     method = models.CharField(max_length=4)
#     content_type = models.CharField(max_length=255)
#     payload = models.TextField(blank=True)
#     after = models.ForeignKey('self', null=True, blank=True)
#     last_response = models.TextField(blank=True)
# 
#     def __unicode__(self):
#         return self.description
# 
#     def __str__(self):
#         return self.__unicode__().encode('utf-8', 'replace')


# Path: sideloader/tests/test_views.py
from django.contrib.auth.models import User
from django.test import TestCase
from django.core.urlresolvers import reverse
from sideloader.models import Project, ReleaseFlow, ReleaseStream, WebHook
import pytest


    def test_new_project_default_flows(self):
        """
        When we create a new project, we get some default workflows.
        """
        prod_stream = ReleaseStream.objects.create(name="Production")
        qa_stream = ReleaseStream.objects.create(name="QA")
        self.client.login(username="root", password="pass")
        self.assertEqual(list(Project.objects.all()), [])
        self.assertEqual(list(ReleaseFlow.objects.all()), [])
        self.client.post(reverse("projects_create"), {
            "name": "My Project",
            "github_url": "foo.git",
            "branch": "develop",
            "deploy_type": "virtualenv",
            "package_manager": "deb",
        })
        [proj] = Project.objects.all()

        [prod_f, qa_f] = list(ReleaseFlow.objects.all().order_by("name"))
        self.assertEqual(prod_f.project, proj)
        self.assertEqual(prod_f.stream, prod_stream)
        self.assertEqual(qa_f.project, proj)
        self.assertEqual(qa_f.stream, qa_stream)


class TestReleaseFlow(TestCase):
    def setUp(self):
        self.root = User.objects.create_superuser(
            "root", "root@localhost", "pass")

        self.prod_stream = ReleaseStream.objects.create(name="Production")