|
5 | 5 | from unittest.mock import mock_open, patch |
6 | 6 |
|
7 | 7 | from django.contrib.auth.models import User |
8 | | -from django.test import TestCase, Client |
| 8 | +from django.test import TestCase, Client, override_settings |
9 | 9 | from django.urls import reverse |
10 | 10 | from django.utils import timezone, dateparse |
11 | 11 |
|
12 | 12 | from .models import ( |
13 | 13 | Card, Group, LogAccess, Role, TimeSlot, UserProfile, |
14 | | - LogCredits, Category, Device, LogDevice |
| 14 | + LogCredits, Category, Device, LogDevice, LogError |
15 | 15 | ) |
16 | 16 | from .arp import get_neighbours |
17 | 17 |
|
@@ -135,6 +135,21 @@ def test_open_door_by_nfc(self): |
135 | 135 | response = client.get(url, HTTP_AUTHORIZATION=auth) |
136 | 136 | self.assertEqual(response.status_code, 405) |
137 | 137 |
|
| 138 | + @override_settings(LABADMIN_NOTIFY_MQTT_ENTRANCE=True) |
| 139 | + def test_open_door_by_nfc_mqtt_error_log(self): |
| 140 | + client = Client() |
| 141 | + auth = 'Token {}'.format(self.device.token) |
| 142 | + url = reverse('open-door-nfc') |
| 143 | + data = { |
| 144 | + 'nfc_id': self.card.nfc_id |
| 145 | + } |
| 146 | + |
| 147 | + mqtt_errors = LogError.objects.filter(description__endswith='failed to publish to mqtt') |
| 148 | + self.assertFalse(mqtt_errors.exists()) |
| 149 | + response = client.post(url, data, format='json', HTTP_AUTHORIZATION=auth) |
| 150 | + mqtt_errors = LogError.objects.filter(description__endswith='failed to publish to mqtt') |
| 151 | + self.assertEqual(mqtt_errors.count(), 1) |
| 152 | + |
138 | 153 | def test_get_card_credits(self): |
139 | 154 |
|
140 | 155 | client = Client() |
|
0 commit comments