Fit for unit test (#3426)

* Fit for unit test

- Write known value to setting before perfoming read test

(cherry picked from commit 7042d8b9badb7bf50f6f6566c3d4171d68d43f0c)

* Allow longer timeout for image download tests

(cherry picked from commit e1ce13043f)
This commit is contained in:
Oliver 2022-07-28 13:52:16 +10:00 committed by GitHub
parent 2b1658e513
commit 4d5e267753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -267,7 +267,7 @@ class TestHelpers(TestCase):
# Attempt to download an image which throws a 404 # Attempt to download an image which throws a 404
with self.assertRaises(requests.exceptions.HTTPError): with self.assertRaises(requests.exceptions.HTTPError):
helpers.download_image_from_url("https://httpstat.us/404") helpers.download_image_from_url("https://httpstat.us/404", timeout=10)
# Attempt to download, but timeout # Attempt to download, but timeout
with self.assertRaises(requests.exceptions.Timeout): with self.assertRaises(requests.exceptions.Timeout):
@ -275,7 +275,7 @@ class TestHelpers(TestCase):
# Attempt to download, but not a valid image # Attempt to download, but not a valid image
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
helpers.download_image_from_url("https://httpstat.us/200") helpers.download_image_from_url("https://httpstat.us/200", timeout=10)
large_img = "https://github.com/inventree/InvenTree/raw/master/InvenTree/InvenTree/static/img/paper_splash_large.jpg" large_img = "https://github.com/inventree/InvenTree/raw/master/InvenTree/InvenTree/static/img/paper_splash_large.jpg"
@ -283,13 +283,13 @@ class TestHelpers(TestCase):
# Attempt to download an image which is too large # Attempt to download an image which is too large
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
helpers.download_image_from_url(large_img) helpers.download_image_from_url(large_img, timeout=10)
# Increase allowable download size # Increase allowable download size
InvenTreeSetting.set_setting('INVENTREE_DOWNLOAD_IMAGE_MAX_SIZE', 5, change_user=None) InvenTreeSetting.set_setting('INVENTREE_DOWNLOAD_IMAGE_MAX_SIZE', 5, change_user=None)
# Download a valid image (should not throw an error) # Download a valid image (should not throw an error)
helpers.download_image_from_url(large_img) helpers.download_image_from_url(large_img, timeout=10)
class TestQuoteWrap(TestCase): class TestQuoteWrap(TestCase):

View File

@ -534,8 +534,10 @@ class NotificationUserSettingsApiTest(InvenTreeAPITestCase):
def test_setting(self): def test_setting(self):
"""Test the string name for NotificationUserSetting.""" """Test the string name for NotificationUserSetting."""
NotificationUserSetting.set_setting('NOTIFICATION_METHOD_MAIL', True, change_user=self.user, user=self.user)
test_setting = NotificationUserSetting.get_setting_object('NOTIFICATION_METHOD_MAIL', user=self.user) test_setting = NotificationUserSetting.get_setting_object('NOTIFICATION_METHOD_MAIL', user=self.user)
self.assertEqual(str(test_setting), 'NOTIFICATION_METHOD_MAIL (for testuser): ') self.assertEqual(str(test_setting), 'NOTIFICATION_METHOD_MAIL (for testuser): True')
class PluginSettingsApiTest(InvenTreeAPITestCase): class PluginSettingsApiTest(InvenTreeAPITestCase):