# Path: newsarticles/models.py
# class Article(models.Model):
#     """
#     Base article contents. Should never change after initial scraping
#     """
#     news_source = models.ForeignKey(NewsSource, null=True, db_index=True)
#     url = models.CharField(max_length=1024, unique=True, db_index=True)
#     title = models.TextField()
#     author = models.CharField(max_length=1024, default="", blank=True)
#     bodytext = models.TextField()
#     orig_html = models.TextField(blank=True)
#     created = models.DateTimeField(auto_now_add=True, db_index=True)
#     last_modified = models.DateTimeField(auto_now=True)
# 
#     objects = ArticleQuerySet.as_manager()
# 
#     # Fields from classification/coding- move to UserCoding
#     relevant = models.NullBooleanField(db_index=True)
#     categories = models.ManyToManyField(Category, blank=True)
# 
#     def __str__(self):
#         return self.url[:90]
# 
#     def is_coded(self):
#         return hasattr(self, 'usercoding')
# 
#     def current_coding(self):
#         return getattr(self, 'usercoding', None)
# 
#     def is_relevant(self):
#         coding = self.current_coding()
#         return coding and coding.relevant
# 
#     def get_categories(self):
#         coding = self.current_coding()
#         if coding:
#             return coding.categories.all()
#         else:
#             return []
# 
#     # Deprecated, use news_source instead.
#     feedname = models.CharField(
#         max_length=1, editable=False, null=True, db_index=True)
# 
# class UserCoding(models.Model):
#     article = models.OneToOneField(Article, db_index=True)
#     date = models.DateTimeField(auto_now=True)
#     user = models.ForeignKey(User, db_index=True, null=True, blank=True,
#                              on_delete=models.SET_NULL)
# 
#     # Fields from classification/coding
#     relevant = models.BooleanField()
#     categories = models.ManyToManyField(Category, blank=True)
#     locations = models.TextField(default='[]', blank=True)
#     sentiment = models.IntegerField(
#         blank=True, null=True, choices=SENTIMENT_CHOICES)
# 
#     class Meta:
#         unique_together = (("article", "user"),)
# 
# class NewsSource(models.Model):
#     name = models.CharField(max_length=256)
#     short_name = models.CharField(max_length=256, db_index=True)
#     legacy_feed_id = models.CharField(max_length=8, blank=True, db_index=True)
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']
# 
# class Category(models.Model):
# 
#     KINDS = OrderedDict([
#         ('crimes', 'Crimes'),
#         ('orgs', 'Justice Agencies / Agencies'),
#         ('policing', 'Policing'),
#         ('other', 'Misc.'),
#     ])
#     DEFAULT_KIND = 'other'
# 
#     title = models.CharField(max_length=256)
#     abbreviation = models.CharField(max_length=5)
#     active = models.BooleanField(default=True)
#     kind = models.CharField(
#         max_length=50, choices=KINDS.items(), default=DEFAULT_KIND)
#     created = models.DateTimeField(auto_now=False, auto_now_add=True)
# 
#     objects = CategoryQuerySet.as_manager()
# 
#     def __str__(self):
#         return '{} ({})'.format(self.title, self.abbreviation)
# 
#     class Meta:
#         ordering = ['kind', 'abbreviation']


from uuid import uuid4
from django.test import TestCase
from newsarticles.models import Article, UserCoding, NewsSource, Category
        article.save()
    return article

def make_category(save=True):
    cat = Category(title="", abbreviation="")
    if save:
        cat.save()
    return cat

class ArticleTest(TestCase):
    @classmethod
    def setUp(cls):
        cls.article = make_article()
        cls.categories = [make_category(), make_category(), make_category()]

    def test_is_coded_uncoded(self):
        self.assertFalse(self.article.is_coded())

    def test_is_coded_coded(self):
        UserCoding.objects.create(
            article=self.article,
            relevant=True,
        )

        self.assertTrue(self.article.is_coded())

    def test_relevant_uncoded(self):
        self.assertIsNone(self.article.is_relevant())

    def test_relevant_one_coding_true(self):

