Skip to content

Commit

Permalink
Add tests for new get_all_cites subfunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
virhe committed Nov 30, 2023
1 parent 06a6200 commit ebf4178
Showing 1 changed file with 106 additions and 35 deletions.
141 changes: 106 additions & 35 deletions src/tests/repositories/test_cite_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit ebf4178

Please sign in to comment.