def test_descriptor_schema(self): resolwe = MagicMock() data = Data(id=1, resolwe=resolwe) data._descriptor_schema = DescriptorSchema(resolwe=resolwe, id=2) # test getting descriptor schema attribute self.assertEqual(data.descriptor_schema.id, 2) # pylint: disable=no-member # descriptor schema is not set data._descriptor_schema = None self.assertEqual(data.descriptor_schema, None) # hydrated descriptor schema descriptor_schema = { "slug": "test-schema", "name": "Test schema", "version": "1.0.0", "schema": [ { "default": "56G", "type": "basic:string:", "name": "description", "label": "Object description" } ], "id": 1, } data = Data(id=1, descriptor_schema=descriptor_schema, resolwe=MagicMock()) self.assertTrue(isinstance(data.descriptor_schema, DescriptorSchema)) # pylint: disable=no-member,unsubscriptable-object self.assertEqual(data.descriptor_schema.slug, 'test-schema') self.assertEqual(data.descriptor_schema.schema[0]['label'], 'Object description')
def test_descriptor_schema(self): data = Data(id=1, resolwe=MagicMock()) data._descriptor_schema = 1 # test getting descriptor schema attribute data.resolwe.descriptor_schema.get = MagicMock( return_value='descriptor_schema') self.assertEqual(data.descriptor_schema, 'descriptor_schema') _, get_kwargs = data.resolwe.descriptor_schema.get.call_args self.assertEqual(get_kwargs['id'], 1) # descriptor schema is not set data._descriptor_schema = None self.assertEqual(data.descriptor_schema, None) # cache is cleared at update data._hydrated_descriptor_schema = 'descriptor_schema' data.update() self.assertEqual(data._hydrated_descriptor_schema, None) # new data object data = Data(resolwe=MagicMock()) data.descriptor_schema = 'my-schema' self.assertEqual(data._descriptor_schema, 'my-schema') data.resolwe.descriptor_schema.get = MagicMock( return_value='descriptor_schema') self.assertEqual(data.descriptor_schema, 'descriptor_schema') _, get_kwargs = data.resolwe.descriptor_schema.get.call_args self.assertEqual(get_kwargs['slug'], 'my-schema') # hidrated descriptor schema descriptor_schema = { "slug": "test-schema", "name": "Test schema", "version": "1.0.0", "schema": [{ "default": "56G", "type": "basic:string:", "name": "description", "label": "Object description" }], "id": 1, } data = Data(id=1, descriptor_schema=descriptor_schema, resolwe=MagicMock()) self.assertTrue(isinstance(data.descriptor_schema, DescriptorSchema)) # pylint: disable=no-member self.assertEqual(data.descriptor_schema.slug, 'test-schema')
def test_descriptor_schema(self): data = Data(id=1, resolwe=MagicMock()) data._descriptor_schema = 1 # test getting descriptor schema attribute data.resolwe.descriptor_schema.get = MagicMock(return_value='descriptor_schema') self.assertEqual(data.descriptor_schema, 'descriptor_schema') _, get_kwargs = data.resolwe.descriptor_schema.get.call_args self.assertEqual(get_kwargs['id'], 1) # descriptor schema is not set data._descriptor_schema = None self.assertEqual(data.descriptor_schema, None) # cache is cleared at update data._hydrated_descriptor_schema = 'descriptor_schema' data.update() self.assertEqual(data._hydrated_descriptor_schema, None) # new data object data = Data(resolwe=MagicMock()) data.descriptor_schema = 'my-schema' self.assertEqual(data._descriptor_schema, 'my-schema') data.resolwe.descriptor_schema.get = MagicMock(return_value='descriptor_schema') self.assertEqual(data.descriptor_schema, 'descriptor_schema') _, get_kwargs = data.resolwe.descriptor_schema.get.call_args self.assertEqual(get_kwargs['slug'], 'my-schema') # hidrated descriptor schema descriptor_schema = { "slug": "test-schema", "name": "Test schema", "version": "1.0.0", "schema": [ { "default": "56G", "type": "basic:string:", "name": "description", "label": "Object description" } ], "id": 1, } data = Data(id=1, descriptor_schema=descriptor_schema, resolwe=MagicMock()) self.assertTrue(isinstance(data.descriptor_schema, DescriptorSchema)) # pylint: disable=no-member self.assertEqual(data.descriptor_schema.slug, 'test-schema')