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)
    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)
    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 = collection
        self.assertEqual(relation.collection, collection)