Fix the "test_offline" test (#42458)
* Fix the test offline test
* Refactor test_offline method with context patches
Refactor test_offline to use patch for offline mode.
* Apply suggestion from @Wauplin
---------
Co-authored-by: Lucain <lucainp@gmail.com>