-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2896 from stveit/feature/mac-to-vendor-model
Add OUI model
- Loading branch information
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add model representing an Organizationally Unique Identifier (OUI) to identify vendors for mac addresses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.db import models | ||
|
||
from nav.models.fields import VarcharField | ||
|
||
|
||
class OUI(models.Model): | ||
"""Defines an OUI and the name of the vendor the OUI belongs to""" | ||
|
||
oui = models.CharField(max_length=17, primary_key=True) | ||
vendor = VarcharField() | ||
|
||
def __str__(self): | ||
return self.oui | ||
|
||
class Meta(object): | ||
db_table = 'oui' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE manage.oui ( | ||
oui MACADDR PRIMARY KEY, | ||
vendor VARCHAR NOT NULL, | ||
CHECK (oui=trunc(oui)) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
|
||
from django.db.utils import IntegrityError | ||
|
||
from nav.models.oui import OUI | ||
|
||
|
||
class TestOUI: | ||
def test_string_representation_should_match_oui(self, valid_oui): | ||
assert str(valid_oui) == valid_oui.oui | ||
|
||
def test_save_should_raise_error_if_last_3_bytes_are_not_zero(self, invalid_oui): | ||
with pytest.raises(IntegrityError): | ||
invalid_oui.save() | ||
|
||
def test_save_should_allow_oui_if_last_3_bytes_are_zero(self, valid_oui): | ||
valid_oui.save() | ||
|
||
|
||
@pytest.fixture() | ||
def valid_oui(): | ||
oui = "aa:bb:cc:00:00:00" | ||
instance = OUI(oui=oui, vendor="myvendor") | ||
yield instance | ||
instance.delete() | ||
|
||
|
||
@pytest.fixture() | ||
def invalid_oui(): | ||
oui = "aa:bb:cc:dd:ee:ff" | ||
instance = OUI(oui=oui, vendor="myvendor") | ||
yield instance | ||
instance.delete() |