# Path: cab/models.py
# class Bookmark(models.Model):
#     snippet = models.ForeignKey(Snippet, related_name="bookmarks", on_delete=models.CASCADE)
#     user = models.ForeignKey(User, related_name="cab_bookmarks", on_delete=models.CASCADE)
#     date = models.DateTimeField(auto_now_add=True)
# 
#     class Meta:
#         ordering = ("-date",)
# 
#     def __str__(self):
#         return "%s bookmarked by %s" % (self.snippet, self.user)
# 
#     def save(self, *args, **kwargs):
#         super(Bookmark, self).save(*args, **kwargs)
#         self.snippet.update_bookmark_count()
# 
#     def delete(self, *args, **kwargs):
#         super(Bookmark, self).delete(*args, **kwargs)
#         self.snippet.update_bookmark_count()
# 
# class Language(models.Model):
#     name = models.CharField(max_length=100)
#     slug = models.SlugField(unique=True)
#     language_code = models.CharField(max_length=50)
#     mime_type = models.CharField(max_length=100)
#     file_extension = models.CharField(max_length=10)
# 
#     objects = LanguageManager()
# 
#     class Meta:
#         ordering = ("name",)
# 
#     def __str__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return reverse("cab_language_detail", kwargs={"slug": self.slug})
# 
#     def get_lexer(self):
#         return lexers.get_lexer_by_name(self.language_code)
# 
# class Snippet(models.Model):
#     title = models.CharField(max_length=255)
#     language = models.ForeignKey(Language, on_delete=models.CASCADE)
#     author = models.ForeignKey(User, on_delete=models.CASCADE)
#     description = models.TextField()
#     description_html = models.TextField(editable=False)
#     code = models.TextField()
#     highlighted_code = models.TextField(editable=False)
#     version = models.CharField(max_length=5, choices=VERSIONS, default="0.0")
#     pub_date = models.DateTimeField(auto_now_add=True)
#     updated_date = models.DateTimeField(auto_now=True)
#     bookmark_count = models.IntegerField(default=0)  # denormalized count
#     rating_score = models.IntegerField(default=0)  # denormalized score
# 
#     ratings = Ratings()
#     tags = TaggableManager(blank=True)
# 
#     objects = SnippetManager()
# 
#     class Meta:
#         ordering = ("-pub_date",)
# 
#     def __str__(self):
#         return self.title
# 
#     def save(self, *args, **kwargs):
#         self.description_html = sanitize_markdown(self.description)
#         self.highlighted_code = self.highlight()
#         super(Snippet, self).save(*args, **kwargs)
# 
#     def get_absolute_url(self):
#         return reverse("cab_snippet_detail", kwargs={"snippet_id": self.id})
# 
#     def highlight(self):
#         return highlight(self.code, self.language.get_lexer(), formatters.HtmlFormatter(linenos=True))
# 
#     def get_tagstring(self):
#         return ", ".join([t.name for t in self.tags.order_by("name").all()])
# 
#     def get_version(self):
#         return dict(VERSIONS)[self.version]
# 
#     def update_rating(self):
#         self.rating_score = self.ratings.cumulative_score() or 0
#         self.save()
# 
#     def update_bookmark_count(self):
#         self.bookmark_count = self.bookmarks.count() or 0
#         self.save()
# 
#     def mark_as_inappropiate(self):
#         snippet_flag = SnippetFlag(snippet=self, user=self.author, flag=SnippetFlag.FLAG_INAPPROPRIATE)
#         snippet_flag.save()
# 
#     def mark_as_spam(self):
#         snippet_flag = SnippetFlag(snippet=self, user=self.author, flag=SnippetFlag.FLAG_SPAM)
#         snippet_flag.save()
# 
# Path: cab/templatetags/markup.py
# @register.filter
# def safe_markdown(value):
#     """
#     Strip raw HTML and run Markdown over a given value.
#     """
#     return sanitize_markdown(value)


from django.contrib.auth.models import AnonymousUser, User
from django.template import Context, Template
from django.test import SimpleTestCase, TestCase
from django.urls import reverse
from rest_framework import status
from ..api.serializers import SnippetSerializer
from ..models import Bookmark, Language, Snippet
from ..templatetags.markup import safe_markdown



# @skip("These tests don't test production code.")
# @override_settings(ROOT_URLCONF='cab.tests.urls')
class BaseCabTestCase(TestCase):
    def setUp(self):
        """
        Because tags and ratings use GFKs which require content-type-ids, and
        as I am running 1.1.X at the moment, do all this stuff in the setUp()
        """
        self.user_a = User.objects.create_user("a", "a", "a")
        self.user_b = User.objects.create_user("b", "b", "b")


