test_parsing_and_db.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from pathlib import Path
  2. from gemini_antenna.db import AntennaDB
  3. from gemini_antenna.multiFeedParsing import parsegemsub, parsexml, parsetwtxt
  4. def test_gemsub(db: AntennaDB):
  5. agelimit = 1605000000
  6. with open(Path("tests") / "feed.gmi") as file:
  7. entries = parsegemsub(file.read(), "gemini://gemini.jrandom.net/gemlog/")
  8. assert db.insertFeedEntries(entries) == 3
  9. assert db.insertFeedEntries(entries, agelimit) == 2
  10. assert len(db.getEntries()) == 3
  11. db.pruneDB(agelimit)
  12. assert len(db.getEntries()) == 2
  13. db.deleteFeeds("gemini://gemini.jrandom.net/~user/gemlog/")
  14. assert len(db.getEntries()) == 2
  15. db.deleteFeeds("gemini://gemini.jrandom.net/gemlog/")
  16. assert len(db.getEntries()) == 0
  17. def test_atom(db: AntennaDB):
  18. agelimit = 1605000000
  19. with open(Path("tests") / "feed.atom") as file:
  20. entries = parsexml(file.read(), "gemini://gemini.jrandom.net/gemlog/")
  21. assert db.insertFeedEntries(entries) == 3
  22. assert db.insertFeedEntries(entries, agelimit) == 2
  23. assert len(db.getEntries()) == 3
  24. db.pruneDB(agelimit)
  25. assert len(db.getEntries()) == 2
  26. db.deleteFeeds("gemini://gemini.jrandom.net/~user/gemlog/")
  27. assert len(db.getEntries()) == 2
  28. db.deleteFeeds("gemini://gemini.jrandom.net/gemlog/")
  29. assert len(db.getEntries()) == 0
  30. def test_twtxt(db: AntennaDB):
  31. agelimit = 1450000000
  32. with open(Path("tests") / "twtxt.txt") as file:
  33. entries = parsetwtxt(file.read(), "gemini://example.com/twtxt.txt")
  34. assert db.insertTwtxtEntries(entries) == 4
  35. assert len(db.getTwts()) == 4
  36. db.pruneDB(agelimit)
  37. assert len(db.getTwts()) == 3
  38. db.deleteFeeds("gemini://example.com/~user/twtxt.txt")
  39. assert len(db.getTwts()) == 3
  40. db.deleteFeeds("gemini://example.com/twtxt.txt")
  41. assert len(db.getTwts()) == 0