-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement factories for DCIM DeviceRole
, DeviceType
, Manufacturer
, and Platform
#2594
Conversation
DeviceType
, Manufacturer
, and Platform
DeviceType
, Manufacturer
, and Platform
Can you add these to |
397a840
to
041bde7
Compare
DeviceType
, Manufacturer
, and Platform
DeviceRole
, DeviceType
, Manufacturer
, and Platform
- Added object creation to `generate_test_data
- `Manufacturer` will be named from a predefined list of known network vendors - `Platform` will only set `napalm_driver` if a `manufacturer` is set - `Platform` will be named based on the `manufacturer.name` - `Platform.napalm_driver` will be selected from a mapping of known driver names - `DeviceType` will be named based on the `manufacturer.name`
- Also tweaked the generation a bit for the other factories I've added.
- Updated new factories to have `description` be only a single sentence to simplify filter testing.
Still broken: ``` ====================================================================== FAIL: test_api_docs (nautobot.utilities.tests.test_api.APIDocsTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/jathan/sandbox/src/nautobot/nautobot/utilities/tests/test_api.py", line 146, in test_api_docs self.assertEqual(response.status_code, 200) AssertionError: 500 != 200 ```
1357d8c
to
dcc3663
Compare
Co-authored-by: Gary Snider <75227981+gsnider2195@users.noreply.github.com>
This wasn't a result of any changes you made but I noticed this test failing while I was running tests for your PR. Should we fix it in your branch since it's also related to factory changes? Seed:
>>> from nautobot.extras.filters import StatusFilterSet
>>> StatusFilterSet({'q': 'active'}, Status.objects.all()).qs
<StatusQuerySet [<Status: Active>, <Status: ComplexActive>]> |
As discussed I'll be fixing this |
# FIXME(jathan): This has to be replaced with# `get_deletable_object` and | ||
# `get_deletable_object_pks` but this is a workaround just so all of these objects are | ||
# deletable for now. | ||
DeviceType.objects.all().delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this be a problem as soon as we add Device factories, since Device.device_type
uses models.PROTECT
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Thus the comments! This is really just to get this merged in so we don't keep kicking the merge conflicts can down the road.
# factories. | ||
@override_settings(EXEMPT_VIEW_PERMISSIONS=["*"]) | ||
def test_bulk_edit_objects_with_constrained_permission(self): | ||
DeviceType.objects.exclude(model__startswith="Test Device Type").delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concern here and below. I totally understand this is gnarly code to work with but just want to make sure we're not setting ourselves up for more pain in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Agreed. Definitely have to replace all of this as we get closer to refactoring everything to use and expect factory-generated fixtures.
params = {"role": [device_roles[0].slug, device_roles[1].slug]} | ||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) | ||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), len(device_roles)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems weird to me that these changes are needed - as written it sure looks like we should always have exactly two results here and below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there were cases where it was sometimes resulting in a result of 1 so I made it where the roles being selected weren't adjacent and then relied on the count there instead of hard-coding the integer value expected. Meh.
Closes: #1334, Related: #2282
What's Changed
This implements
DeviceRoleFactory
,DeviceTypeFactory
,ManufacturerFactory
, andPlatformFactory
.Manufacturer.name = "Cisco"
would result inPlatform.name = "Cisco Platform 1"
andDeviceType.name = "Cisco DeviceType 1"
.TODO