# Path: shiori/bookmark/models.py
# class Category(BaseObject):
#     """ Category model """
#     category = models.CharField(max_length=255, unique=True)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'category'
# 
#     def __unicode__(self):
#         return self.category
# 
# class Tag(BaseObject):
#     """ Tag model """
#     tag = models.CharField(max_length=255, unique=True)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'tag'
# 
#     def __unicode__(self):
#         return self.tag
# 
# class Bookmark(BaseObject):
#     """ Bookmark model """
#     url = models.URLField()
#     title = models.CharField(max_length=255)
#     category = models.ForeignKey(Category)
#     tags = models.ManyToManyField(Tag, through='BookmarkTag')
#     registered_datetime = models.DateTimeField(auto_now=True,
#                                                auto_now_add=True)
#     description = models.TextField(blank=True)
#     owner = models.ForeignKey(User)
#     is_hide = models.BooleanField(default=False)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'bookmark'
#         unique_together = ('url', 'owner')
# 
#     def __unicode__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         """ bookmark permalink path """
#         return "/shiori/b/%s" % self.id
# 
# Path: shiori/bookmark/feed_generator.py
# class LatestEntries(Feed):
#     """ Feed generator class """
#     title = 'Shiori new bookmarks'
#     link = '/shiori/'
#     description = 'Updates on changes and additions to Shiori.'
#     description_template = 'feeds/latest_title.html'
# 
#     def items(self):
#         """ Retrieve latest 5 bookmarks """
#         return Bookmark.objects.order_by('-registered_datetime')[:5]


from django.core.urlresolvers import resolve
from django.test import TestCase, TransactionTestCase
from django.contrib.auth.models import User
from django.views.generic import RedirectView
from django.db import IntegrityError
from shiori.bookmark.models import Category, Tag, Bookmark
from shiori.bookmark.feed_generator import LatestEntries
import shiori.bookmark.views
import shiori_tests.tests.vars as v

        query2 = Category.objects.get(category=v.category2)
        self.assertEqual(query2.id, self.category0.id)

    def test_delete_category(self):
        self.category0.delete()
        with self.assertRaises(Category.DoesNotExist):
            Category.objects.get(category=self.category0.category)

        with self.assertRaises(Category.DoesNotExist):
            Category.objects.get(id=self.category0.id)

    def test_get_tag(self):
        query = Tag.objects.get(tag=self.tag0.tag)
        self.assertEqual(query.__unicode__(), self.tag0.tag)
        self.assertEqual(query.__str__(), self.tag0.tag)

    def test_save_tag_confilict(self):
        with self.assertRaises(IntegrityError):
            query = Tag(tag=self.tag1.tag)
            query.save()

    def test_save_tag(self):
        query = Tag(tag=v.tag2)
        query.save()

        query2 = Tag.objects.get(tag=v.tag2)
        self.assertEqual(query2.__str__(), v.tag2)

    def test_update_tag(self):

# Path: shiori/bookmark/models.py
# class Category(BaseObject):
#     """ Category model """
#     category = models.CharField(max_length=255, unique=True)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'category'
# 
#     def __unicode__(self):
#         return self.category
# 
# class Tag(BaseObject):
#     """ Tag model """
#     tag = models.CharField(max_length=255, unique=True)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'tag'
# 
#     def __unicode__(self):
#         return self.tag
# 
# class Bookmark(BaseObject):
#     """ Bookmark model """
#     url = models.URLField()
#     title = models.CharField(max_length=255)
#     category = models.ForeignKey(Category)
#     tags = models.ManyToManyField(Tag, through='BookmarkTag')
#     registered_datetime = models.DateTimeField(auto_now=True,
#                                                auto_now_add=True)
#     description = models.TextField(blank=True)
#     owner = models.ForeignKey(User)
#     is_hide = models.BooleanField(default=False)
# 
#     class Meta(object):
#         """ meta class """
#         db_table = 'bookmark'
#         unique_together = ('url', 'owner')
# 
#     def __unicode__(self):
#         return self.title
# 
#     def get_absolute_url(self):
#         """ bookmark permalink path """
#         return "/shiori/b/%s" % self.id
# 
# Path: shiori/bookmark/feed_generator.py
# class LatestEntries(Feed):
#     """ Feed generator class """
#     title = 'Shiori new bookmarks'
#     link = '/shiori/'
#     description = 'Updates on changes and additions to Shiori.'
#     description_template = 'feeds/latest_title.html'
# 
#     def items(self):
#         """ Retrieve latest 5 bookmarks """
#         return Bookmark.objects.order_by('-registered_datetime')[:5]


# Path: shiori_tests/tests/test_bookmark.py
from django.core.urlresolvers import resolve
from django.test import TestCase, TransactionTestCase
from django.contrib.auth.models import User
from django.views.generic import RedirectView
from django.db import IntegrityError
from shiori.bookmark.models import Category, Tag, Bookmark
from shiori.bookmark.feed_generator import LatestEntries
import shiori.bookmark.views
import shiori_tests.tests.vars as v


        query2 = Category.objects.get(category=v.category2)
        self.assertEqual(query2.id, self.category0.id)

    def test_delete_category(self):
        self.category0.delete()
        with self.assertRaises(Category.DoesNotExist):
            Category.objects.get(category=self.category0.category)

        with self.assertRaises(Category.DoesNotExist):
            Category.objects.get(id=self.category0.id)

    def test_get_tag(self):
        query = Tag.objects.get(tag=self.tag0.tag)
        self.assertEqual(query.__unicode__(), self.tag0.tag)
        self.assertEqual(query.__str__(), self.tag0.tag)

    def test_save_tag_confilict(self):
        with self.assertRaises(IntegrityError):
            query = Tag(tag=self.tag1.tag)
            query.save()

    def test_save_tag(self):
        query = Tag(tag=v.tag2)
        query.save()

        query2 = Tag.objects.get(tag=v.tag2)
        self.assertEqual(query2.__str__(), v.tag2)

    def test_update_tag(self):

        query = Tag(id=self.tag0.id, tag=v.tag2)