def test_list_all_usable_architectures_returns_no_duplicates(self): arch = factory.make_name('arch') subarch = factory.make_name('subarch') self.make_usable_boot_resource(arch=arch, subarch=subarch) self.make_usable_boot_resource(arch=arch, subarch=subarch) self.assertEqual(["%s/%s" % (arch, subarch)], list_all_usable_architectures())
def test_list_all_usable_architectures_combines(self): arches = [(factory.make_name('arch'), factory.make_name('subarch')) for _ in range(3)] for arch, subarch in arches: self.make_usable_boot_resource(arch=arch, subarch=subarch) expected = ["%s/%s" % (arch, subarch) for arch, subarch in arches] self.assertItemsEqual(expected, list_all_usable_architectures())
def test_list_all_usable_architectures_sorts_output(self): arches = [(factory.make_name('arch'), factory.make_name('subarch')) for _ in range(3)] for arch, subarch in arches: self.make_usable_boot_resource(arch=arch, subarch=subarch) expected = ["%s/%s" % (arch, subarch) for arch, subarch in arches] self.assertEqual(sorted(expected), list_all_usable_architectures())
def clean_arch(self): """Turn `arch` parameter into a list of architecture names. Even though `arch` is a single-value field, it turns into a list during cleaning. The architecture parameter may be a wildcard. """ # Import list_all_usable_architectures as part of its module, not # directly, so that patch_usable_architectures can easily patch it # for testing purposes. usable_architectures = maasserver_forms.list_all_usable_architectures() architecture_wildcards = get_architecture_wildcards( usable_architectures) value = self.cleaned_data[self.get_field_name("arch")] if value: if value in usable_architectures: # Full 'arch/subarch' specified directly. return [value] elif value in architecture_wildcards: # Try to expand 'arch' to all available 'arch/subarch' # matches. return architecture_wildcards[value] set_form_error( self, self.get_field_name("arch"), "Architecture not recognised.", ) return None