Example #1
0
def test_article_less_than_operator():
    article_1 = Article(date.fromisoformat('2020-03-15'), None, None, None,
                        None, None, None)

    article_2 = Article(date.fromisoformat('2020-04-20'), None, None, None,
                        None, None, None)

    assert article_1 < article_2
Example #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)
Example #3
0
def test_tag_construction(tag):
    assert tag.tag_name == 'Action'

    for article in tag.tagged_articles:
        assert False

    assert not tag.is_applied_to(
        Article(None, None, None, None, None, None, None, None))
Example #4
0
def article():
    return Article(
        2014,
        'James Gunn',
        ['Tom Cruise', 'Stevie Wonder'],
        7,
        5.0,
        'Guardians of the Galaxy',
        'A movie about things and stuff',
    )
def make_article(new_article_date):
    article = Article(
        2014,
        'James Gunn',
        ['Chris Pratt', 'Vin Diesel', 'Bradley Cooper', 'Zoe Saldana'],
        121,
        8.1,
        'Guardians of the Galaxy',
        'A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.',
    )
    return article
def test_repository_can_add_article(in_memory_repo):
    article = Article(
        2014,
        'James Gunn',
        ['Chris Pratt', 'Vin Diesel', 'Bradley Cooper', 'Zoe Saldana'],
        121,
        8.1,
        'Guardians of the Galaxy',
        'A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.',
    )
    in_memory_repo.add_article(article)

    assert in_memory_repo.get_article(1) == article
Example #7
0
def article_to_dict(article: Article):
    article_dict = {
        'id': article.id,
        'date': article.date,
        'title': article.title,
        'first_para': article.first_para,
        'director': article.director,
        'actors': article.actors,
        'rating': article.rating,
        'comments': comments_to_dict(article.comments),
        'tags': tags_to_dict(article.tags),
        'image_link': article.get_image()
    }
    return article_dict
def test_repository_can_add_article(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    number_of_articles = repo.get_number_of_articles()

    new_article_id = number_of_articles + 1

    article = Article(
        2014,
        'James Gunn',
        ['Chris Pratt', 'Vin Diesel', 'Bradley Cooper', 'Zoe Saldana'],
        121,
        8.1,
        'Guardians of the Galaxy',
        'A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.',
    )
    repo.add_article(article)

    assert repo.get_article(new_article_id) == article
Example #9
0
    def get_articles_by_date(self, target_date: date) -> List[Article]:
        target_article = Article(
            date=target_date,
            title=None,
            first_para=None,
            director=None,
            actors=None,
            runtime=None,
            rating=None
        )
        matching_articles = list()

        try:
            index = self.article_index(target_article)
            for article in self._articles[index:None]:
                if article.date == target_date:
                    matching_articles.append(article)
                else:
                    break
        except ValueError:
            # No articles for specified date. Simply return an empty list.
            pass

        return matching_articles
Example #10
0
def dict_to_article(dict):
    article = Article(dict.id, dict.date, dict.title, dict.first_para,
                      dict.actors, dict.directors, dict.rating,
                      dict.image_link, dict.tags)
    # Note there's no comments or tags.
    return article