Example #1
0
def test_create_article():
    cmd = CreateArticleCommand(author='*****@*****.**',
                               title='New Article',
                               content='Awsome article')
    article = cmd.execute()
    db_article = Article.get_by_id(article.id)

    assert db_article.id == article.id
    assert db_article.author == article.author
    assert db_article.title == article.title
    assert db_article.content == article.content
Example #2
0
def test_create_article_aready_exists():
    Article(author='*****@*****.**',
            title='New Article',
            content='Super extra awesome article').save()

    cmd = CreateArticleCommand(author='*****@*****.**',
                               title='New Article',
                               content='Super awesome article')

    with pytest.raises(AlreadyExists):
        cmd.execute()
Example #3
0
def test_create_article_already_exists():
    """
    GIVEN CreateArticleCommand with a title of some article in database
    WHEN the execute method is called
    THEN the AlreadyExists exception must be raised
    """
    Article(author='*****@*****.**',
            title='New Article',
            content='Super extra awesome article').save()

    cmd = CreateArticleCommand(author='*****@*****.**',
                               title='New Article',
                               content='Super awesome article')

    with pytest.raises(AlreadyExists):
        cmd.execute()
Example #4
0
def test_create_article():
    """
    GIVEN CreateArticleCommand with a valid properties author, title and content
    WHEN the execute method is called
    THEN a new Article must exist in the database with the same attributes
    """
    cmd = CreateArticleCommand(author='*****@*****.**',
                               title='New Article',
                               content='Super awesome article')

    article = cmd.execute()

    db_article = Article.get_by_id(article.id)

    assert db_article.id == article.id
    assert db_article.author == article.author
    assert db_article.title == article.title
    assert db_article.content == article.content
def test_create_article(monkeypatch):
    """
    GIVEN CreateArticleCommand with valid properties author, title and content
    WHEN the execute method is called
    THEN a new Article must exist in the database with same attributes
    """
    article = Article(author='*****@*****.**',
                      title='New Article',
                      content='Super awesome article')
    monkeypatch.setattr(Article, 'save', lambda self: article)
    cmd = CreateArticleCommand(author='*****@*****.**',
                               title='New Article',
                               content='Super awesome article')

    db_article = cmd.execute()

    assert db_article.id == article.id
    assert db_article.author == article.author
    assert db_article.title == article.title
    assert db_article.content == article.content
Example #6
0
def create_article():
    cmd = CreateArticleCommand(
        **request.json
    )
    return jsonify(cmd.execute().dict())