# 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
        self.qa_stream = ReleaseStream.objects.create(name="QA")
        self.prod_stream = ReleaseStream.objects.create(name="Production")
        self.proj = Project.objects.create(
            name="My Project", github_url="foo.git", branch="develop",
            created_by_user=self.root, idhash="seekrit")
        self.qa_flow = ReleaseFlow.objects.create(
            name="QA Flow", project=self.proj)
        self.prod_flow = ReleaseFlow.objects.create(
            name="Production Flow", project=self.proj)

    def assert_form_field_choices(self, url, field, choices):
        resp = self.client.get(url)
        # We're not using this at the moment.
        assert field not in resp.context['form'].fields
        # self.assertEqual(
        #     list(resp.context['form'].fields[field].choices), choices)

    def test_new_webhook(self):
        """
        We can create a new webhook for a flow.
        """
        self.client.login(username="root", password="pass")
        self.assertEqual(list(WebHook.objects.all()), [])
        url = reverse("webhooks_create", args=[self.qa_flow.pk])
        resp = self.client.post(url, {
            "description": "My Webhook",
            "url": "https://example.com/hook/token",
            "method": "POST",
            "content_type": "application/json",
        })

# 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

        self.qa_stream = ReleaseStream.objects.create(name="QA")
        self.prod_stream = ReleaseStream.objects.create(name="Production")
        self.proj = Project.objects.create(
            name="My Project", github_url="foo.git", branch="develop",
            created_by_user=self.root, idhash="seekrit")
        self.qa_flow = ReleaseFlow.objects.create(
            name="QA Flow", project=self.proj)
        self.prod_flow = ReleaseFlow.objects.create(
            name="Production Flow", project=self.proj)

    def assert_form_field_choices(self, url, field, choices):
        resp = self.client.get(url)
        # We're not using this at the moment.
        assert field not in resp.context['form'].fields
        # self.assertEqual(
        #     list(resp.context['form'].fields[field].choices), choices)

    def test_new_webhook(self):
        """
        We can create a new webhook for a flow.
        """
        self.client.login(username="root", password="pass")
        self.assertEqual(list(WebHook.objects.all()), [])
        url = reverse("webhooks_create", args=[self.qa_flow.pk])
        resp = self.client.post(url, {
            "description": "My Webhook",
            "url": "https://example.com/hook/token",
            "method": "POST",
            "content_type": "application/json",
        })

        [hook] = WebHook.objects.all()