TechAndCheck / zenodotus

MIT License
4 stars 1 forks source link

Ensure tests can be run offline #352

Open reefdog opened 1 year ago

reefdog commented 1 year ago

It would be nice to be able to run our tests offline, for low-bandwidth scenarios and as a target for fully mocking all our external API calls. #206 got us way down the path, but disabling internet and running tests reveals some additional gaps, of two types:

Click to view full test output ``` Error: ArchiveItemTest#test_destroying_a_user_resets_the_submitter_id_of_ArchiveItems_it_created: Birdsong::AuthorizationError: Invalid response code 0 app/media_sources/twitter_media_source.rb:60:in `retrieve_tweet' app/media_sources/twitter_media_source.rb:35:in `extract' app/models/sources/tweet.rb:47:in `create_from_url' test/models/archive_item_test.rb:17:in `block in ' test/models/archive_item_test.rb:11:in `block in around' test/models/archive_item_test.rb:10:in `around' rails test test/models/archive_item_test.rb:15 Failure: TwitterMediaSourceTest#test_initializing_returns_blank [/Users/justin/Projects/duke/zenodotus/test/media_sources/twitter_media_source_test.rb:23]: [Birdsong::NoTweetFoundError] exception expected, not Class: Message: <"Invalid response code 0"> ---Backtrace--- app/media_sources/twitter_media_source.rb:60:in `retrieve_tweet' app/media_sources/twitter_media_source.rb:35:in `extract' test/media_sources/twitter_media_source_test.rb:24:in `block in test_initializing_returns_blank' test/media_sources/twitter_media_source_test.rb:23:in `test_initializing_returns_blank' --------------- rails test test/media_sources/twitter_media_source_test.rb:22 Error: TwitterMediaSourceTest#test_extracting_creates_tweet_object: Birdsong::AuthorizationError: Invalid response code 0 app/media_sources/twitter_media_source.rb:60:in `retrieve_tweet' app/media_sources/twitter_media_source.rb:35:in `extract' test/media_sources/twitter_media_source_test.rb:29:in `test_extracting_creates_tweet_object' rails test test/media_sources/twitter_media_source_test.rb:28 Error: TweetTest#before_all: Birdsong::AuthorizationError: Invalid response code 0 app/media_sources/twitter_media_source.rb:60:in `retrieve_tweet' app/media_sources/twitter_media_source.rb:35:in `extract' test/models/tweet_test.rb:10:in `before_all' rails test test/models/tweet_test.rb:9 Failure: IngestControllerTest#test_can_archive_MediaReview_from_a_webpage [/Users/justin/Projects/duke/zenodotus/test/controllers/ingest_controller_test.rb:113]: Expected response to be a <200: OK>, but was a <400: Bad Request> Response body: {"response_code":40,"response":"Could not find MediaReview in webpage"}. Expected: 200 Actual: 400 rails test test/controllers/ingest_controller_test.rb:111 Error: IngestControllerTest#test_Can_archive_media_review_from_json: Birdsong::AuthorizationError: Invalid response code 0 app/media_sources/twitter_media_source.rb:60:in `retrieve_tweet' app/media_sources/twitter_media_source.rb:35:in `extract' app/models/sources/tweet.rb:47:in `create_from_url' app/models/archive_item.rb:34:in `create_from_media_review' app/controllers/ingest_controller.rb:168:in `archive_from_media_review' app/controllers/ingest_controller.rb:76:in `submit_media_review' test/controllers/ingest_controller_test.rb:90:in `block in ' rails test test/controllers/ingest_controller_test.rb:52 Failure: IngestControllerTest#test_can_archive_multiple_MediaReview_from_a_webpage [/Users/justin/Projects/duke/zenodotus/test/controllers/ingest_controller_test.rb:129]: Expected response to be a <200: OK>, but was a <400: Bad Request> Response body: {"response_code":40,"response":"Could not find MediaReview in webpage"}. Expected: 200 Actual: 400 rails test test/controllers/ingest_controller_test.rb:127 Error: ImageHashTest#test_dhash_properly_added_to_graph: Birdsong::AuthorizationError: Invalid response code 0 app/media_sources/twitter_media_source.rb:60:in `retrieve_tweet' app/media_sources/twitter_media_source.rb:35:in `extract' test/models/image_hash_test.rb:17:in `block in ' rails test test/models/image_hash_test.rb:14 Error: ArchiveControllerTest#test_can_run_text_search: Birdsong::AuthorizationError: Invalid response code 0 app/media_sources/twitter_media_source.rb:60:in `retrieve_tweet' app/media_sources/twitter_media_source.rb:35:in `extract' app/models/sources/tweet.rb:47:in `create_from_url' test/controllers/text_search_controller_test.rb:10:in `block in ' test/controllers/archive_controller_test.rb:11:in `block in around' test/controllers/archive_controller_test.rb:10:in `around' rails test test/controllers/text_search_controller_test.rb:8 Error: TwitterUserTest#test_can_update_twitter_user: Birdsong::AuthorizationError: Invalid response code 0 app/media_sources/twitter_media_source.rb:60:in `retrieve_tweet' app/media_sources/twitter_media_source.rb:35:in `extract' test/models/twitter_user_test.rb:7:in `setup' rails test test/models/twitter_user_test.rb:39 Error: TwitterUserTest#test_can_create_twitter_user: Birdsong::AuthorizationError: Invalid response code 0 app/media_sources/twitter_media_source.rb:60:in `retrieve_tweet' app/media_sources/twitter_media_source.rb:35:in `extract' test/models/twitter_user_test.rb:7:in `setup' rails test test/models/twitter_user_test.rb:18 ```
reefdog commented 1 year ago

Update: the only remaining failures for this to work are the Could not find MediaReview in webpage in ingest_controller_test:

Failure:
MediaVault::IngestControllerTest#test_can_archive_multiple_MediaReview_from_a_webpage [/Users/justin/Projects/duke/zenodotus/test/controllers/media_vault/ingest_controller_test.rb:161]:
Expected response to be a <200: OK>, but was a <400: Bad Request>
Response body: {"response_code":40,"response":"Could not find MediaReview in webpage"}.
Expected: 200
  Actual: 400

rails test test/controllers/media_vault/ingest_controller_test.rb:159

Failure:
MediaVault::IngestControllerTest#test_can_archive_MediaReview_from_a_webpage [/Users/justin/Projects/duke/zenodotus/test/controllers/media_vault/ingest_controller_test.rb:145]:
Expected response to be a <200: OK>, but was a <400: Bad Request>
Response body: {"response_code":40,"response":"Could not find MediaReview in webpage"}.
Expected: 200
  Actual: 400

rails test test/controllers/media_vault/ingest_controller_test.rb:143