1393
1397
self.assertItemsEqual(
1394
1398
[existing_id], extract_system_ids(parsed_result))
1400
def test_GET_list_with_macs_returns_matching_nodes(self):
1401
# The "list" operation takes optional "mac_address" parameters. Only
1402
# nodes with matching MAC addresses will be returned.
1403
macs = [factory.make_mac_address() for counter in range(3)]
1404
matching_mac = macs[0].mac_address
1405
matching_system_id = macs[0].node.system_id
1406
response = self.client.get(self.get_uri('nodes/'), {
1408
'mac_address': [matching_mac],
1410
parsed_result = json.loads(response.content)
1411
self.assertItemsEqual(
1412
[matching_system_id], extract_system_ids(parsed_result))
1396
1414
def test_GET_list_allocated_returns_only_allocated_with_user_token(self):
1397
1415
# If the user's allocated nodes have different session tokens,
1398
1416
# list_allocated should only return the nodes that have the
2227
2245
'arch': "armhf",
2228
2246
'subarch': "armadaxp",
2229
'mac': "AA:BB:CC:DD:EE:FF",
2247
'mac': factory.make_mac_address().mac_address,
2230
2248
'menutitle': "menutitle",
2231
2249
'kernelimage': "/my/kernel",
2232
2250
'append': "append",
2276
2294
self.assertEqual(expected, observed)
2296
def test_compose_enlistment_preseed_url_links_to_enlistment_preseed(self):
2297
response = self.client.get(api.compose_enlistment_preseed_url())
2299
(httplib.OK, get_enlist_preseed()),
2300
(response.status_code, response.content))
2302
def test_compose_preseed_url_links_to_preseed_for_node(self):
2303
node = factory.make_node()
2304
response = self.client.get(api.compose_preseed_url(node))
2306
(httplib.OK, get_preseed(node)),
2307
(response.status_code, response.content))
2309
def test_compose_preseed_kernel_opt_returns_option_for_known_node(self):
2310
mac = factory.make_mac_address()
2312
"auto url=%s" % api.compose_preseed_url(mac.node),
2313
api.compose_preseed_kernel_opt(mac.mac_address))
2315
def test_compose_preseed_kernel_opt_returns_option_for_unknown_node(self):
2317
"auto url=%s" % api.compose_enlistment_preseed_url(),
2318
api.compose_preseed_kernel_opt(factory.getRandomMACAddress()))
2320
def test_pxe_config_appends_enlistment_preseed_url_for_unknown_node(self):
2321
params = self.get_params()
2322
params['mac'] = factory.getRandomMACAddress()
2323
response = self.client.get(reverse('pxeconfig'), params)
2324
self.assertIn(api.compose_enlistment_preseed_url(), response.content)
2326
def test_pxe_config_appends_preseed_url_for_known_node(self):
2327
params = self.get_params()
2328
node = MACAddress.objects.get(mac_address=params['mac']).node
2329
response = self.client.get(reverse('pxeconfig'), params)
2330
self.assertIn(api.compose_preseed_url(node), response.content)
2279
2333
class TestNodeGroupsAPI(APITestCase):