def test_can_retrieve_an_article_and_add_a_comment_to_it(session_factory): repo = SqlAlchemyRepository(session_factory) # Fetch Article and User. article = repo.get_article(5) author = repo.get_user('thorke') # Create a new Comment, connecting it to the Article and User. comment = make_comment('First death in Australia', author, article) article_fetched = repo.get_article(5) author_fetched = repo.get_user('thorke') assert comment in article_fetched.comments assert comment in author_fetched.comments
def test_repository_returns_none_when_there_are_no_subsequent_articles(session_factory): repo = SqlAlchemyRepository(session_factory) article = repo.get_article(177) next_date = repo.get_date_of_next_article(article) assert next_date is None
def test_repository_returns_date_of_next_article(session_factory): repo = SqlAlchemyRepository(session_factory) article = repo.get_article(3) next_date = repo.get_date_of_next_article(article) assert next_date.isoformat() == '2020-03-05'
def test_repository_returns_none_when_there_are_no_previous_articles(session_factory): repo = SqlAlchemyRepository(session_factory) article = repo.get_article(1) previous_date = repo.get_date_of_previous_article(article) assert previous_date is None
def test_repository_returns_date_of_previous_article(session_factory): repo = SqlAlchemyRepository(session_factory) article = repo.get_article(6) previous_date = repo.get_date_of_previous_article(article) assert previous_date.isoformat() == '2020-03-01'
def test_repository_does_not_add_a_comment_without_a_user(session_factory): repo = SqlAlchemyRepository(session_factory) article = repo.get_article(2) comment = Comment(None, article, "Trump's onto it!", datetime.today()) with pytest.raises(RepositoryException): repo.add_comment(comment)
def test_repository_can_add_a_comment(session_factory): repo = SqlAlchemyRepository(session_factory) user = repo.get_user('thorke') article = repo.get_article(2) comment = make_comment("Trump's onto it!", user, article) repo.add_comment(comment) assert comment in repo.get_comments()
def test_repository_can_add_article(session): repo = SqlAlchemyRepository(session) article = Article( 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 ) repo.add_article(article) session.commit() assert repo.get_article(7) is article
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'))
def test_repository_does_not_retrieve_a_non_existent_article(session_factory): repo = SqlAlchemyRepository(session_factory) article = repo.get_article(201) assert article is None