Ejemplo n.º 1
0
    def test_collection(self, copy_mock):
        relation = Relation(id=1, resolwe=MagicMock())
        collection = Collection(id=3, resolwe=MagicMock())
        collection.id = 3  # this is overriden when initialized

        # get collection
        relation.resolwe.collection.get = MagicMock(return_value=collection)
        relation._collection = 3
        self.assertEqual(relation.collection, collection)

        # test caching collection attribute
        self.assertEqual(relation.collection, collection)
        self.assertEqual(relation.resolwe.collection.get.call_count, 1)

        # set collection
        relation.collection = 2
        self.assertEqual(relation._collection, 2)
        self.assertEqual(relation._hydrated_collection, None)
        relation.collection = collection
        self.assertEqual(relation._collection, 3)
        self.assertEqual(relation._hydrated_collection, collection)

        # cache is cleared at update
        relation._collection = 2
        relation._hydrated_collection = collection
        relation.update()
        self.assertEqual(relation._hydrated_collection, None)
Ejemplo n.º 2
0
    def test_collection(self):
        relation = Relation(id=1, resolwe=MagicMock())
        collection = Collection(id=3, resolwe=MagicMock())
        collection.id = 3  # this is overriden when initialized

        # get collection
        relation.resolwe.collection.get = MagicMock(return_value=collection)
        relation._collection = 3
        self.assertEqual(relation.collection, collection)

        # test caching collection attribute
        self.assertEqual(relation.collection, collection)
        self.assertEqual(relation.resolwe.collection.get.call_count, 1)

        # set collection
        relation.collection = 2
        self.assertEqual(relation._collection, 2)
        self.assertEqual(relation._hydrated_collection, None)
        relation.collection = collection
        self.assertEqual(relation._collection, 3)
        self.assertEqual(relation._hydrated_collection, collection)

        # cache is cleared at update
        relation._collection = 2
        relation._hydrated_collection = collection
        relation.update()
        self.assertEqual(relation._hydrated_collection, None)
Ejemplo n.º 3
0
    def test_samples(self):
        relation = Relation(id=1, resolwe=MagicMock())

        sample_1 = MagicMock(id=1)
        sample_2 = MagicMock(id=2)
        # order in return_value is intentionally mixed to test ordering
        relation.resolwe.sample.filter = MagicMock(
            return_value=[sample_2, sample_1])
        relation.entities = [
            {
                'entity': 1,
                'position': None
            },
            {
                'entity': 2,
                'position': None
            },
        ]
        self.assertEqual(relation.samples, [sample_1, sample_2])
        relation.resolwe.sample.filter.assert_called_with(id__in='1,2')

        # test caching
        self.assertEqual(relation.samples, [sample_1, sample_2])
        self.assertEqual(relation.resolwe.sample.filter.call_count, 1)

        # cache is cleared at update
        relation._samples = ['sample']
        relation.update()
        self.assertEqual(relation._samples, None)
Ejemplo n.º 4
0
    def test_samples(self):
        relation = Relation(id=1, resolwe=MagicMock())

        sample_1 = MagicMock(id=1)
        sample_2 = MagicMock(id=2)
        # order in return_value is intentionally mixed to test ordering
        relation.resolwe.sample.filter = MagicMock(return_value=[sample_2, sample_1])
        relation.partitions = [
            {'entity': 1, 'position': None},
            {'entity': 2, 'position': None},
        ]
        self.assertEqual(relation.samples, [sample_1, sample_2])
        relation.resolwe.sample.filter.assert_called_with(id__in=[1, 2])

        # test caching
        self.assertEqual(relation.samples, [sample_1, sample_2])
        self.assertEqual(relation.resolwe.sample.filter.call_count, 1)

        # cache is cleared at update
        relation._samples = ['sample']
        relation.update()
        self.assertEqual(relation._samples, None)