test_write_rss_feed.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. try:
  2. from urllib import quote_plus
  3. except ImportError:
  4. from urllib.parse import quote_plus
  5. from xml.sax.saxutils import escape
  6. from write_rss_feed import FEED_FILENAME, lambda_handler
  7. def test_rss_feed_written(
  8. mocked_s3, uploaded_episodes, bucket, folder, domain, event):
  9. lambda_handler(event, context=None)
  10. feed_path = '{}/feed.xml'.format(folder)
  11. feed_xml = mocked_s3.get_object(
  12. Bucket=bucket,
  13. Key=feed_path)['Body'].read().decode()
  14. mp3s = [
  15. e['Key']
  16. for e in mocked_s3.list_objects_v2(Bucket=bucket)['Contents']
  17. if e['Key'].endswith('.mp3')
  18. ]
  19. for mp3 in mp3s:
  20. enclosure = '<enclosure url="{}/{}"'.format(
  21. domain, quote_plus(mp3, safe='/'))
  22. assert enclosure in feed_xml
  23. def test_index_with_first_feed(
  24. mocked_s3, uploaded_episodes, bucket, folder, domain, event):
  25. lambda_handler(event, context=None)
  26. index_html = mocked_s3.get_object(
  27. Bucket=bucket,
  28. Key='index.html',)['Body'].read().decode()
  29. link = '<a href="{}/{}/{}">{}</a>'.format(
  30. domain, folder, FEED_FILENAME, folder)
  31. assert link in index_html
  32. def test_index_with_additional_feed(
  33. mocked_s3, uploaded_episodes, bucket, domain,
  34. folder, event,
  35. folder2, event2
  36. ):
  37. lambda_handler(event, context=None)
  38. mocked_s3.put_object(
  39. Bucket=bucket,
  40. Key='{}/talking-17.mp3'.format(folder2),
  41. Body='talky talky',)
  42. lambda_handler(event2, None)
  43. index_html = mocked_s3.get_object(
  44. Bucket=bucket,
  45. Key='index.html',)['Body'].read().decode()
  46. link = '<a href="{}/{}/{}">{}</a>'.format(
  47. domain, folder, FEED_FILENAME, folder)
  48. assert link in index_html
  49. link2 = '<a href="{}/{}/{}">{}</a>'.format(
  50. domain, quote_plus(folder2), FEED_FILENAME, escape(folder2))
  51. assert link2 in index_html
  52. # test next
  53. # - lambda test button
  54. # - no folder
  55. # -