Skip to content
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

Issue 60 #61

Merged
merged 4 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion openwrt_luci_rpc/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def get_hostname_from_dhcp(dhcp_result, mac):
if x['.type'] == 'host'
and 'mac' in x
and 'name' in x
and x['mac'].upper() == mac]
and ((isinstance(x['mac'], list)
and x['mac'][0].upper() == mac)
or (isinstance(x['mac'], str)
and x['mac'].upper() == mac))]

if host:
log.debug("DNS name lookup for mac {} "
Expand Down
53 changes: 53 additions & 0 deletions tests/test_openwrt_60.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Tests for `openwrt_luci_rpc` package."""


import unittest

from openwrt_luci_rpc import utilities


class TestOpenwrtLuciRPC(unittest.TestCase):
"""Tests for `openwrt_luci_rpc` package."""

def setUp(self):
"""Set up test fixtures, if any."""

def tearDown(self):
"""Tear down test fixtures, if any."""

def test_get_hostname_from_dhcp_mac_list_formating(self):
"""Test if lower case list of MAC match with Upper case."""

data = [{
".name": "cfg07ee1",
".type": "host",
"name": "imac-ethernet",
".index": 4,
"mac": ["c8:2a:10:4a:10:dd"],
"dns": "1",
".anonymous": True,
"ip": "192.168.1.124"
}]

data = utilities.get_hostname_from_dhcp(data, "C8:2A:10:4A:10:DD")
assert data is None

def test_get_hostname_from_dhcp_mac_string_formating(self):
"""Test if lower case string of MAC match with Upper case."""

data = [{
".name": "cfg07ee1",
".type": "host",
"name": "imac-ethernet",
".index": 4,
"mac": "c8:2a:10:4a:10:dd",
"dns": "1",
".anonymous": True,
"ip": "192.168.1.124"
}]

data = utilities.get_hostname_from_dhcp(data, "C8:2A:10:4A:10:DD")
assert data is None