コード例 #1
0
def test_can_update_many_article_attributes_at_once():
    _article = {
        'title': 'An article',
        'description': 'A great description',
        'content': 'This is a useful article',
        'category_id': 1,
        'tags': ['verbos', 'substantivos'],
    }

    uow = FakeUnitOfWork()

    create_tags(uow)

    article_service.add_article(**_article, uow=uow)

    _article = uow.articles.get('an-article')

    assert _article.tags == [tag.Tag('verbos'), tag.Tag('substantivos')]

    article_service.update_article(article_url='an-article',
                                   description='A new description',
                                   content='A new content',
                                   category=2,
                                   tags=['dicas'],
                                   uow=uow)

    updated = uow.articles.get('an-article')

    assert updated.description == 'A new description'
    assert updated.content == 'A new content'
    assert updated.category == 2
    assert updated.tags == [tag.Tag('dicas')]
コード例 #2
0
def tag_factory():
    return [
        tag.Tag('verbos'),
        tag.Tag('vocabulario'),
        tag.Tag('subtantivo'),
        tag.Tag('gramatica')
    ]
コード例 #3
0
def test_service_can_update_tag():
    uow = FakeUnitOfWork()

    tag_list = [tag.Tag('dicas'), tag.Tag('verbos'), tag.Tag('substantivos')]

    for _tag in tag_list:
        uow.tags.add(_tag)

    assert len(uow.tags.list()) == 3

    tag_service.update_tag(tag_name='dicas', new_name='sugestões', uow=uow)

    assert uow.tags.get('sugestões')
コード例 #4
0
def test_raises_tag_not_found_error_when_deleting_non_existent_tag():
    uow = FakeUnitOfWork()

    tag_list = [tag.Tag('dicas'), tag.Tag('verbos'), tag.Tag('substantivos')]

    for _tag in tag_list:
        uow.tags.add(_tag)

    assert len(uow.tags.list()) == 3

    with pytest.raises(exceptions.TagNotFound, match='Tag not found'):

        tag_service.delete_tag('adjetivos', uow)
コード例 #5
0
def test_service_can_delete_tag():
    uow = FakeUnitOfWork()

    tag_list = [tag.Tag('dicas'), tag.Tag('verbos'), tag.Tag('substantivos')]

    for _tag in tag_list:
        uow.tags.add(_tag)

    assert len(uow.tags.list()) == 3

    tag_service.delete_tag('dicas', uow)

    assert len(uow.tags.list()) == 2
コード例 #6
0
def test_gets_valid_tags():
    uow = FakeUnitOfWork()

    tag_list = [tag.Tag('dicas'), tag.Tag('verbos'), tag.Tag('substantivos')]

    for _tag in tag_list:
        uow.tags.add(_tag)

    tags_to_check = ['dicas', 'verbos', 'substantivos', 'invalid1', 'invalid2']

    valid_tags = tag_service.get_valid_tags_by_name(tags_to_check, uow)

    assert valid_tags == tag_list
コード例 #7
0
def test_returns_false_when_title_is_not_duplicate():
    uow = FakeUnitOfWork()

    article_1 = article.Article(
        title='An article',
        description='A great description',
        content='This is a useful article',
        category=category.Category.CULTURE,
        tags=[tag.Tag('verbos'), tag.Tag('substantivos')])

    uow.articles.add(article_1)

    uow.commit()

    assert article_service.title_is_duplicate(title='A new article',
                                              uow=uow) is False
コード例 #8
0
def test_service_adds_an_article():
    uow = FakeUnitOfWork()

    create_tags(uow)

    _article = {
        'title': 'An article',
        'description': 'A great description',
        'content': 'This is a useful article',
        'category_id': 1,
        'tags': ['verbos', 'substantivos'],
    }

    article_title = article_service.add_article(**_article, uow=uow)

    result = uow.articles.get('an-article')

    assert article_title == 'An article'
    assert result.tags == [tag.Tag('verbos'), tag.Tag('substantivos')]
コード例 #9
0
def add_tag(tag_name: str, uow: unit_of_work.AbstractUnitOfWork) -> str:
    with uow:

        tags = uow.tags.list()

        _tag = tag.Tag(tag_name)

        if _tag in tags:
            raise exceptions.DuplicateTag(f'Tag {tag_name} is duplicate')

        uow.tags.add(_tag)
        uow.commit()

    return tag_name
コード例 #10
0
def test_returns_false_when_passing_article_to_exclude_from_comparison():
    uow = FakeUnitOfWork()

    article_1 = article.Article(
        title='An article',
        description='A great description',
        content='This is a useful article',
        category=category.Category.CULTURE,
        tags=[tag.Tag('verbos'), tag.Tag('substantivos')])

    article_2 = article.Article(
        title='Another article',
        description='A great description',
        content='This is a useful article',
        category=category.Category.CULTURE,
        tags=[tag.Tag('verbos'), tag.Tag('substantivos')])

    uow.articles.add(article_1)
    uow.articles.add(article_2)
    uow.commit()

    assert article_service.title_is_duplicate(
        title='An article', article_to_update=article_1, uow=uow) is False
コード例 #11
0
    def test_can_add_an_article(self, session):
        _article = article.Article(
            title='An article',
            description='A great description',
            content='This is a useful article',
            tags=[tag.Tag('verbos')],
            category=category.Category.GUIDE
        )

        repo = repository.SqlAlchemyRepositoryArticles(session)

        repo.add(_article)
        session.commit()

        assert session.query(article.Article).first() == _article
コード例 #12
0
    def test_gets_article_by_url(self, session):
        _article = article.Article(
            title='An article',
            description='A great description',
            content='This is a useful article',
            tags=[tag.Tag('verbos')],
            category=category.Category.GUIDE
        )

        repo = repository.SqlAlchemyRepositoryArticles(session)

        repo.add(_article)
        session.commit()

        assert _article == repo.get(value='an-article')
コード例 #13
0
def test_uow_can_add_an_article(session_factory):

    _article = article.Article(title='An article',
                               description='A great description',
                               content='This is a useful article',
                               tags=[tag.Tag('verbos')],
                               category=category.Category.GUIDE)

    uow = unit_of_work.SqlAlchemyUnitOfWork(session_factory)

    with uow:
        uow.articles.add(_article)
        uow.commit()

    session = session_factory()

    retrieved_article = session.query(article.Article).first()

    assert retrieved_article.title == 'An article'
コード例 #14
0
def test_can_update_tags_of_article():
    _article = {
        'title': 'An article',
        'description': 'A great description',
        'content': 'This is a useful article',
        'category_id': 1,
        'tags': ['verbos', 'substantivos'],
    }

    uow = FakeUnitOfWork()

    create_tags(uow)

    article_service.add_article(**_article, uow=uow)

    _article = uow.articles.get(value='an-article')

    article_service.update_attribute(_article,
                                     attribute='tags',
                                     _kwargs={'tags': ['verbos']},
                                     uow=uow)

    updated = uow.articles.get(value='an-article')
    assert updated.tags == [tag.Tag('verbos')]
コード例 #15
0
def create_tags(uow):
    _tags = [tag.Tag('verbos'), tag.Tag('substantivos'), tag.Tag('dicas')]

    for _tag in _tags:
        uow.tags.add(_tag)
    uow.commit()