# 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 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 django.contrib.auth.models import User
from newsarticles.models import Article, NewsSource, Category

TEST_BODY = """
this is a long block of text for testing that article bodies get shortened for
non-logged-in users. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
"""

class DataFactory(object):
    """
    Helper class for instantiating model data in tests.
    """
    def make_category(self):
        return Category.objects.create(
            title='Guns',
            abbreviation='GUN',
            kind='crimes',
        )

    def make_admin(self):
        return User.objects.create_user(username='user1', password='12345', is_staff=True)

    def make_news_source(self):
        return NewsSource.objects.create(name='Daily Planet', short_name='planet')

    def make_article(self, title='Article title', news_source=None):
        if not news_source:

# 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 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/helpers.py
from django.contrib.auth.models import User
from newsarticles.models import Article, NewsSource, Category


TEST_BODY = """
this is a long block of text for testing that article bodies get shortened for
non-logged-in users. Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
"""

class DataFactory(object):
    """
    Helper class for instantiating model data in tests.
    """
    def make_category(self):
        return Category.objects.create(
            title='Guns',
            abbreviation='GUN',
            kind='crimes',
        )

    def make_admin(self):
        return User.objects.create_user(username='user1', password='12345', is_staff=True)

    def make_news_source(self):
        return NewsSource.objects.create(name='Daily Planet', short_name='planet')

    def make_article(self, title='Article title', news_source=None):
        if not news_source:

            news_source=NewsSource.objects.first()