Exemplo n.º 1
0
 def test_to_dict_with_selections_returns_dict_without_selections(self):
     boot_source = factory.make_BootSource(
         keyring_data=b"123445", keyring_filename=""
     )
     factory.make_BootSourceSelection(boot_source=boot_source)
     boot_source_dict = boot_source.to_dict_without_selections()
     self.assertEqual([], boot_source_dict["selections"])
 def test_GET_returns_boot_source(self):
     self.become_admin()
     boot_source_selection = factory.make_BootSourceSelection()
     response = self.client.get(
         get_boot_source_selection_uri(boot_source_selection))
     self.assertEqual(http.client.OK, response.status_code)
     returned_boot_source_selection = json_load_bytes(response.content)
     boot_source = boot_source_selection.boot_source
     # The returned object contains a 'resource_uri' field.
     self.assertEqual(
         reverse(
             "boot_source_selection_handler",
             args=[boot_source.id, boot_source_selection.id],
         ),
         returned_boot_source_selection["resource_uri"],
     )
     # The other fields are the boot source selection's fields.
     del returned_boot_source_selection["resource_uri"]
     # All the fields are present.
     self.assertItemsEqual(
         DISPLAYED_BOOTSOURCESELECTION_FIELDS,
         returned_boot_source_selection.keys(),
     )
     self.assertThat(
         boot_source_selection,
         MatchesStructure.byEquality(**returned_boot_source_selection),
     )
Exemplo n.º 3
0
 def test_to_dict_with_selections_returns_bootloaders(self):
     keyring_data = b"Some Keyring Data"
     boot_source = factory.make_BootSource(
         keyring_data=keyring_data, keyring_filename=""
     )
     boot_source_selection = factory.make_BootSourceSelection(
         boot_source=boot_source
     )
     bootloaders = []
     for arch in boot_source_selection.arches:
         bootloader_type = factory.make_name("bootloader-type")
         factory.make_BootSourceCache(
             boot_source=boot_source,
             bootloader_type=bootloader_type,
             release=bootloader_type,
             arch=arch,
         )
         bootloaders.append(bootloader_type)
     self.assertItemsEqual(
         [
             selection["release"]
             for selection in boot_source.to_dict()["selections"]
             if "bootloader-type" in selection["release"]
         ],
         bootloaders,
     )
Exemplo n.º 4
0
 def test_PUT_updates_boot_source_selection(self):
     self.become_admin()
     boot_source_selection = factory.make_BootSourceSelection()
     new_os = factory.make_name('os')
     new_release = factory.make_name('release')
     boot_source_caches = factory.make_many_BootSourceCaches(
         2,
         boot_source=boot_source_selection.boot_source,
         os=new_os,
         release=new_release)
     new_values = {
         'os':
         new_os,
         'release':
         new_release,
         'arches': [boot_source_caches[0].arch, boot_source_caches[1].arch],
         'subarches':
         [boot_source_caches[0].subarch, boot_source_caches[1].subarch],
         'labels': [boot_source_caches[0].label],
     }
     response = self.client.put(
         get_boot_source_selection_uri(boot_source_selection), new_values)
     self.assertEqual(http.client.OK, response.status_code,
                      response.content)
     boot_source_selection = reload_object(boot_source_selection)
     self.assertAttributes(boot_source_selection, new_values)
Exemplo n.º 5
0
 def test_DELETE_deletes_boot_source_selection(self):
     self.become_admin()
     boot_source_selection = factory.make_BootSourceSelection()
     response = self.client.delete(
         get_boot_source_selection_uri(boot_source_selection))
     self.assertEqual(http.client.NO_CONTENT, response.status_code)
     self.assertIsNone(reload_object(boot_source_selection))
 def test_PUT_requires_admin(self):
     boot_source_selection = factory.make_BootSourceSelection()
     new_values = {"release": factory.make_name("release")}
     response = self.client.put(
         get_boot_source_selection_uri(boot_source_selection), new_values
     )
     self.assertEqual(http.client.FORBIDDEN, response.status_code)
