Skip to content

Commit 20231fb

Browse files
author
Ritwick DSouza
committed
[raspbian] Added tests for radio settings
1 parent abb7eca commit 20231fb

1 file changed

Lines changed: 235 additions & 0 deletions

File tree

tests/raspbian/test_radios.py

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
import unittest
2+
3+
from netjsonconfig import Raspbian
4+
from netjsonconfig.utils import _TabsMixin
5+
6+
7+
class TestRadio(unittest.TestCase, _TabsMixin):
8+
9+
def test_radio_multi(self):
10+
o = Raspbian({
11+
"radios": [
12+
{
13+
"name": "radio0",
14+
"phy": "phy0",
15+
"driver": "mac80211",
16+
"protocol": "802.11n",
17+
"channel": 11,
18+
"channel_width": 20,
19+
"tx_power": 5,
20+
"country": "IT"
21+
},
22+
{
23+
"name": "radio1",
24+
"phy": "phy1",
25+
"driver": "mac80211",
26+
"protocol": "802.11n",
27+
"channel": 36,
28+
"channel_width": 20,
29+
"tx_power": 4,
30+
"country": "IT"
31+
}
32+
],
33+
"interfaces": [
34+
{
35+
"name": "wlan0",
36+
"type": "wireless",
37+
"wireless": {
38+
"radio": "radio0",
39+
"mode": "access_point",
40+
"ssid": "myWiFi"
41+
}
42+
}
43+
]
44+
})
45+
46+
expected = '''# config: /etc/hostapd/hostapd.conf
47+
interface=wlan0
48+
driver=nl80211
49+
hw_mode=g
50+
channel=11
51+
ieee80211n=1
52+
ssid=myWiFi
53+
54+
'''
55+
self.assertEqual(o.render(), expected)
56+
57+
def test_radio_n_24ghz(self):
58+
o = Raspbian({
59+
"radios": [
60+
{
61+
"name": "radio0",
62+
"phy": "phy0",
63+
"driver": "mac80211",
64+
"protocol": "802.11n",
65+
"channel": 3,
66+
"channel_width": 20,
67+
"tx_power": 3
68+
}
69+
],
70+
"interfaces": [
71+
{
72+
"name": "wlan0",
73+
"type": "wireless",
74+
"wireless": {
75+
"radio": "radio0",
76+
"mode": "access_point",
77+
"ssid": "myWiFi"
78+
}
79+
}
80+
]
81+
})
82+
83+
expected = '''# config: /etc/hostapd/hostapd.conf
84+
interface=wlan0
85+
driver=nl80211
86+
hw_mode=g
87+
channel=3
88+
ieee80211n=1
89+
ssid=myWiFi
90+
91+
'''
92+
self.assertEqual(o.render(), expected)
93+
94+
def test_radio_n_5ghz(self):
95+
o = Raspbian({
96+
"radios": [
97+
{
98+
"name": "radio0",
99+
"phy": "phy0",
100+
"driver": "mac80211",
101+
"protocol": "802.11n",
102+
"channel": 36,
103+
"channel_width": 20,
104+
"tx_power": 3
105+
}
106+
],
107+
"interfaces": [
108+
{
109+
"name": "wlan0",
110+
"type": "wireless",
111+
"wireless": {
112+
"radio": "radio0",
113+
"mode": "access_point",
114+
"ssid": "myWiFi"
115+
}
116+
}
117+
]
118+
})
119+
120+
expected = '''# config: /etc/hostapd/hostapd.conf
121+
interface=wlan0
122+
driver=nl80211
123+
hw_mode=a
124+
channel=36
125+
ieee80211n=1
126+
ssid=myWiFi
127+
128+
'''
129+
self.assertEqual(o.render(), expected)
130+
131+
def test_radio_ac(self):
132+
o = Raspbian({
133+
"radios": [
134+
{
135+
"name": "radio0",
136+
"phy": "phy0",
137+
"driver": "mac80211",
138+
"protocol": "802.11ac",
139+
"channel": 132,
140+
"channel_width": 80,
141+
}
142+
],
143+
"interfaces": [
144+
{
145+
"name": "wlan0",
146+
"type": "wireless",
147+
"wireless": {
148+
"radio": "radio0",
149+
"mode": "access_point",
150+
"ssid": "myWiFi"
151+
}
152+
}
153+
]
154+
})
155+
156+
expected = '''# config: /etc/hostapd/hostapd.conf
157+
interface=wlan0
158+
driver=nl80211
159+
hw_mode=a
160+
channel=132
161+
ieee80211ac=1
162+
ssid=myWiFi
163+
164+
'''
165+
self.assertEqual(o.render(), expected)
166+
167+
def test_radio_a(self):
168+
o = Raspbian({
169+
"radios": [
170+
{
171+
"name": "radio0",
172+
"phy": "phy0",
173+
"driver": "mac80211",
174+
"protocol": "802.11a",
175+
"channel": 0,
176+
"channel_width": 20
177+
}
178+
],
179+
"interfaces": [
180+
{
181+
"name": "wlan0",
182+
"type": "wireless",
183+
"wireless": {
184+
"radio": "radio0",
185+
"mode": "access_point",
186+
"ssid": "myWiFi"
187+
}
188+
}
189+
]
190+
})
191+
192+
expected = '''# config: /etc/hostapd/hostapd.conf
193+
interface=wlan0
194+
driver=nl80211
195+
hw_mode=a
196+
channel=0
197+
ssid=myWiFi
198+
199+
'''
200+
self.assertEqual(o.render(), expected)
201+
202+
def test_radio_g(self):
203+
o = Raspbian({
204+
"radios": [
205+
{
206+
"name": "radio0",
207+
"phy": "phy0",
208+
"driver": "mac80211",
209+
"protocol": "802.11g",
210+
"channel": 0,
211+
"channel_width": 20
212+
}
213+
],
214+
"interfaces": [
215+
{
216+
"name": "wlan0",
217+
"type": "wireless",
218+
"wireless": {
219+
"radio": "radio0",
220+
"mode": "access_point",
221+
"ssid": "myWiFi"
222+
}
223+
}
224+
]
225+
})
226+
227+
expected = '''# config: /etc/hostapd/hostapd.conf
228+
interface=wlan0
229+
driver=nl80211
230+
hw_mode=g
231+
channel=0
232+
ssid=myWiFi
233+
234+
'''
235+
self.assertEqual(o.render(), expected)

0 commit comments

Comments
 (0)