# Path: newsarticles/models.py
# class Article(models.Model):
#     """
#     Base article contents. Should never change after initial scraping
#     """
#     news_source = models.ForeignKey(NewsSource, null=True, db_index=True)
#     url = models.CharField(max_length=1024, unique=True, db_index=True)
#     title = models.TextField()
#     author = models.CharField(max_length=1024, default="", blank=True)
#     bodytext = models.TextField()
#     orig_html = models.TextField(blank=True)
#     created = models.DateTimeField(auto_now_add=True, db_index=True)
#     last_modified = models.DateTimeField(auto_now=True)
# 
#     objects = ArticleQuerySet.as_manager()
# 
#     # Fields from classification/coding- move to UserCoding
#     relevant = models.NullBooleanField(db_index=True)
#     categories = models.ManyToManyField(Category, blank=True)
# 
#     def __str__(self):
#         return self.url[:90]
# 
#     def is_coded(self):
#         return hasattr(self, 'usercoding')
# 
#     def current_coding(self):
#         return getattr(self, 'usercoding', None)
# 
#     def is_relevant(self):
#         coding = self.current_coding()
#         return coding and coding.relevant
# 
#     def get_categories(self):
#         coding = self.current_coding()
#         if coding:
#             return coding.categories.all()
#         else:
#             return []
# 
#     # Deprecated, use news_source instead.
#     feedname = models.CharField(
#         max_length=1, editable=False, null=True, db_index=True)
# 
# class UserCoding(models.Model):
#     article = models.OneToOneField(Article, db_index=True)
#     date = models.DateTimeField(auto_now=True)
#     user = models.ForeignKey(User, db_index=True, null=True, blank=True,
#                              on_delete=models.SET_NULL)
# 
#     # Fields from classification/coding
#     relevant = models.BooleanField()
#     categories = models.ManyToManyField(Category, blank=True)
#     locations = models.TextField(default='[]', blank=True)
#     sentiment = models.IntegerField(
#         blank=True, null=True, choices=SENTIMENT_CHOICES)
# 
#     class Meta:
#         unique_together = (("article", "user"),)
# 
# class NewsSource(models.Model):
#     name = models.CharField(max_length=256)
#     short_name = models.CharField(max_length=256, db_index=True)
#     legacy_feed_id = models.CharField(max_length=8, blank=True, db_index=True)
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         ordering = ['name']
# 
# class Category(models.Model):
# 
#     KINDS = OrderedDict([
#         ('crimes', 'Crimes'),
#         ('orgs', 'Justice Agencies / Agencies'),
#         ('policing', 'Policing'),
#         ('other', 'Misc.'),
#     ])
#     DEFAULT_KIND = 'other'
# 
#     title = models.CharField(max_length=256)
#     abbreviation = models.CharField(max_length=5)
#     active = models.BooleanField(default=True)
#     kind = models.CharField(
#         max_length=50, choices=KINDS.items(), default=DEFAULT_KIND)
#     created = models.DateTimeField(auto_now=False, auto_now_add=True)
# 
#     objects = CategoryQuerySet.as_manager()
# 
#     def __str__(self):
#         return '{} ({})'.format(self.title, self.abbreviation)
# 
#     class Meta:
#         ordering = ['kind', 'abbreviation']


# Path: newsarticles/tests/test_models.py
from uuid import uuid4
from django.test import TestCase
from newsarticles.models import Article, UserCoding, NewsSource, Category

        article.save()
    return article

def make_category(save=True):
    cat = Category(title="", abbreviation="")
    if save:
        cat.save()
    return cat

class ArticleTest(TestCase):
    @classmethod
    def setUp(cls):
        cls.article = make_article()
        cls.categories = [make_category(), make_category(), make_category()]

    def test_is_coded_uncoded(self):
        self.assertFalse(self.article.is_coded())

    def test_is_coded_coded(self):
        UserCoding.objects.create(
            article=self.article,
            relevant=True,
        )

        self.assertTrue(self.article.is_coded())

    def test_relevant_uncoded(self):
        self.assertIsNone(self.article.is_relevant())

    def test_relevant_one_coding_true(self):

        UserCoding.objects.create(