mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	refactor into new test file
This commit is contained in:
		
							
								
								
									
										45
									
								
								InvenTree/common/test_notifications.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								InvenTree/common/test_notifications.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | |||||||
|  | # -*- coding: utf-8 -*- | ||||||
|  | from __future__ import unicode_literals | ||||||
|  |  | ||||||
|  | from .notifications import NotificationMethod, SingleNotificationMethod, BulkNotificationMethod | ||||||
|  | from part.test_part import BaseNotificationIntegrationTest | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class NotificationTests(BaseNotificationIntegrationTest): | ||||||
|  |  | ||||||
|  |     def test_NotificationMethod(self): | ||||||
|  |         """ensure the implementation requirements are tested""" | ||||||
|  |  | ||||||
|  |         class FalseNotificationMethod(NotificationMethod): | ||||||
|  |             pass | ||||||
|  |  | ||||||
|  |         class AnotherFalseNotificationMethod(NotificationMethod): | ||||||
|  |             def send(self): | ||||||
|  |                 pass | ||||||
|  |  | ||||||
|  |         with self.assertRaises(NotImplementedError): | ||||||
|  |             FalseNotificationMethod('', '', '') | ||||||
|  |  | ||||||
|  |         with self.assertRaises(NotImplementedError): | ||||||
|  |             AnotherFalseNotificationMethod('', '', '') | ||||||
|  |  | ||||||
|  |     def test_SingleNotificationMethod(self): | ||||||
|  |         """ensure the implementation requirements are tested""" | ||||||
|  |  | ||||||
|  |         class WrongImplementation(SingleNotificationMethod): | ||||||
|  |             pass | ||||||
|  |  | ||||||
|  |         with self.assertRaises(NotImplementedError): | ||||||
|  |             self._notification_run() | ||||||
|  |  | ||||||
|  |     def test_BulkNotificationMethod(self): | ||||||
|  |         """ensure the implementation requirements are tested""" | ||||||
|  |  | ||||||
|  |         class WrongImplementation(BulkNotificationMethod): | ||||||
|  |             pass | ||||||
|  |  | ||||||
|  |         with self.assertRaises(NotImplementedError): | ||||||
|  |             self._notification_run() | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # A integration test for notifications is provided in test_part.PartNotificationTest | ||||||
| @@ -8,9 +8,6 @@ from django.contrib.auth import get_user_model | |||||||
|  |  | ||||||
| from .models import InvenTreeSetting | from .models import InvenTreeSetting | ||||||
| from .models import NotificationEntry | from .models import NotificationEntry | ||||||
| from .notifications import NotificationMethod, SingleNotificationMethod, BulkNotificationMethod |  | ||||||
|  |  | ||||||
| from part.test_part import BaseNotificationIntegrationTest |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class SettingsTest(TestCase): | class SettingsTest(TestCase): | ||||||
| @@ -111,43 +108,3 @@ class NotificationEntryTest(TestCase): | |||||||
|         self.assertFalse(NotificationEntry.check_recent('test.notification2', 1, delta)) |         self.assertFalse(NotificationEntry.check_recent('test.notification2', 1, delta)) | ||||||
|  |  | ||||||
|         self.assertTrue(NotificationEntry.check_recent('test.notification', 1, delta)) |         self.assertTrue(NotificationEntry.check_recent('test.notification', 1, delta)) | ||||||
|  |  | ||||||
|  |  | ||||||
| class NotificationTests(BaseNotificationIntegrationTest): |  | ||||||
|  |  | ||||||
|     def test_NotificationMethod(self): |  | ||||||
|         """ensure the implementation requirements are tested""" |  | ||||||
|  |  | ||||||
|         class FalseNotificationMethod(NotificationMethod): |  | ||||||
|             pass |  | ||||||
|  |  | ||||||
|         class AnotherFalseNotificationMethod(NotificationMethod): |  | ||||||
|             def send(self): |  | ||||||
|                 pass |  | ||||||
|  |  | ||||||
|         with self.assertRaises(NotImplementedError): |  | ||||||
|             FalseNotificationMethod('', '', '') |  | ||||||
|  |  | ||||||
|         with self.assertRaises(NotImplementedError): |  | ||||||
|             AnotherFalseNotificationMethod('', '', '') |  | ||||||
|  |  | ||||||
|     def test_SingleNotificationMethod(self): |  | ||||||
|         """ensure the implementation requirements are tested""" |  | ||||||
|  |  | ||||||
|         class WrongImplementation(SingleNotificationMethod): |  | ||||||
|             pass |  | ||||||
|  |  | ||||||
|         with self.assertRaises(NotImplementedError): |  | ||||||
|             self._notification_run() |  | ||||||
|  |  | ||||||
|     def test_BulkNotificationMethod(self): |  | ||||||
|         """ensure the implementation requirements are tested""" |  | ||||||
|  |  | ||||||
|         class WrongImplementation(BulkNotificationMethod): |  | ||||||
|             pass |  | ||||||
|  |  | ||||||
|         with self.assertRaises(NotImplementedError): |  | ||||||
|             self._notification_run() |  | ||||||
|  |  | ||||||
|  |  | ||||||
| # A integration test for notifications is provided in test_part.PartNotificationTest |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user