Esempio n. 1
0
 def test_from_systems_stream_invalid_missing_model(self):
     raw = json.dumps({
         "systems": [
             {
                 "label":
                 "1234",
                 "brand": {
                     "id": "brand-id",
                     "username": "******",
                     "display-name": "this is my brand",
                     "validation": "verified",
                 },
                 "actions": [
                     {
                         "title": "reinstall",
                         "mode": "install"
                     },
                     {
                         "title": "recover",
                         "mode": "recover"
                     },
                 ]
             },
         ]
     })
     with self.assertRaises(jsonschema.ValidationError):
         RecoverySystemsModel.from_systems_stream(StringIO(raw))
Esempio n. 2
0
 def test_from_systems_stream_happy(self):
     raw = json.dumps(self.reference)
     systems = RecoverySystemsModel.from_systems_stream(StringIO(raw))
     exp = RecoverySystemsModel([
         RecoverySystem(current=True,
                        label="1234",
                        model=SystemModel(
                            model="core20-amd64",
                            brand_id="brand-id",
                            display_name="Core 20 AMD64 system"),
                        brand=Brand(ID="brand-id",
                                    username="******",
                                    display_name="this is my brand",
                                    validation="verified"),
                        actions=[
                            SystemAction(title="reinstall", mode="install"),
                            SystemAction(title="recover", mode="recover")
                        ]),
         RecoverySystem(
             current=False,
             label="other",
             model=SystemModel(model="my-brand-box",
                               brand_id="other-brand-id",
                               display_name="Funky box"),
             brand=Brand(ID="other-brand-id",
                         username="******",
                         display_name="my brand",
                         validation="unproven"),
             actions=[SystemAction(title="reinstall", mode="install")]),
     ])
     self.assertEqual(systems.systems, exp.systems)
     self.assertEqual(systems.current, exp.systems[0])
Esempio n. 3
0
 def test_from_systems_stream_invalid_missing_brand(self):
     raw = json.dumps({
         "systems": [
             {
                 "label":
                 "1234",
                 "model": {
                     "model": "core20-amd64",
                     "brand-id": "brand-id",
                     "display-name": "Core 20 AMD64 system",
                 },
                 "actions": [
                     {
                         "title": "reinstall",
                         "mode": "install"
                     },
                     {
                         "title": "recover",
                         "mode": "recover"
                     },
                 ]
             },
         ]
     })
     with self.assertRaises(jsonschema.ValidationError):
         RecoverySystemsModel.from_systems_stream(StringIO(raw))
Esempio n. 4
0
    def test_to_response_stream(self):
        raw = json.dumps(self.reference)
        model = RecoverySystemsModel.from_systems_stream(StringIO(raw))

        model.select(model.systems[1], model.systems[1].actions[0])

        stream = StringIO()
        RecoverySystemsModel.to_response_stream(model.selection, stream)
        fromjson = json.loads(stream.getvalue())
        self.assertEqual(
            fromjson, {
                "label": "other",
                "action": {
                    "mode": "install",
                    "title": "reinstall",
                },
            })
Esempio n. 5
0
 def test_selection(self):
     raw = json.dumps(self.reference)
     model = RecoverySystemsModel.from_systems_stream(StringIO(raw))
     model.select(model.systems[1], model.systems[1].actions[0])
     self.assertEqual(
         model.selection,
         SelectedSystemAction(system=model.systems[1],
                              action=model.systems[1].actions[0]))
     model.unselect()
     self.assertIsNone(model.selection)
Esempio n. 6
0
    def __init__(self, opts, chooser_input, chooser_output):
        """Takes the options and raw input/output streams for communicating with the
        chooser parent process.
        """
        self._chooser_output = chooser_output
        # make_model is used by super()'s constructor, but we need to use the
        # instance data
        self.make_model = lambda: RecoverySystemsModel.from_systems_stream(
            chooser_input)

        super().__init__(opts)
        self.prober = Prober(opts.machine_config, self.debug_flags)
Esempio n. 7
0
 def test_from_systems_stream_valid_no_actions(self):
     raw = json.dumps({
         "systems": [
             {
                 "label": "1234",
                 "model": {
                     "model": "core20-amd64",
                     "brand-id": "brand-id",
                     "display-name": "Core 20 AMD64 system",
                 },
                 "brand": {
                     "id": "brand-id",
                     "username": "******",
                     "display-name": "this is my brand",
                     "validation": "verified",
                 },
                 "actions": [],
             },
         ]
     })
     RecoverySystemsModel.from_systems_stream(StringIO(raw))
Esempio n. 8
0
    def test_only_one_and_current(self, cv, ccsv):
        model = RecoverySystemsModel.from_systems([model2_current])
        app = make_app(model=model)
        c = RecoveryChooserController(app)
        # both views are constructed
        ccsv.assert_called_with(c, c.model.current, has_more=False)
        cv.assert_called_with(c, c.model.systems)

        v = c.make_ui()
        self.assertEqual(v, 'current')
        # going back does nothing
        c.back()
        c.ui.set_body.not_called()
Esempio n. 9
0
    def test_all_systems_first_no_current(self, cv, ccsv):
        model = RecoverySystemsModel.from_systems([model1_non_current])
        app = make_app(model=model)
        c = RecoveryChooserController(app)

        # sanity
        self.assertIsNone(c.model.current)

        # we get the all-systems view now
        cv.assert_called()
        # current system view is not constructed at all
        ccsv.assert_not_called()

        v = c.make_ui()
        self.assertEqual(v, 'all')
Esempio n. 10
0
    def test_all_systems_first_no_current(self, cv, ccsv):
        model = RecoverySystemsModel.from_systems([model1_non_current])
        app = make_app(model=model)
        c = RecoveryChooserController(app)
        c.ui.start_ui = mock.Mock()

        # sanity
        self.assertIsNone(c.model.current)

        # we get the all-systems view now
        cv.assert_called()
        # current system view is not constructed at all
        ccsv.assert_not_called()

        c.start_ui()
        c.ui.set_body.assert_called_with('all')
Esempio n. 11
0
 def test_no_current(self):
     reference = {
         "systems": [
             {
                 "current":
                 False,
                 "label":
                 "1234",
                 "brand": {
                     "id": "brand-id",
                     "username": "******",
                     "display-name": "this is my brand",
                     "validation": "verified",
                 },
                 "model": {
                     "model": "core20-amd64",
                     "brand-id": "brand-id",
                     "display-name": "Core 20 AMD64 system",
                 },
                 "actions": [
                     {
                         "title": "reinstall",
                         "mode": "install"
                     },
                     {
                         "title": "recover",
                         "mode": "recover"
                     },
                 ]
             },
         ],
     }
     systems = RecoverySystemsModel.from_systems(reference["systems"])
     self.assertEqual(len(systems.systems), 1)
     self.assertEqual(systems.systems[0].label, "1234")
     self.assertIsNone(systems.current)
Esempio n. 12
0
def make_model():
    return RecoverySystemsModel.from_systems(
        [model1_non_current, model2_current])
Esempio n. 13
0
 def test_from_systems_stream_invalid_empty(self):
     with self.assertRaises(jsonschema.ValidationError):
         RecoverySystemsModel.from_systems_stream(StringIO("{}"))