def test_collections(self): data = Data(id=1, resolwe=MagicMock()) # test getting collections attribute data.api(data.id).get = MagicMock(return_value={'collections': [5]}) data.resolwe.collection.filter = MagicMock(return_value=[ Collection(data.resolwe, **{'id': 5, 'name': 'XYZ'}) ]) self.assertEqual(len(data.collections), 1) self.assertEqual(data.collections[0].id, 5) self.assertEqual(data.collections[0].name, 'XYZ') # test caching collections attribute self.assertEqual(len(data.collections), 1) self.assertEqual(data.resolwe.collection.filter.call_count, 1) # cache is cleared at update data.update() self.assertEqual(data._collections, None) # raising error if data object is not saved data.id = None with self.assertRaises(ValueError): _ = data.collections
def test_collections(self): data = Data(id=1, resolwe=MagicMock()) # test getting collections attribute data.api(data.id).get = MagicMock(return_value={'collections': [5]}) data.resolwe.collection.filter = MagicMock(return_value=[ Collection(data.resolwe, **{'id': 5, 'name': 'XYZ'}) ]) self.assertEqual(len(data.collections), 1) self.assertEqual(data.collections[0].id, 5) self.assertEqual(data.collections[0].name, 'XYZ') # test caching collections attribute self.assertEqual(len(data.collections), 1) self.assertEqual(data.resolwe.collection.filter.call_count, 1) # cache is cleared at update data.update() self.assertEqual(data._collections, None) # raising error if data object is not saved data.id = None with self.assertRaises(ValueError): _ = data.collections
def test_sample(self): data = Data(id=1, resolwe=MagicMock()) data.api(data.id).get = MagicMock(return_value={'entities': [5]}) data.resolwe.sample.get = MagicMock( return_value=Sample(data.resolwe, **{'id': 5, 'name': 'XYZ'})) self.assertEqual(data.sample.id, 5) self.assertEqual(data.sample.name, 'XYZ') # test caching self.assertEqual(data.sample.id, 5) self.assertEqual(data.resolwe.sample.get.call_count, 1) # cache is cleared at update data.update() self.assertEqual(data._sample, None) # raising error if data object is not saved data.id = None with self.assertRaises(ValueError): _ = data.sample
def test_sample(self): data = Data(id=1, resolwe=MagicMock()) data.api(data.id).get = MagicMock(return_value={'entities': [5]}) data.resolwe.sample.get = MagicMock( return_value=Sample(data.resolwe, **{'id': 5, 'name': 'XYZ'})) self.assertEqual(data.sample.id, 5) self.assertEqual(data.sample.name, 'XYZ') # test caching self.assertEqual(data.sample.id, 5) self.assertEqual(data.resolwe.sample.get.call_count, 1) # cache is cleared at update data.update() self.assertEqual(data._sample, None) # raising error if data object is not saved data.id = None with self.assertRaises(ValueError): _ = data.sample
def test_no_sample(self): data = Data(id=1, resolwe=MagicMock()) # Data object does not belong to any sample: data.api(data.id).get = MagicMock(return_value={'entities': []}) self.assertEqual(data.sample, None)
def test_no_sample(self): data = Data(id=1, resolwe=MagicMock()) # Data object does not belong to any sample: data.api(data.id).get = MagicMock(return_value={'entities': []}) self.assertEqual(data.sample, None)