def test_list(self): user = factory.make_User() handler = FabricHandler(user, {}, None) factory.make_Fabric() expected_fabrics = [ self.dehydrate_fabric(fabric) for fabric in Fabric.objects.all() ] self.assertItemsEqual(expected_fabrics, handler.list({}))
def test_get_default_vlan_is_first(self): user = factory.make_User() handler = FabricHandler(user, {}, None) fabric = factory.make_Fabric() default_vlan = fabric.get_default_vlan() tagged_vlan_ids = [ factory.make_VLAN(fabric=fabric).id for _ in range(3) ] observed = handler.get({"id": fabric.id}) self.assertEqual([default_vlan.id] + tagged_vlan_ids, observed["vlan_ids"])
def test_get(self): user = factory.make_User() handler = FabricHandler(user, {}, None) fabric = factory.make_Fabric() vlan = fabric.get_default_vlan() for _ in range(3): node = factory.make_Node(interface=True) interface = node.get_boot_interface() interface.vlan = vlan interface.save() self.assertEqual(self.dehydrate_fabric(fabric), handler.get({"id": fabric.id}))
def test_list_constant_queries(self): user = factory.make_User() handler = FabricHandler(user, {}, None) for _ in range(10): fabric = factory.make_Fabric() vlan = fabric.get_default_vlan() for _ in range(3): node = factory.make_Node(interface=True) interface = node.get_boot_interface() interface.vlan = vlan interface.save() queries_one, _ = count_queries(handler.list, {"limit": 1}) queries_multiple, _ = count_queries(handler.list, {}) self.assertEqual(queries_one, queries_multiple)