Various Mastodon Bots

tests.py 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/python3
  2. import format
  3. import unittest
  4. from rbu_rss import RBU_RSS
  5. from util import getAbsolutePath
  6. class testFormat(unittest.TestCase):
  7. def setUp(self):
  8. self.maxDiff = None
  9. def test_extractText(self):
  10. testHtml = ('<p>The past was not as smelly as you think'
  11. '<a href="https://newrepublic.com/article/129828/'
  12. 'getting-clean-tudor-way" rel="nofollow noopener" '
  13. 'target="_blank"><span class="invisible"></span><span class='
  14. '"ellipsis"></span><span class="invisible"></span></a></p><p>'
  15. '<a href="https://refactorcamp.org/tags/heyfeedfox" '
  16. 'class="mention hashtag" rel="tag"><span></span></a></p>')
  17. desiredResult = 'The past was not as smelly as you think'
  18. result = format.extractText(testHtml)
  19. self.assertEqual(result, desiredResult)
  20. def test_extractExternalLinks(self):
  21. testHtml = ('<p>Design thinking is inherently conservative '
  22. '<a href="https://refactorcamp.org/tags/heyfeedfox" '
  23. 'class="mention hashtag" rel="tag">#<span>heyfeedfox</span></a> '
  24. '<a href="https://hbr.org/2018/09/design-thinking-is-fundamentally'
  25. '-conservative-and-preserves-the-status-quo" rel="nofollow noopener"'
  26. 'target="_blank"><span class="invisible">https://zfadd.is/resume'
  27. '</span><span class="ellipsis">hbr.org/2018/09/design-thinkin</span>'
  28. '<span class="invisible">g-is-fundamentally-conservative-and-preserves'
  29. '-the-status-quo</span></a></p>'
  30. 'a href="http://hello world"')
  31. desiredResult = \
  32. ["hbr.org/2018/09/design-thinking-is-fundamentally-conservative-and-preserves-the-status-quo",
  33. "hello world"]
  34. result = format.extractExternalLinks(testHtml)
  35. self.assertEqual(result, desiredResult)
  36. def test_formatBlogLog(self):
  37. self.maxDiff = None
  38. title = 'Report: The Diminishing Marginal Value of Aesthetics'
  39. author = '@telos'
  40. link = 'http://subpixel.space/entries/diminishing-marginal-aesthetic-value/'
  41. result = format.formatBlogLog(title, author, link)
  42. desiredResult = (
  43. 'Report: The Diminishing Marginal Value of Aesthetics '
  44. 'by <a href="https://refactorcamp.org/@telos">@telos</a>. '
  45. '<a '
  46. 'href="http://subpixel.space/entries/diminishing-marginal-aesthetic-value/">Link</a>')
  47. self.assertEqual(result, desiredResult)
  48. def test_formatLinkedTootLog(self):
  49. mastobot = RBU_RSS()
  50. linkedToot = mastobot.status(100722130702281095)
  51. title = linkedToot.content
  52. author = linkedToot.account.acct
  53. result = format.formatLinkedTootLog(title, author)
  54. desiredResult = ('A detailed assault on the book Sapiens. '
  55. 'The author of the critique cites his own work '
  56. 'a lot, but shows how many of the theories put forth '
  57. 'as fact in Sapiens are incorrect and ahistorical. .'
  58. '<a '
  59. 'href="http://www.newenglishreview.org/custpage.cfm?'
  60. 'sec_id=189085">Link</a>. ht '
  61. '<a href="https://refactorcamp.org/@britt">@britt</a>')
  62. self.assertEqual(result, desiredResult)
  63. def test_formatLocalTootLog(self):
  64. mastobot = RBU_RSS()
  65. localToot = mastobot.status(100719517294830106)
  66. title = localToot.content
  67. author = localToot.account.acct
  68. result = format.formatLocalTootLog(title, author)
  69. desiredResult = ('Irreversible choices have 2 aspects besides not '
  70. 'being able to go back: the fateful option leading '
  71. 'to uncharted regimes, and do-overs being'
  72. ' costly/impossible. '
  73. 'If future is like past, or you can do-over cheaply'
  74. ', irreversibility is moot. Like Coke vs Sprite at a '
  75. 'vending machine.'
  76. ' -- <a href="https://refactorcamp.org/@vgr">@vgr</a>')
  77. self.assertEqual(result, desiredResult)
  78. if __name__ == '__main__':
  79. unittest.main()