def get_gadget_snap(): model = next(decode(Snapd().get_assertions('model')), None) if model: # convert to resource to handle presence of track info resource = model_to_resource(model) return resource.get('gadget') return None
def test_decode_focal(self): assertion_stream = create_mock_response(model_focal_desktop) iter = decode(assertion_stream) a = next(iter) self.assertIn('type', a) self.assertEqual(a['type'], 'model') self.assertIn('model', a) self.assertEqual(a['model'], 'generic-classic') with self.assertRaises(StopIteration): next(iter)
def test_decode_uc20(self): assertion_stream = create_mock_response(model_uc20) iter = decode(assertion_stream) a = next(iter) self.assertIn('type', a) self.assertEqual(a['type'], 'model') self.assertIn('model', a) self.assertEqual(a['model'], 'ubuntu-core-20-amd64-dangerous') with self.assertRaises(StopIteration): next(iter)
def test_decode_focal(self): assertion_stream = create_mock_response(serial_focal_desktop) iter = decode(assertion_stream) a = next(iter) self.assertIn('type', a) self.assertEqual(a['type'], 'serial') self.assertIn('serial', a) self.assertEqual(a['serial'], '12345678-1234-1234-1234-b4f4dc4a1f9a') with self.assertRaises(StopIteration): next(iter)
def test_decode_uc16_brandstore(self): assertion_stream = create_mock_response(model_uc16_brandstore) iter = decode(assertion_stream) a = next(iter) self.assertIn('type', a) self.assertEqual(a['type'], 'model') self.assertIn('model', a) self.assertEqual(a['model'], 'devicemodel') self.assertIn('store', a) self.assertEqual(a['store'], 'aaaaabbbbbccccc12345') self.assertIn('brand-id', a) self.assertEqual(a['brand-id'], 'acmeinc') with self.assertRaises(StopIteration): next(iter)
def test_model_to_resource_uc16_brandstore(self): assertion_stream = create_mock_response(model_uc16_brandstore) iter = decode(assertion_stream) a = next(iter) correct_resource = { 'type': 'model', 'authority-id': 'acmeinc', 'brand-id': 'acmeinc', 'model': 'devicemodel', 'sign-key-sha3-384': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'architecture': 'amd64', 'gadget': 'device', 'kernel': 'device-kernel', 'store': 'aaaaabbbbbccccc12345' } self.assertDictEqual(correct_resource, model_to_resource(a)) with self.assertRaises(StopIteration): next(iter)
def test_model_to_resource_focal_server(self): assertion_stream = create_mock_response(model_focal_server) iter = decode(assertion_stream) a = next(iter) correct_resource = { 'type': 'model', 'authority-id': 'generic', 'brand-id': 'generic', 'model': 'generic-classic', 'sign-key-sha3-384': 'd-JcZF9nD9eBw7bwMnH61x-bklnQOhQud1Is6o_cn2wTj8EYDi9musrIT9z2MdAa' } self.assertDictEqual(correct_resource, model_to_resource(a)) self.assertNotIn('kernel', model_to_resource(a)) with self.assertRaises(StopIteration): next(iter)
def test_model_to_resource_uc18(self): assertion_stream = create_mock_response(model_uc18) iter = decode(assertion_stream) a = next(iter) correct_resource = { 'type': 'model', 'authority-id': 'canonical', 'brand-id': 'canonical', 'model': 'ubuntu-core-18-amd64', 'architecture': 'amd64', 'base': 'core18', 'sign-key-sha3-384': '9tydnLa6MTJ-jaQTFUXEwHl1yRx7ZS4K5cyFDhYDcPzhS7uyEkDxdUjg9g08BtNn', 'kernel': 'pc-kernel', 'kernel_track': '18', 'gadget': 'pc', 'gadget_track': '18' } self.assertDictEqual(correct_resource, model_to_resource(a)) with self.assertRaises(StopIteration): next(iter)
def test_serial_to_resource_focal(self): assertion_stream = create_mock_response(serial_focal_desktop) iter = decode(assertion_stream) a = next(iter) correct_resource = { 'type': 'serial', 'authority-id': 'generic', 'brand-id': 'generic', 'model': 'generic-classic', 'serial': '12345678-1234-1234-1234-b4f4dc4a1f9a', 'sign-key-sha3-384': 'wrfougkz3Huq2T_KklfnufCC0HzG7bJ9wP99GV0FF-D3QH3eJtuSRlQc2JhrAoh1' } self.assertDictEqual(correct_resource, serial_to_resource(a)) with self.assertRaises(StopIteration): next(iter)