-
Notifications
You must be signed in to change notification settings - Fork 41
Add vendor lookup endpoint #3354
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
base: master
Are you sure you want to change the base?
Changes from all commits
a34ad52
67344b4
de2ae4e
44e9fd0
40038be
da95afd
f7f50ca
91e2418
fafcba0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add endpoint for looking up vendor of MAC address |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
from nav.models.event import AlertHistory | ||
from nav.models.fields import INFINITY | ||
from nav.web.api.v1.views import get_endpoints | ||
from nav.models.oui import OUI | ||
|
||
|
||
ENDPOINTS = {name: force_str(url) for name, url in get_endpoints().items()} | ||
|
@@ -346,6 +347,100 @@ def test_interface_with_last_used_should_be_listable( | |
assert response.status_code == 200 | ||
|
||
|
||
class TestVendorLookupGet: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The lines
feel like something we can set up here for the whole class instead of repeating it in every test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it so it now uses a fixture |
||
def test_if_vendor_is_found_it_should_include_vendor_in_response( | ||
self, db, api_client, vendor_endpoint, oui | ||
): | ||
test_mac = 'aa:bb:cc:dd:ee:ff' | ||
response = api_client.get(f"{ENDPOINTS[vendor_endpoint]}?mac={test_mac}") | ||
assert response.status_code == 200 | ||
assert response.data[test_mac] == oui.vendor | ||
|
||
def test_should_always_return_mac_with_correct_format( | ||
self, db, api_client, vendor_endpoint, oui | ||
): | ||
test_mac = 'AA-BB-CC-DD-EE-FF' | ||
response = api_client.get(f"{ENDPOINTS[vendor_endpoint]}?mac={test_mac}") | ||
assert response.status_code == 200 | ||
assert response.data['aa:bb:cc:dd:ee:ff'] == oui.vendor | ||
|
||
def test_if_vendor_is_not_found_it_should_return_empty_dict( | ||
self, db, api_client, vendor_endpoint | ||
): | ||
test_mac = 'aa:bb:cc:dd:ee:ff' | ||
response = api_client.get(f"{ENDPOINTS[vendor_endpoint]}?mac={test_mac}") | ||
assert response.status_code == 200 | ||
assert response.data == {} | ||
|
||
def test_if_mac_is_invalid_it_should_return_400( | ||
self, db, api_client, vendor_endpoint | ||
): | ||
test_mac = 'invalidmac' | ||
response = api_client.get(f"{ENDPOINTS[vendor_endpoint]}?mac={test_mac}") | ||
assert response.status_code == 400 | ||
|
||
def test_if_mac_is_not_provided_it_should_return_empty_dict( | ||
self, db, api_client, vendor_endpoint | ||
): | ||
response = api_client.get(ENDPOINTS[vendor_endpoint]) | ||
assert response.status_code == 200 | ||
assert response.data == {} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A vendor-endpoint specific fixture would do, I guess :) |
||
class TestVendorLookupPost: | ||
def test_if_vendor_is_found_it_should_include_vendor_in_response( | ||
self, db, api_client, vendor_endpoint, oui | ||
): | ||
test_mac = 'aa:bb:cc:dd:ee:ff' | ||
response = create(api_client, vendor_endpoint, [test_mac]) | ||
assert response.status_code == 200 | ||
assert response.data[test_mac] == oui.vendor | ||
|
||
def test_should_always_return_macs_with_correct_format( | ||
self, db, api_client, vendor_endpoint, oui | ||
): | ||
test_mac = 'AA-BB-CC-DD-EE-FF' | ||
response = create(api_client, vendor_endpoint, [test_mac]) | ||
assert response.status_code == 200 | ||
assert response.data['aa:bb:cc:dd:ee:ff'] == oui.vendor | ||
|
||
def test_if_vendor_is_not_found_it_should_be_omitted_from_response( | ||
self, db, api_client, vendor_endpoint, oui | ||
): | ||
test_mac = '11:22:33:44:55:66' | ||
response = create(api_client, vendor_endpoint, [test_mac]) | ||
assert response.status_code == 200 | ||
assert test_mac not in response.data | ||
|
||
def test_if_empty_list_is_provided_it_should_return_empty_dict( | ||
self, db, api_client, vendor_endpoint | ||
): | ||
response = create(api_client, vendor_endpoint, []) | ||
assert response.status_code == 200 | ||
assert response.data == {} | ||
|
||
def test_if_mac_is_invalid_it_should_return_400( | ||
self, db, api_client, vendor_endpoint | ||
): | ||
response = create(api_client, vendor_endpoint, ["invalidmac"]) | ||
assert response.status_code == 400 | ||
|
||
|
||
@pytest.fixture() | ||
def oui(db): | ||
oui = OUI(oui='aa:bb:cc:00:00:00', vendor='myvendor') | ||
oui.save() | ||
yield oui | ||
oui.delete() | ||
|
||
|
||
@pytest.fixture() | ||
def vendor_endpoint(db, token): | ||
endpoint = 'vendor' | ||
create_token_endpoint(token, endpoint) | ||
return endpoint | ||
|
||
|
||
# Helpers | ||
|
||
|
||
|
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.
My DRF-fu is rusty (as mentioned in another PR review today). I assume the primary reason the url pattern is added explicitly, rather than through DRF's router-thingy is that this view isn't actually a model view with built-in CRUD-magic?
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, using the router stuff did not seem to work very well with
APIView