# Path: cab/models.py
# class Bookmark(models.Model):
#     snippet = models.ForeignKey(Snippet, related_name="bookmarks", on_delete=models.CASCADE)
#     user = models.ForeignKey(User, related_name="cab_bookmarks", on_delete=models.CASCADE)
#     date = models.DateTimeField(auto_now_add=True)
# 
#     class Meta:
#         ordering = ("-date",)
# 
#     def __str__(self):
#         return "%s bookmarked by %s" % (self.snippet, self.user)
# 
#     def save(self, *args, **kwargs):
#         super(Bookmark, self).save(*args, **kwargs)
#         self.snippet.update_bookmark_count()
# 
#     def delete(self, *args, **kwargs):
#         super(Bookmark, self).delete(*args, **kwargs)
#         self.snippet.update_bookmark_count()
# 
# class Language(models.Model):
#     name = models.CharField(max_length=100)
#     slug = models.SlugField(unique=True)
#     language_code = models.CharField(max_length=50)
#     mime_type = models.CharField(max_length=100)
#     file_extension = models.CharField(max_length=10)
# 
#     objects = LanguageManager()
# 
#     class Meta:
#         ordering = ("name",)
# 
#     def __str__(self):
#         return self.name
# 
#     def get_absolute_url(self):
#         return reverse("cab_language_detail", kwargs={"slug": self.slug})
# 
#     def get_lexer(self):
#         return lexers.get_lexer_by_name(self.language_code)
# 
# class Snippet(models.Model):
#     title = models.CharField(max_length=255)
#     language = models.ForeignKey(Language, on_delete=models.CASCADE)
#     author = models.ForeignKey(User, on_delete=models.CASCADE)
#     description = models.TextField()
#     description_html = models.TextField(editable=False)
#     code = models.TextField()
#     highlighted_code = models.TextField(editable=False)
#     version = models.CharField(max_length=5, choices=VERSIONS, default="0.0")
#     pub_date = models.DateTimeField(auto_now_add=True)
#     updated_date = models.DateTimeField(auto_now=True)
#     bookmark_count = models.IntegerField(default=0)  # denormalized count
#     rating_score = models.IntegerField(default=0)  # denormalized score
# 
#     ratings = Ratings()
#     tags = TaggableManager(blank=True)
# 
#     objects = SnippetManager()
# 
#     class Meta:
#         ordering = ("-pub_date",)
# 
#     def __str__(self):
#         return self.title
# 
#     def save(self, *args, **kwargs):
#         self.description_html = sanitize_markdown(self.description)
#         self.highlighted_code = self.highlight()
#         super(Snippet, self).save(*args, **kwargs)
# 
#     def get_absolute_url(self):
#         return reverse("cab_snippet_detail", kwargs={"snippet_id": self.id})
# 
#     def highlight(self):
#         return highlight(self.code, self.language.get_lexer(), formatters.HtmlFormatter(linenos=True))
# 
#     def get_tagstring(self):
#         return ", ".join([t.name for t in self.tags.order_by("name").all()])
# 
#     def get_version(self):
#         return dict(VERSIONS)[self.version]
# 
#     def update_rating(self):
#         self.rating_score = self.ratings.cumulative_score() or 0
#         self.save()
# 
#     def update_bookmark_count(self):
#         self.bookmark_count = self.bookmarks.count() or 0
#         self.save()
# 
#     def mark_as_inappropiate(self):
#         snippet_flag = SnippetFlag(snippet=self, user=self.author, flag=SnippetFlag.FLAG_INAPPROPRIATE)
#         snippet_flag.save()
# 
#     def mark_as_spam(self):
#         snippet_flag = SnippetFlag(snippet=self, user=self.author, flag=SnippetFlag.FLAG_SPAM)
#         snippet_flag.save()
# 
# Path: cab/templatetags/markup.py
# @register.filter
# def safe_markdown(value):
#     """
#     Strip raw HTML and run Markdown over a given value.
#     """
#     return sanitize_markdown(value)


# Path: cab/tests/tests.py
from django.contrib.auth.models import AnonymousUser, User
from django.template import Context, Template
from django.test import SimpleTestCase, TestCase
from django.urls import reverse
from rest_framework import status
from ..api.serializers import SnippetSerializer
from ..models import Bookmark, Language, Snippet
from ..templatetags.markup import safe_markdown




# @skip("These tests don't test production code.")
# @override_settings(ROOT_URLCONF='cab.tests.urls')
class BaseCabTestCase(TestCase):
    def setUp(self):
        """
        Because tags and ratings use GFKs which require content-type-ids, and
        as I am running 1.1.X at the moment, do all this stuff in the setUp()
        """
        self.user_a = User.objects.create_user("a", "a", "a")
        self.user_b = User.objects.create_user("b", "b", "b")


        self.python = Language.objects.create(