Exemplo n.º 1
0
def test_article_less_than_operator():
    article_1 = Movies(date.fromisoformat('2020-03-15'), None, None, None,
                       None)

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

    assert article_1 < article_2
Exemplo n.º 2
0
def test_tag_construction(tag):
    assert tag.tag_name == 'New Zealand'

    for article in tag.tagged_articles:
        assert False

    assert not tag.is_applied_to(Movies(None, None, None, None, None, None))
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])
        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 Movies object.
        article = Movies(
            id=article_key,
            date=date.fromisoformat(data_row[6]+"-02-28"),
            title=data_row[1],
            first_para=data_row[3],
            hyperlink="{}{}{}".format("https://image.tmdb.org/t/p/", "w400", data_row[13]),
            image_hyperlink="{}{}{}".format("https://image.tmdb.org/t/p/", "w400", data_row[13])
        )

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

    # Create Tag objects, associate them with Movies 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)
Exemplo n.º 4
0
def article():
    return Movies(
        date.fromisoformat('2020-03-15'),
        'Coronavirus travel restrictions: Self-isolation deadline pushed back to give airlines breathing room',
        'The self-isolation deadline has been pushed back',
        'https://www.nzherald.co.nz/business/news/article.cfm?c_id=3&objectid=12316800',
        'https://th.bing.com/th/id/OIP.0lCxLKfDnOyswQCF9rcv7AHaCz?w=344&h=132&c=7&o=5&pid=1.7'
    )
Exemplo n.º 5
0
def make_article():
    article = Movies(
        article_date, "Coronavirus: First case of virus in New Zealand",
        "The first case of coronavirus has been confirmed in New Zealand  and authorities are now scrambling to track down people who may have come into contact with the patient.",
        "https://www.stuff.co.nz/national/health/119899280/ministry-of-health-gives-latest-update-on-novel-coronavirus",
        "https://resources.stuff.co.nz/content/dam/images/1/z/e/3/w/n/image.related.StuffLandscapeSixteenByNine.1240x700.1zduvk.png/1583369866749.jpg"
    )
    return article
def make_article(new_article_date):
    article = Movies(
        new_article_date,
        'Coronavirus travel restrictions: Self-isolation deadline pushed back to give airlines breathing room',
        'The self-isolation deadline has been pushed back',
        'https://www.nzherald.co.nz/business/news/article.cfm?c_id=3&objectid=12316800',
        'https://th.bing.com/th/id/OIP.0lCxLKfDnOyswQCF9rcv7AHaCz?w=344&h=132&c=7&o=5&pid=1.7'
    )
    return article
Exemplo n.º 7
0
def test_repository_can_add_article(in_memory_repo):
    article = Movies(
        date.fromisoformat('2020-03-09'),
        'Second US coronavirus cruise tests negative amid delays and cancellations',
        'It was revealed ...',
        'https://www.nzherald.co.nz/travel/news/article.cfm?c_id=7&objectid=12315024',
        'https://www.nzherald.co.nz/resizer/ix7hy3lzkMWUkD8hE6kdZ-8oaOM=/620x349/smart/filters:quality(70)/arc-anglerfish-syd-prod-nzme.s3.amazonaws.com/public/7VFOBLCBCNDHLICBY3CTPFR2L4.jpg',
        7)
    in_memory_repo.add_article(article)

    assert in_memory_repo.get_article(7) is article
    def get_articles_by_date(self, target_date: date) -> List[Movies]:
        target_article = Movies(
            date=target_date,
            title=None,
            first_para=None,
            hyperlink=None,
            image_hyperlink=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
Exemplo n.º 9
0
def dict_to_article(dict):
    article = Movies(dict.id, dict.date, dict.title, dict.first_para,
                     dict.hyperlink)
    # Note there's no comments or tags.
    return article