Commit ef2a5922 authored by luxcem's avatar luxcem
Browse files

start articles tests

parent 5fbde568
...@@ -2,4 +2,4 @@ from django.apps import AppConfig ...@@ -2,4 +2,4 @@ from django.apps import AppConfig
class RpConfig(AppConfig): class RpConfig(AppConfig):
name = 'rp' name = "rp"
import datetime
import pytz
import factory import factory
from factory.fuzzy import FuzzyDateTime
from .models import Article from .models import Article
...@@ -6,7 +10,19 @@ from .models import Article ...@@ -6,7 +10,19 @@ from .models import Article
class ArticleFactory(factory.django.DjangoModelFactory): class ArticleFactory(factory.django.DjangoModelFactory):
class Meta: class Meta:
model = Article model = Article
url = factory.Faker("url") url = factory.Faker("url")
lang = "en" lang = "en"
title = factory.Faker("sentence", nb_words=4) title = factory.Faker("sentence", nb_words=4)
website = factory.Sequence(lambda n: "Website {}".format(n))
extracts = factory.Faker("text") extracts = factory.Faker("text")
created_at = FuzzyDateTime(
datetime.datetime(2014, 1, 1, tzinfo=pytz.UTC))
updated_at = FuzzyDateTime(
datetime.datetime(2014, 1, 1, tzinfo=pytz.UTC))
published_at = FuzzyDateTime(
datetime.datetime(2014, 1, 1, tzinfo=pytz.UTC))
status = "PENDING"
...@@ -9,23 +9,27 @@ class Article(UnDVotedMixin): ...@@ -9,23 +9,27 @@ class Article(UnDVotedMixin):
url = models.URLField("URL") url = models.URLField("URL")
lang = models.CharField(_("Language"), max_length=50, null=True) lang = models.CharField(_("Language"), max_length=50, null=True)
metadata = models.TextField(_("Opengraph metadata"), blank=True, null=True) metadata = models.TextField(_("Opengraph metadata"), blank=True, null=True)
screenshot = models.ImageField(_("Article screenshot"), blank=True, null=True) screenshot = models.ImageField(_("Article screenshot"),
blank=True, null=True)
title = models.CharField(_("Article title"), max_length=255, default="") title = models.CharField(_("Article title"), max_length=255, default="")
website = models.CharField(_("Website"), max_length=255, default="") website = models.CharField(_("Website"), max_length=255, default="")
extracts = models.TextField(_("Content extracts"), blank=True, null=True) extracts = models.TextField(_("Content extracts"), blank=True, null=True)
created_at = models.DateTimeField(_("Creation date"), auto_now_add=True) created_at = models.DateTimeField(_("Creation date"), auto_now_add=True)
updated_at = models.DateTimeField(_("Last update"), auto_now=True) updated_at = models.DateTimeField(_("Last update"), auto_now=True)
published_at = models.DateTimeField(_("Publication date"), blank=True, null=True) published_at = models.DateTimeField(_("Publication date"),
blank=True, null=True)
STATUS_CHOICES = ( STATUS_CHOICES = (
("PENDING", _("Pending")), ("PENDING", _("Pending")),
("PUBLISHED", _("Published")), ("PUBLISHED", _("Published")),
("REJECTED", _("Rejected")) ("REJECTED", _("Rejected"))
) )
status = models.CharField( status = models.CharField(
_("Published"), choices=STATUS_CHOICES, default="PENDING", _("Published"), choices=STATUS_CHOICES,
max_length=20) default="PENDING", max_length=20
)
tags = TaggableManager() tags = TaggableManager()
......
...@@ -27,7 +27,8 @@ class UnDVotes(models.Model): ...@@ -27,7 +27,8 @@ class UnDVotes(models.Model):
verbose_name_plural = _("Votes") verbose_name_plural = _("Votes")
def __str__(self): def __str__(self):
return "{}:{}:{}".format(self.username, self.content_object, self.score) return "{}:{}:{}".format(
self.username, self.content_object, self.score)
class UnDVotedMixin(models.Model): class UnDVotedMixin(models.Model):
......
from rp.models import Article
from rp.factories import ArticleFactory
from rp.apps import RpConfig
def test_init():
assert RpConfig.name == "rp"
def test_article():
article = ArticleFactory()
assert type(article) == Article
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment