Skip to content

Commit

Permalink
Refactor to NetworkNumberAssignment
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Dec 22, 2023
1 parent ee09c31 commit 822ae67
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/meshapi/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def has_permission(self, request, view):
return True


class NewNodePermissions(permissions.BasePermission):
class NetworkNumberAssignmentPermissions(permissions.BasePermission):
def has_permission(self, request, view):
if not (request.user.is_superuser or is_admin(request.user) or is_installer(request.user)):
raise PermissionDenied(perm_denied_generic_msg)
Expand Down
10 changes: 5 additions & 5 deletions src/meshapi/tests/test_nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setUp(self):

def test_nn_valid_building_id(self):
response = self.admin_c.post(
"/api/v1/new-node/", {"meshapi_building_id": self.building_id}, content_type="application/json"
"/api/v1/nn-assign/", {"meshapi_building_id": self.building_id}, content_type="application/json"
)

code = 200
Expand All @@ -46,7 +46,7 @@ def test_nn_valid_building_id(self):

def test_nn_invalid_building_id(self):
response = self.admin_c.post(
"/api/v1/new-node/", {"meshapi_building_id": 69420}, content_type="application/json"
"/api/v1/nn-assign/", {"meshapi_building_id": 69420}, content_type="application/json"
)

code = 404
Expand All @@ -58,7 +58,7 @@ def test_nn_invalid_building_id(self):

def test_nn_bad_request(self):
response = self.admin_c.post(
"/api/v1/new-node/", {"meshapi_building_id": "chom"}, content_type="application/json"
"/api/v1/nn-assign/", {"meshapi_building_id": "chom"}, content_type="application/json"
)

code = 404
Expand All @@ -68,7 +68,7 @@ def test_nn_bad_request(self):
f"status code incorrect for test_nn_invalid_building_id. Should be {code}, but got {response.status_code}",
)

response = self.admin_c.post("/api/v1/new-node/", "Tell me your secrets >:)", content_type="application/json")
response = self.admin_c.post("/api/v1/nn-assign/", "Tell me your secrets >:)", content_type="application/json")

code = 400
self.assertEqual(
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_nn_search_for_new_number(self):

for b_id, nn in [(self.b2_bid, 111), (self.b3_bid, 112), (self.b4_bid, 130)]:
response = self.admin_c.post(
"/api/v1/new-node/", {"meshapi_building_id": b_id}, content_type="application/json"
"/api/v1/nn-assign/", {"meshapi_building_id": b_id}, content_type="application/json"
)

code = 200
Expand Down
2 changes: 1 addition & 1 deletion src/meshapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
path("requests/", views.RequestList.as_view(), name="meshapi-v1-request-list"),
path("requests/<int:pk>/", views.RequestDetail.as_view(), name="meshapi-v1-request-detail"),
path("join/", views.join_form, name="meshapi-v1-join"),
path("new-node/", views.new_node, name="meshapi-v1-new-node"),
path("nn-assign/", views.network_number_assignment, name="meshapi-v1-nn-assign"),
]

urlpatterns = format_suffix_patterns(urlpatterns)
10 changes: 5 additions & 5 deletions src/meshapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
MemberRetrieveUpdateDestroyPermissions,
InstallListCreatePermissions,
InstallRetrieveUpdateDestroyPermissions,
NewNodePermissions,
NetworkNumberAssignmentPermissions,
RequestListCreatePermissions,
RequestRetrieveUpdateDestroyPermissions,
)
Expand Down Expand Up @@ -319,13 +319,13 @@ def join_form(request):


@dataclass
class NewNodeRequest:
class NetworkNumberAssignmentRequest:
meshapi_building_id: int


@api_view(["POST"])
@permission_classes([NewNodePermissions])
def new_node(request):
@permission_classes([NetworkNumberAssignmentPermissions])
def network_number_assignment(request):
"""
Takes in an existing building ID (not an NYC BIN, one of ours), and assigns
it a network number, deduping using the other buildings in our database.
Expand All @@ -334,7 +334,7 @@ def new_node(request):

try:
request_json = json.loads(request.body)
r = NewNodeRequest(**request_json)
r = NetworkNumberAssignmentRequest(**request_json)
except (TypeError, JSONDecodeError) as e:
print(f"NN Request failed. Could not decode request: {e}")
return Response({"Got incomplete request"}, status=status.HTTP_400_BAD_REQUEST)
Expand Down

0 comments on commit 822ae67

Please sign in to comment.