Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    def test_collections(self):
        data = Data(id=1, resolwe=MagicMock())

        # test getting collections attribute
        data.resolwe.collection.filter = MagicMock(return_value=['collection'])
        self.assertEqual(data.collections, ['collection'])

        # test caching collections attribute
        self.assertEqual(data.collections, ['collection'])
        self.assertEqual(data.resolwe.collection.filter.call_count, 1)

        # cache is cleared at update
        data._collections = ['collection']
        data.update()
        self.assertEqual(data._collections, None)

        # raising error if data object is not saved
        data.id = None
        with self.assertRaises(ValueError):
            _ = data.collections
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    def test_sample(self):
        data = Data(id=1, resolwe=MagicMock())

        data.resolwe.sample.filter = MagicMock(return_value=[])
        self.assertEqual(data.sample, None)

        data.resolwe.sample.filter = MagicMock(return_value=['sample'])
        self.assertEqual(data.sample, 'sample')
        # test caching
        self.assertEqual(data.sample, 'sample')
        self.assertEqual(data.resolwe.sample.filter.call_count, 1)

        # cache is cleared at update
        data._sample = 'sample'
        data.update()
        self.assertEqual(data._sample, None)

        # raising error if data object is not saved
        data.id = None
        with self.assertRaises(ValueError):
            _ = data.sample