# 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
                             title=v.title0,
                             category=self.category0,
                             description=v.description0,
                             owner=self.user0)
            query.save()

    def test_save_bookmark_same_url_by_another_user(self):
        query = Bookmark(url=v.url0,
                         title=v.title0,
                         category=self.category0,
                         description=v.description0,
                         owner=self.user1)
        query.save()
        query = Bookmark.objects.get(url=v.url0, owner=self.user1)
        self.assertEqual(query.__str__(), v.title0)

    def test_update_bookmark(self):
        query = Bookmark(id=self.bookmark.id,
                         url=v.url1,
                         title=v.title1,
                         category=self.category1,
                         description=v.description1,
                         owner=self.user0)
        query.save()

        query2 = Bookmark.objects.get(url=v.url1, owner=self.user0)
        self.assertEqual(query2.id, self.bookmark.id)

    def test_delete_bookmark(self):
        self.bookmark.delete()

# 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

                             title=v.title0,
                             category=self.category0,
                             description=v.description0,
                             owner=self.user0)
            query.save()

    def test_save_bookmark_same_url_by_another_user(self):
        query = Bookmark(url=v.url0,
                         title=v.title0,
                         category=self.category0,
                         description=v.description0,
                         owner=self.user1)
        query.save()
        query = Bookmark.objects.get(url=v.url0, owner=self.user1)
        self.assertEqual(query.__str__(), v.title0)

    def test_update_bookmark(self):
        query = Bookmark(id=self.bookmark.id,
                         url=v.url1,
                         title=v.title1,
                         category=self.category1,
                         description=v.description1,
                         owner=self.user0)
        query.save()

        query2 = Bookmark.objects.get(url=v.url1, owner=self.user0)
        self.assertEqual(query2.id, self.bookmark.id)

    def test_delete_bookmark(self):
        self.bookmark.delete()

        with self.assertRaises(Bookmark.DoesNotExist):