|
8 | 8 |
|
9 | 9 | from ..signals import device_registered |
10 | 10 |
|
11 | | -Config = load_model('config', 'Config') |
| 11 | +Device = load_model('config', 'Device') |
12 | 12 | Notification = load_model('openwisp_notifications', 'Notification') |
13 | 13 |
|
14 | 14 | notification_qs = Notification.objects.all() |
@@ -40,18 +40,28 @@ def test_device_registered(self): |
40 | 40 | # we simulate that "device_registered" signal is emitted |
41 | 41 | config = self._create_config() |
42 | 42 | device = config.device |
43 | | - device_registered.send(sender=Config, instance=config.device) |
44 | 43 |
|
45 | | - self.assertEqual(notification_qs.count(), 1) |
46 | | - notification = notification_qs.first() |
47 | | - self.assertEqual(notification.actor, device) |
48 | | - self.assertEqual(notification.target, device) |
49 | | - self.assertEqual(notification.type, 'device_registered') |
50 | | - self.assertEqual( |
51 | | - notification.email_subject, |
52 | | - f'[example.com] SUCCESS: "{device}" registered successfully', |
53 | | - ) |
54 | | - self.assertIn('registered successfully', notification.message) |
| 44 | + with self.subTest('is_new=True'): |
| 45 | + device_registered.send(sender=Device, instance=config.device, is_new=True) |
| 46 | + self.assertEqual(notification_qs.count(), 1) |
| 47 | + notification = notification_qs.first() |
| 48 | + self.assertEqual(notification.actor, device) |
| 49 | + self.assertEqual(notification.target, device) |
| 50 | + self.assertEqual(notification.type, 'device_registered') |
| 51 | + self.assertEqual( |
| 52 | + notification.email_subject, |
| 53 | + f'[example.com] SUCCESS: "{device}" registered successfully', |
| 54 | + ) |
| 55 | + self.assertIn('registered successfully', notification.message) |
| 56 | + self.assertIn('A new device', notification.message) |
| 57 | + |
| 58 | + Notification.objects.all().delete() |
| 59 | + |
| 60 | + with self.subTest('is_new=True'): |
| 61 | + device_registered.send(sender=Device, instance=config.device, is_new=False) |
| 62 | + self.assertEqual(notification_qs.count(), 1) |
| 63 | + notification = notification_qs.first() |
| 64 | + self.assertIn('The existing device', notification.message) |
55 | 65 |
|
56 | 66 | def test_default_notification_type_already_unregistered(self): |
57 | 67 | # Simulates if 'default notification type is already unregistered |
|
0 commit comments