Exemple #1
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)
    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