#!/usr/bin/env python
# -*- coding: utf-8 -*-

from django.db import IntegrityError
from django.test import TestCase

from opps.core.models.source import Source


class SourceModelTest(TestCase):

    def setUp(self):
        self.source = Source.objects.create(name=u'Test site',
                slug=u'test-site')

    def test_check_create_test_site(self):
        """
        Check exist source test site, create on setup class
        """
        source = Source.objects.filter(slug='test-site').get()
        self.assertTrue(source)
        self.assertEqual(source, self.source)

    def test_not_register_url(self):
        """
        url not registered
        """
        source = Source.objects.filter(slug='test-site').get()
        self.assertFalse(self.source.url)
        self.assertEqual(self.source.url, source.url)

    def test_register_url(self):
        """
        url registered
        """
        self.source.url = u"http://example.com/"
        self.source.save()

        source = Source.objects.filter(slug='test-site').get()
        self.assertTrue(self.source.url)
        self.assertEqual(self.source.url, source.url)

    def test_duplicate_source_slug(self):
        """
        create 2 source with same slug
        """
        self.assertRaises(IntegrityError, Source.objects.create,
                name=u'test site', slug=u'test-site')

@@ -111,16 +111,106 @@
 stCase%0A%0A
+from django.contrib.sites.models import Site%0Afrom django.contrib.auth.models import User%0A%0A
 from opp
@@ -293,32 +293,174 @@
 ef setUp(self):%0A
+        self.user = User.objects.create(username=u'test', password='test')%0A        self.site = Site.objects.filter(name=u'example.com').get()%0A
         self.sou
@@ -539,16 +539,48 @@
 st-site'
+, user=self.user, site=self.site
 )%0A%0A    d

Fix test source, add user and site on setup source