예제 #1
0
    def create_article(cls, command: CreateArticleCommand):
        user_repo = current_domain.repository_for(User)
        user = user_repo.get_by_token(command.token)

        if user is not None:
            # Convert a Command Object into a DTO, to pass into the domain
            article_dto = CreateArticleDTO(title=command.title,
                                           description=command.description,
                                           body=command.body,
                                           tag_list=command.tag_list,
                                           author=user)

            # Call a factory method to construct a Articl object
            article = Article.create(article_dto)

            # Persist the new Article object
            article_repo = current_domain.repository_for(Article)
            article_repo.add(article)

            # Convert the persisted article object into a resource
            #   to be passed onto the callee
            article_resource = ArticleRepresentation().dump(article)
            return article_resource

        return None
예제 #2
0
    def article(self):
        user = User(email='*****@*****.**', username='******', password='******')

        return Article(title="How to train your dragon",
                       description="Ever wonder how?",
                       body="You have to believe",
                       tagList=["reactjs", "angularjs", "dragons"],
                       author=user)
예제 #3
0
    def test_successfully_updating_an_articles_attributes(self):
        user = User(email='*****@*****.**', username='******', password='******')

        article_dto = CreateArticleDTO(
            title="How to train your dragon",
            description="Ever wonder how?",
            body="You have to believe",
            tag_list=["reactjs", "angularjs", "dragons"],
            author=user)
        article = Article.create(article_dto)
        article.update(body='Belief is everything')

        assert article.body == 'Belief is everything'
예제 #4
0
    def test_that_invalid_fields_are_ignored_during_update(self):
        user = User(email='*****@*****.**', username='******', password='******')

        article_dto = CreateArticleDTO(
            title="How to train your dragon",
            description="Ever wonder how?",
            body="You have to believe",
            tag_list=["reactjs", "angularjs", "dragons"],
            author=user)
        article = Article.create(article_dto)
        article.update(body='Belief is everything', foo='bar')

        assert article.body == 'Belief is everything'
        assert hasattr(article, 'foo') is False
예제 #5
0
    def test_that_a_slug_is_created_from_the_article_title(self):
        user = User(email='*****@*****.**', username='******', password='******')

        article_dto = CreateArticleDTO(
            title="How to train your dragon",
            description="Ever wonder how?",
            body="You have to believe",
            tag_list=["reactjs", "angularjs", "dragons"],
            author=user)

        article = Article.create(article_dto)

        assert article.slug is not None
        assert article.slug == "how-to-train-your-dragon"
예제 #6
0
    def test_that_updating_an_article_title_also_updated_slug(self):
        user = User(email='*****@*****.**', username='******', password='******')

        article_dto = CreateArticleDTO(
            title="How to train your dragon",
            description="Ever wonder how?",
            body="You have to believe",
            tag_list=["reactjs", "angularjs", "dragons"],
            author=user)
        article = Article.create(article_dto)

        article.update(
            title='How to train your dragon - Part 2 - At Worlds End')

        assert article.slug == 'how-to-train-your-dragon-part-2-at-worlds-end'
예제 #7
0
    def test_that_a_new_article_can_be_created_successfully(self):
        user = User(email='*****@*****.**', username='******', password='******')

        article_dto = CreateArticleDTO(
            title="How to train your dragon",
            description="Ever wonder how?",
            body="You have to believe",
            tag_list=["reactjs", "angularjs", "dragons"],
            author=user)

        article = Article.create(article_dto)

        assert article is not None
        assert isinstance(article, Article)
        assert article.id is not None

        try:
            UUID(str(article.id))
        except ValueError:
            pytest.fail("ID is not valid UUID")
예제 #8
0
 def article(self, user2):
     return Article(title="How to train your dragon",
                    description="Ever wonder how?",
                    body="You have to believe",
                    tagList=["reactjs", "angularjs", "dragons"],
                    author=user2)
예제 #9
0
 def test_that_mandatory_fields_are_validated(self):
     with pytest.raises(ValidationError):
         Article()
예제 #10
0
 def test_that_an_article_can_be_initialized_successfully(self):
     article = Article(title="How to train your dragon",
                       description="Ever wonder how?",
                       body="You have to believe",
                       tagList=["reactjs", "angularjs", "dragons"])
     assert article is not None