conftest.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import boto3
  2. import pytest
  3. from moto import mock_s3
  4. from write_rss_feed import DOMAIN
  5. import write_rss_feed
  6. @pytest.fixture
  7. def region():
  8. return 'us-east-1'
  9. @pytest.fixture
  10. def domain(region, bucket):
  11. return DOMAIN.format(bucket=bucket, region=region)
  12. @pytest.fixture
  13. def mocked_s3(region):
  14. with mock_s3():
  15. s3 = boto3.client('s3', region_name=region)
  16. write_rss_feed.s3 = s3
  17. yield s3
  18. @pytest.fixture
  19. def bucket():
  20. return 'my-bucket'
  21. @pytest.fixture
  22. def folder():
  23. return 'Pod-Fever'
  24. @pytest.fixture
  25. def folder2():
  26. return '2nd-podcast & friends'
  27. @pytest.fixture
  28. def uploaded_episodes(mocked_s3, bucket, folder):
  29. mocked_s3.create_bucket(Bucket=bucket)
  30. for i in range(1, 11):
  31. size = 1000 + 100 * i
  32. mocked_s3.put_object(
  33. Bucket=bucket,
  34. Key='{}/episode{}.mp3'.format(folder, i),
  35. Body='x' * size,)
  36. @pytest.fixture
  37. def event(bucket, folder):
  38. return make_event("{}/episode10.mp3".format(folder), bucket)
  39. @pytest.fixture
  40. def event2(bucket, folder2):
  41. return make_event("{}/talking-17.mp3".format(folder2), bucket)
  42. def make_event(key, bucket):
  43. return {
  44. "Records": [
  45. {
  46. "eventVersion": "2.0",
  47. "eventTime": "1970-01-01T00:00:00.000Z",
  48. "requestParameters": {
  49. "sourceIPAddress": "127.0.0.1"
  50. },
  51. "s3": {
  52. "configurationId": "testConfigRule",
  53. "object": {
  54. "eTag": "0123456789abcdef0123456789abcdef",
  55. "key": key,
  56. "sequencer": "0A1B2C3D4E5F678901",
  57. "size": 1024
  58. },
  59. "bucket": {
  60. "ownerIdentity": {
  61. "principalId": "EXAMPLE"
  62. },
  63. "name": bucket,
  64. "arn": "arn:aws:s3:::mybucket"
  65. },
  66. "s3SchemaVersion": "1.0"
  67. },
  68. "responseElements": {
  69. "x-amz-id-2": "EXAMPLE123/567/ABCDEFGH",
  70. "x-amz-request-id": "EXAMPLE123456789"
  71. },
  72. "awsRegion": "us-east-1",
  73. "eventName": "ObjectCreated:Put",
  74. "userIdentity": {
  75. "principalId": "EXAMPLE"
  76. },
  77. "eventSource": "aws:s3"
  78. }
  79. ]
  80. }