def test_repository_can_add_a_tag(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    tag = Tag('Motoring')
    repo.add_tag(tag)

    assert tag in repo.get_tags()
Esempio n. 2
0
def load_articles_and_tags(data_path: str, repo: MemoryRepository):
    tags = dict()

    for data_row in read_csv_file(os.path.join(data_path, 'Data1000Movies.csv')):
        article_key = int(data_row[0])
        number_of_tags = len(data_row[3].split(","))
        article_tags = data_row[2].split(",")
        # Add any new tags; associate the current article with tags.
        for tag in article_tags:
            if tag not in tags.keys():
                tags[tag] = list()
            tags[tag].append(article_key)

        # Create Article object.
        article = Article(
            date=int(data_row[6]),
            title=data_row[1],
            first_para=data_row[3],
            id=int(article_key),
            director=Director(data_row[4]),
            actors=[Actor(i) for i in data_row[5].split(",")],
            runtime = int(data_row[7]),
            rating=float(data_row[8])
        )

        # Add the Article to the repository.
        repo.add_article(article)

    # Create Tag objects, associate them with Articles and add them to the repository.
    for tag_name in tags.keys():
        tag = Tag(tag_name)
        for article_id in tags[tag_name]:
            article = repo.get_article(article_id)
            make_tag_association(article, tag)
        repo.add_tag(tag)
def test_repository_can_retrieve_article(in_memory_repo):
    article = in_memory_repo.get_article(1)

    # Check that the Article has the expected title.
    assert article.title == 'Guardians of the Galaxy'

    # Check that the Article is commented as expected.
    comment_one = [
        comment for comment in article.comments
        if comment.comment == 'Oh no, COVID-19 has hit New Zealand'
    ][0]
    comment_two = [
        comment for comment in article.comments
        if comment.comment == 'Yeah Freddie, bad news'
    ][0]

    assert comment_one.user.username == 'fmercury'
    assert comment_two.user.username == "thorke"

    # Check that the Article is tagged as expected.
    assert article.is_tagged_by(Tag('Action'))
    assert article.is_tagged_by(Tag('Adventure'))
def test_repository_can_retrieve_article(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    article = repo.get_article(1)

    # Check that the Article has the expected title.
    assert article.title == 'Coronavirus: First case of virus in New Zealand'

    # Check that the Article is commented as expected.
    comment_one = [
        comment for comment in article.comments
        if comment.comment == 'Oh no, COVID-19 has hit New Zealand'
    ][0]
    comment_two = [
        comment for comment in article.comments
        if comment.comment == 'Yeah Freddie, bad news'
    ][0]

    assert comment_one.user.username == 'fmercury'
    assert comment_two.user.username == "thorke"

    # Check that the Article is tagged as expected.
    assert article.is_tagged_by(Tag('Health'))
    assert article.is_tagged_by(Tag('New Zealand'))
Esempio n. 5
0
def tag():
    return Tag('Action')
def test_repository_can_add_a_tag(in_memory_repo):
    tag = Tag('Motoring')
    in_memory_repo.add_tag(tag)

    assert tag in in_memory_repo.get_tags()
Esempio n. 7
0
def make_tag():
    tag = Tag("Action")
    return tag