Skip to content

Commit

Permalink
Addressed PR comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio-Oliveira-Encora committed Mar 8, 2024
1 parent e84c6c7 commit ed9b14d
Showing 1 changed file with 34 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)
from django.contrib.auth import get_user_model
from ipam.models import ASN, RIR
from rest_framework import status
from users.models import Token
from utilities.testing import APITestCase
from virtualization.models import Cluster, ClusterType
Expand Down Expand Up @@ -124,10 +125,21 @@ def setUp(self):

self.url = "/api/plugins/diode/apply-change-set/"

def act(self, payload, status_code=status.HTTP_200_OK):

Check failure on line 128 in diode-netbox-plugin/netbox_diode_plugin/tests/test_apply_change_set.py

View workflow job for this annotation

GitHub Actions / tests (3.7)

Ruff (D102)

netbox_diode_plugin/tests/test_apply_change_set.py:128:9: D102 Missing docstring in public method

Check failure on line 128 in diode-netbox-plugin/netbox_diode_plugin/tests/test_apply_change_set.py

View workflow job for this annotation

GitHub Actions / tests (3.8)

Ruff (D102)

netbox_diode_plugin/tests/test_apply_change_set.py:128:9: D102 Missing docstring in public method

Check failure on line 128 in diode-netbox-plugin/netbox_diode_plugin/tests/test_apply_change_set.py

View workflow job for this annotation

GitHub Actions / tests (3.9)

Ruff (D102)

netbox_diode_plugin/tests/test_apply_change_set.py:128:9: D102 Missing docstring in public method

Check failure on line 128 in diode-netbox-plugin/netbox_diode_plugin/tests/test_apply_change_set.py

View workflow job for this annotation

GitHub Actions / tests (3.10)

Ruff (D102)

netbox_diode_plugin/tests/test_apply_change_set.py:128:9: D102 Missing docstring in public method

Check failure on line 128 in diode-netbox-plugin/netbox_diode_plugin/tests/test_apply_change_set.py

View workflow job for this annotation

GitHub Actions / tests (3.11)

Ruff (D102)

netbox_diode_plugin/tests/test_apply_change_set.py:128:9: D102 Missing docstring in public method

Check failure on line 128 in diode-netbox-plugin/netbox_diode_plugin/tests/test_apply_change_set.py

View workflow job for this annotation

GitHub Actions / tests (3.12)

Ruff (D102)

netbox_diode_plugin/tests/test_apply_change_set.py:128:9: D102 Missing docstring in public method
response = self.client.post(
self.url, data=payload, format="json", **self.user_header
)
self.assertEqual(response.status_code, status_code)
return response


class ApplyChangeSetTestCase(BaseApplyChangeSet):
"""ApplyChangeSet test cases."""

@staticmethod
def get_change_id(payload, index):

Check failure on line 140 in diode-netbox-plugin/netbox_diode_plugin/tests/test_apply_change_set.py

View workflow job for this annotation

GitHub Actions / tests (3.7)

Ruff (D102)

netbox_diode_plugin/tests/test_apply_change_set.py:140:9: D102 Missing docstring in public method

Check failure on line 140 in diode-netbox-plugin/netbox_diode_plugin/tests/test_apply_change_set.py

View workflow job for this annotation

GitHub Actions / tests (3.8)

Ruff (D102)

netbox_diode_plugin/tests/test_apply_change_set.py:140:9: D102 Missing docstring in public method

Check failure on line 140 in diode-netbox-plugin/netbox_diode_plugin/tests/test_apply_change_set.py

View workflow job for this annotation

GitHub Actions / tests (3.9)

Ruff (D102)

netbox_diode_plugin/tests/test_apply_change_set.py:140:9: D102 Missing docstring in public method

Check failure on line 140 in diode-netbox-plugin/netbox_diode_plugin/tests/test_apply_change_set.py

View workflow job for this annotation

GitHub Actions / tests (3.10)

Ruff (D102)

netbox_diode_plugin/tests/test_apply_change_set.py:140:9: D102 Missing docstring in public method

Check failure on line 140 in diode-netbox-plugin/netbox_diode_plugin/tests/test_apply_change_set.py

View workflow job for this annotation

GitHub Actions / tests (3.11)

Ruff (D102)

netbox_diode_plugin/tests/test_apply_change_set.py:140:9: D102 Missing docstring in public method

Check failure on line 140 in diode-netbox-plugin/netbox_diode_plugin/tests/test_apply_change_set.py

View workflow job for this annotation

GitHub Actions / tests (3.12)

Ruff (D102)

netbox_diode_plugin/tests/test_apply_change_set.py:140:9: D102 Missing docstring in public method
return payload.get("change_set")[index].get("change_id")

def test_change_type_create_return_200(self):
"""Test create change_type with successful."""
payload = {
Expand All @@ -153,12 +165,9 @@ def test_change_type_create_return_200(self):
],
}

response = self.client.post(
self.url, payload, format="json", **self.user_header
)
response = self.act(payload)

self.assertEqual(response.json().get("result"), "success")
self.assertEqual(response.status_code, 200)

def test_change_type_update_return_200(self):
"""Test update change_type with successful."""
Expand Down Expand Up @@ -191,7 +200,6 @@ def test_change_type_update_return_200(self):

site_updated = Site.objects.get(id=20)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.json().get("result"), "success")
self.assertEqual(site_updated.name, "Site A")

Expand Down Expand Up @@ -220,13 +228,10 @@ def test_change_type_create_with_error_return_400(self):
],
}