Exemplo n.º 7
0
 def test_GET_returns_boot_source_selection_list(self):
     self.become_admin()
     boot_source = factory.make_BootSource()
     selections = [
         factory.make_BootSourceSelection(boot_source=boot_source)
         for _ in range(3)
     ]
     # Create boot source selections in another boot source.
     [factory.make_BootSourceSelection() for _ in range(3)]
     response = self.client.get(
         reverse('boot_source_selections_handler', args=[boot_source.id]))
     self.assertEqual(http.client.OK, response.status_code,
                      response.content)
     parsed_result = json_load_bytes(response.content)
     self.assertItemsEqual(
         [selection.id for selection in selections],
         [selection.get('id') for selection in parsed_result])
Exemplo n.º 8
0
 def test_to_dict_returns_dict(self):
     boot_source = factory.make_BootSource(keyring_data=b"123445",
                                           keyring_filename="")
     boot_source_selection = factory.make_BootSourceSelection(
         boot_source=boot_source)
     boot_source_dict = boot_source.to_dict()
     self.assertEqual(boot_source.url, boot_source_dict["url"])
     self.assertEqual([boot_source_selection.to_dict()],
                      boot_source_dict["selections"])
Exemplo n.º 9
0
 def test_to_dict_returns_dict(self):
     boot_source_selection = factory.make_BootSourceSelection()
     expected = {
         "os": boot_source_selection.os,
         "release": boot_source_selection.release,
         "arches": boot_source_selection.arches,
         "subarches": boot_source_selection.subarches,
         "labels": boot_source_selection.labels,
     }
     self.assertEqual(expected, boot_source_selection.to_dict())
Exemplo n.º 10
0
 def test_edits_boot_source_selection_object(self):
     boot_source_selection = factory.make_BootSourceSelection()
     boot_source = boot_source_selection.boot_source
     params = self.make_valid_source_selection_params(boot_source)
     form = BootSourceSelectionForm(instance=boot_source_selection,
                                    data=params)
     self.assertTrue(form.is_valid(), form._errors)
     form.save()
     boot_source_selection = reload_object(boot_source_selection)
     self.assertAttributes(boot_source_selection, params)
Exemplo n.º 11
0
 def test_cannt_delete_commissioning_os(self):
     boot_source_selection = factory.make_BootSourceSelection()
     commissioning_osystem, _ = Config.objects.get_or_create(
         name="commissioning_osystem")
     commissioning_series, _ = Config.objects.get_or_create(
         name="commissioning_distro_series")
     commissioning_osystem.value = boot_source_selection.os
     commissioning_osystem.save()
     commissioning_series.value = boot_source_selection.release
     commissioning_series.save()
     self.assertRaises(ValidationError, boot_source_selection.delete)
Exemplo n.º 12
0
 def test_deleting_boot_source_deletes_its_selections(self):
     # BootSource deletion cascade-deletes related
     # BootSourceSelections. This is implicit in Django but it's
     # worth adding a test for it all the same.
     boot_source = factory.make_BootSource()
     boot_source_selection = factory.make_BootSourceSelection(
         boot_source=boot_source)
     boot_source.delete()
     self.assertNotIn(
         boot_source_selection.id,
         [selection.id for selection in BootSourceSelection.objects.all()])
Exemplo n.º 13
0
 def test_to_dict_with_selections_returns_bootloaders(self):
     keyring_data = b'Some Keyring Data'
     boot_source = factory.make_BootSource(keyring_data=keyring_data,
                                           keyring_filename='')
     boot_source_selection = factory.make_BootSourceSelection(
         boot_source=boot_source)
     bootloaders = []
     for arch in boot_source_selection.arches:
         bootloader_type = factory.make_name('bootloader-type')
         factory.make_BootSourceCache(boot_source=boot_source,
                                      bootloader_type=bootloader_type,
                                      release=bootloader_type,
                                      arch=arch)
         bootloaders.append(bootloader_type)
     self.assertItemsEqual([
         selection['release']
         for selection in boot_source.to_dict()['selections']
         if 'bootloader-type' in selection['release']
     ], bootloaders)
Exemplo n.º 14
0
 def test_DELETE_requires_admin(self):
     boot_source_selection = factory.make_BootSourceSelection()
     response = self.client.delete(
         get_boot_source_selection_uri(boot_source_selection))
     self.assertEqual(http.client.FORBIDDEN, response.status_code)