From ebf4178d6101a44513fbb2d3bae0e442f48d2b24 Mon Sep 17 00:00:00 2001 From: tuome Date: Thu, 30 Nov 2023 17:02:01 +0200 Subject: [PATCH] Add tests for new get_all_cites subfunctions --- .../repositories/test_cite_repository.py | 141 +++++++++++++----- 1 file changed, 106 insertions(+), 35 deletions(-) diff --git a/src/tests/repositories/test_cite_repository.py b/src/tests/repositories/test_cite_repository.py index a0f3cf0..cf4a76c 100644 --- a/src/tests/repositories/test_cite_repository.py +++ b/src/tests/repositories/test_cite_repository.py @@ -83,38 +83,109 @@ def test_add_cite_adds_correct_id_and_type(self): self.assertEqual(cites[0]["id"], "amazingBook") self.assertEqual(cites[0]["type"], "book") - # def test_fetching_all_cites(self): - # self.repository.remove_all_cites() - # self.repository.add_cite( - # Cite( - # "amazingBook", - # "book", - # ["Alice", "Bob"], - # {"year": 3202, "title": "An amazing book"}, - # ) - # ) - # self.repository.add_cite( - # Cite( - # "wonderful story", - # "book", - # ["wonder", "Full"], - # {"year": 2002, "title": "Wonderful story"}, - # ) - # ) - - # cites = self.repository.get_all_cites() - # self.assertEqual(len(cites), 4) - - # def test_get_correct_cites(self): - # self.repository.remove_all_cites() - # self.repository.add_cite( - # Cite( - # "amazingBook", - # "book", - # ["Alice", "Bob"], - # {"year": 3202, "title": "An amazing book"}, - # ) - # ) - # cites = self.repository.get_all_cites() - # self.assertEqual(cites[0]["id"], "amazingBook") - # self.assertEqual(cites[1]["id"], "amazingBook") + def test_get_all_ids(self): + self.repository.add_cite(Cite("idtest1", "book", ["Alice1", "Bob1"], {})) + self.repository.add_cite( + Cite("idtest2", "article", ["AnemicAlice", "BetterBob"], {}) + ) + + expected_ids = ["idtest1", "idtest2"] + ids = self.repository.get_all_ids() + + self.assertEqual(ids, expected_ids) + + def test_get_all_types(self): + self.repository.add_cite(Cite("typetest1", "book", ["Alice1", "Bob1"], {})) + self.repository.add_cite( + Cite("typetest2", "article", ["AnotherAlice", "BusyBob"], {}) + ) + self.repository.add_cite( + Cite("typetest3", "journal", ["AnemicAlice", "BetterBob"], {}) + ) + + expected_types = { + "typetest1": "book", + "typetest2": "article", + "typetest3": "journal", + } + types = self.repository.get_all_types() + + self.assertEqual(types, expected_types) + + def test_get_all_authors(self): + self.repository.add_cite(Cite("authortest1", "book", ["Alice1", "Bob1"], {})) + self.repository.add_cite(Cite("authortest2", "article", ["AnotherAlice"], {})) + + expected_authors = { + "authortest1": ["Alice1", "Bob1"], + "authortest2": ["AnotherAlice"], + } + authors = self.repository.get_all_authors() + + self.assertEqual(authors, expected_authors) + + def test_get_all_fields(self): + self.repository.add_cite( + Cite( + "fieldtest1", + "book", + ["Alice1", "Bob1"], + {"field1": "value1", "field2": "value2"}, + ) + ) + self.repository.add_cite( + Cite( + "fieldtest2", + "article", + ["AnotherAlice"], + {"field3": "value3", "field4": "value4"}, + ) + ) + + expected_fields = { + "fieldtest1": {"field1": "value1", "field2": "value2"}, + "fieldtest2": {"field3": "value3", "field4": "value4"}, + } + fields = self.repository.get_all_fields() + + self.assertEqual(fields, expected_fields) + + def test_get_all_cite(self): + self.repository.add_cite( + Cite( + "fieldtest1", + "book", + ["Alice1", "Bob1"], + {"field1": "value1", "field2": "value2"}, + ) + ) + self.repository.add_cite( + Cite( + "fieldtest2", + "article", + ["AnotherAlice"], + {"field3": "value3", "field4": "value4"}, + ) + ) + + expected_cites = [ + Cite( + "fieldtest1", + "book", + ["Alice1", "Bob1"], + {"field1": "value1", "field2": "value2"}, + ), + Cite( + "fieldtest2", + "article", + ["AnotherAlice"], + {"field3": "value3", "field4": "value4"}, + ), + ] + cites = self.repository.get_all_cites() + + for cite, expected_cite in zip(cites, expected_cites): + self.assertEqual(cite.id, expected_cite.id) + self.assertEqual(cite.type, expected_cite.type) + self.assertEqual(cite.authors, expected_cite.authors) + self.assertEqual(cite.fields, expected_cite.fields)