response = self.client.post(
self.url, payload, format="json", **self.user_header
)
response = self.act(payload, status_code=status.HTTP_400_BAD_REQUEST)

site_created = Site.objects.filter(name="Site A")

self.assertEqual(response.status_code, 400)
self.assertEqual(response.json().get("result"), "failed")
self.assertIn(
'Expected a list of items but got type "int".',
Expand Down Expand Up @@ -259,13 +264,10 @@ def test_change_type_update_with_error_return_400(self):
],
}

response = self.client.post(
self.url, payload, format="json", **self.user_header
)
response = self.act(payload, status_code=status.HTTP_400_BAD_REQUEST)

site_updated = Site.objects.get(id=20)

self.assertEqual(response.status_code, 400)
self.assertEqual(response.json().get("result"), "failed")
self.assertIn(
'Expected a list of items but got type "int".',
Expand Down Expand Up @@ -313,11 +315,8 @@ def test_change_type_create_with_multiples_objects_return_200(self):
],
}

response = self.client.post(
self.url, payload, format="json", **self.user_header
)
response = self.act(payload)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.json().get("result"), "success")

def test_change_type_update_with_multiples_objects_return_200(self):
Expand Down Expand Up @@ -360,14 +359,11 @@ def test_change_type_update_with_multiples_objects_return_200(self):
],
}

response = self.client.post(
self.url, payload, format="json", **self.user_header
)
response = self.act(payload)

site_updated = Site.objects.get(id=20)
device_updated = Device.objects.get(id=10)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.json().get("result"), "success")
self.assertEqual(site_updated.name, "Site A")
self.assertEqual(device_updated.name, "Test Device 3")
Expand Down Expand Up @@ -412,14 +408,11 @@ def test_change_type_create_and_update_with_error_in_one_object_return_400(self)
],
}

response = self.client.post(
self.url, payload, format="json", **self.user_header
)
response = self.act(payload, status_code=status.HTTP_400_BAD_REQUEST)

site_created = Site.objects.filter(name="Site Z")
device_created = Device.objects.filter(name="Test Device 4")

self.assertEqual(response.status_code, 400)
self.assertEqual(response.json().get("result"), "failed")
self.assertIn(
"Related object not found using the provided numeric ID",
Expand Down Expand Up @@ -483,14 +476,11 @@ def test_multiples_create_type_error_in_two_objects_return_400(self):
],
}

response = self.client.post(
self.url, payload, format="json", **self.user_header
)
response = self.act(payload, status_code=status.HTTP_400_BAD_REQUEST)

site_created = Site.objects.filter(name="Site Z")
device_created = Device.objects.filter(name="Test Device 4")

self.assertEqual(response.status_code, 400)
self.assertEqual(response.json().get("result"), "failed")
self.assertIn(
"Related object not found using the provided numeric ID",
Expand Down Expand Up @@ -534,7 +524,6 @@ def test_change_type_update_with_object_id_not_exist_return_400(self):

site_updated = Site.objects.get(id=20)

self.assertEqual(response.status_code, 400)
self.assertEqual(response.json()[0], "Object with id 30 does not exist")
self.assertEqual(site_updated.name, "Site 2")

Expand Down Expand Up @@ -563,11 +552,8 @@ def test_change_set_id_field_not_provided_return_400(self):
],
}

response = self.client.post(
self.url, payload, format="json", **self.user_header
)
response = self.act(payload, status_code=status.HTTP_400_BAD_REQUEST)

self.assertEqual(response.status_code, 400)
self.assertEqual(
response.json().get("errors")[0].get("change_set_id"),
"This field may not be null.",
Expand Down Expand Up @@ -600,11 +586,8 @@ def test_change_set_id_change_id_and_change_type_field_not_provided_return_400(
],
}

response = self.client.post(
self.url, payload, format="json", **self.user_header
)
response = self.act(payload, status_code=status.HTTP_400_BAD_REQUEST)

self.assertEqual(response.status_code, 400)
self.assertEqual(
response.json().get("errors")[0].get("change_set_id"),
"Must be a valid UUID.",
Expand All @@ -625,11 +608,8 @@ def test_change_set_id_field_and_change_set_not_provided_return_400(self):
"change_set": [],
}

response = self.client.post(
self.url, payload, format="json", **self.user_header
)
response = self.act(payload, status_code=status.HTTP_400_BAD_REQUEST)

self.assertEqual(response.status_code, 400)
self.assertEqual(
response.json().get("errors")[0].get("change_set_id"),
"Must be a valid UUID.",
Expand Down Expand Up @@ -681,11 +661,13 @@ def test_change_type_and_object_type_provided_return_400(
],
}

response = self.client.post(
self.url, payload, format="json", **self.user_header
)
response = self.act(payload, status_code=status.HTTP_400_BAD_REQUEST)

self.assertEqual(response.status_code, 400)
# First item of change_set
self.assertEqual(
response.json().get("errors")[0].get("change_id"),
self.get_change_id(payload, 0),
)
self.assertEqual(
response.json().get("errors")[0].get("change_type"),
"This field may not be null.",
Expand All @@ -694,6 +676,12 @@ def test_change_type_and_object_type_provided_return_400(
response.json().get("errors")[0].get("object_type"),
"This field may not be blank.",
)

# Second item of change_set
self.assertEqual(
response.json().get("errors")[1].get("change_id"),
self.get_change_id(payload, 1),
)
self.assertEqual(
response.json().get("errors")[1].get("change_type"),
"This field may not be blank.",
Expand Down

0 comments on commit ed9b14d

Please sign in to comment.