|
| 1 | +"""Unit tests for netbox_onboarding OnboardingDevice model. |
| 2 | +
|
| 3 | +(c) 2020 Network To Code |
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +Unless required by applicable law or agreed to in writing, software |
| 9 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +See the License for the specific language governing permissions and |
| 12 | +limitations under the License. |
| 13 | +""" |
| 14 | +from django.test import TestCase |
| 15 | + |
| 16 | +from dcim.models import Site, DeviceRole, DeviceType, Manufacturer, Device |
| 17 | + |
| 18 | +from netbox_onboarding.models import OnboardingTask |
| 19 | +from netbox_onboarding.models import OnboardingDevice |
| 20 | +from netbox_onboarding.choices import OnboardingStatusChoices |
| 21 | + |
| 22 | + |
| 23 | +class OnboardingDeviceModelTestCase(TestCase): |
| 24 | + """Test the Onboarding models.""" |
| 25 | + |
| 26 | + def setUp(self): |
| 27 | + """Setup objects for Onboarding Model tests.""" |
| 28 | + self.site = Site.objects.create(name="USWEST", slug="uswest") |
| 29 | + manufacturer = Manufacturer.objects.create(name="Juniper", slug="juniper") |
| 30 | + device_role = DeviceRole.objects.create(name="Firewall", slug="firewall") |
| 31 | + device_type = DeviceType.objects.create(slug="srx3600", model="SRX3600", manufacturer=manufacturer) |
| 32 | + |
| 33 | + self.device = Device.objects.create( |
| 34 | + device_type=device_type, name="device1", device_role=device_role, site=self.site |
| 35 | + ) |
| 36 | + |
| 37 | + self.succeeded_task1 = OnboardingTask.objects.create( |
| 38 | + ip_address="10.10.10.10", |
| 39 | + site=self.site, |
| 40 | + status=OnboardingStatusChoices.STATUS_SUCCEEDED, |
| 41 | + created_device=self.device, |
| 42 | + ) |
| 43 | + |
| 44 | + self.succeeded_task2 = OnboardingTask.objects.create( |
| 45 | + ip_address="10.10.10.10", |
| 46 | + site=self.site, |
| 47 | + status=OnboardingStatusChoices.STATUS_SUCCEEDED, |
| 48 | + created_device=self.device, |
| 49 | + ) |
| 50 | + |
| 51 | + self.failed_task1 = OnboardingTask.objects.create( |
| 52 | + ip_address="10.10.10.10", |
| 53 | + site=self.site, |
| 54 | + status=OnboardingStatusChoices.STATUS_FAILED, |
| 55 | + created_device=self.device, |
| 56 | + ) |
| 57 | + |
| 58 | + self.failed_task2 = OnboardingTask.objects.create( |
| 59 | + ip_address="10.10.10.10", |
| 60 | + site=self.site, |
| 61 | + status=OnboardingStatusChoices.STATUS_FAILED, |
| 62 | + created_device=self.device, |
| 63 | + ) |
| 64 | + |
| 65 | + def test_onboardingdevice_autocreated(self): |
| 66 | + """Verify that OnboardingDevice is auto-created.""" |
| 67 | + onboarding_device = OnboardingDevice.objects.get(device=self.device) |
| 68 | + self.assertEqual(self.device, onboarding_device.device) |
| 69 | + |
| 70 | + def test_last_check_attempt_date(self): |
| 71 | + """Verify OnboardingDevice last attempt.""" |
| 72 | + onboarding_device = OnboardingDevice.objects.get(device=self.device) |
| 73 | + self.assertEqual(onboarding_device.last_check_attempt_date, self.failed_task2.created_on) |
| 74 | + |
| 75 | + def test_last_check_successful_date(self): |
| 76 | + """Verify OnboardingDevice last success.""" |
| 77 | + onboarding_device = OnboardingDevice.objects.get(device=self.device) |
| 78 | + self.assertEqual(onboarding_device.last_check_successful_date, self.succeeded_task2.created_on) |
| 79 | + |
| 80 | + def test_status(self): |
| 81 | + """Verify OnboardingDevice status.""" |
| 82 | + onboarding_device = OnboardingDevice.objects.get(device=self.device) |
| 83 | + self.assertEqual(onboarding_device.status, self.failed_task2.status) |
| 84 | + |
| 85 | + def test_last_ot(self): |
| 86 | + """Verify OnboardingDevice last ot.""" |
| 87 | + onboarding_device = OnboardingDevice.objects.get(device=self.device) |
| 88 | + self.assertEqual(onboarding_device.last_ot, self.failed_task2) |
0 commit comments