示例#1
0
    def test_get_resource_collection(self):
        collection = Collection(id=1, resolwe=MagicMock())
        collection.id = 1  # this is overriden when initialized
        self.assertEqual(get_resource_collection(collection), 1)

        relation = Relation(id=1, resolwe=MagicMock())
        relation._hydrated_collection = Collection(id=2, resolwe=MagicMock())
        relation._hydrated_collection.id = 2  # this is overriden when initialized
        self.assertEqual(get_resource_collection(relation), 2)

        data = Data(id=1, resolwe=MagicMock())
        data._collections = [Collection(id=3, resolwe=MagicMock())]
        data._collections[0].id = 3  # this is overriden when initialized
        self.assertEqual(get_resource_collection(data), 3)

        sample = Sample(id=1, resolwe=MagicMock())
        sample._collections = [Collection(id=4, resolwe=MagicMock())]
        sample._collections[0].id = 4  # this is overriden when initialized
        self.assertEqual(get_resource_collection(sample), 4)

        sample = Sample(id=1, resolwe=MagicMock())
        sample._collections = [
            Collection(id=5, resolwe=MagicMock()),
            Collection(id=6, resolwe=MagicMock())
        ]
        sample._collections[0].id = 5  # this is overriden when initialized
        sample._collections[1].id = 6  # this is overriden when initialized
        self.assertEqual(get_resource_collection(sample), None)
        with self.assertRaises(LookupError):
            get_resource_collection(sample, fail_silently=False)
示例#2
0
    def test_get_resource_collection(self):
        collection = Collection(id=1, resolwe=MagicMock())
        collection.id = 1  # this is overriden when initialized
        self.assertEqual(get_resource_collection(collection), 1)

        relation = Relation(id=1, resolwe=MagicMock())
        relation._hydrated_collection = Collection(id=2, resolwe=MagicMock())
        relation._hydrated_collection.id = 2  # this is overriden when initialized
        self.assertEqual(get_resource_collection(relation), 2)

        data = Data(id=1, resolwe=MagicMock())
        data._collections = [Collection(id=3, resolwe=MagicMock())]
        data._collections[0].id = 3  # this is overriden when initialized
        self.assertEqual(get_resource_collection(data), 3)

        sample = Sample(id=1, resolwe=MagicMock())
        sample._collections = [Collection(id=4, resolwe=MagicMock())]
        sample._collections[0].id = 4  # this is overriden when initialized
        self.assertEqual(get_resource_collection(sample), 4)

        sample = Sample(id=1, resolwe=MagicMock())
        sample._collections = [
            Collection(id=5, resolwe=MagicMock()),
            Collection(id=6, resolwe=MagicMock())
        ]
        sample._collections[0].id = 5  # this is overriden when initialized
        sample._collections[1].id = 6  # this is overriden when initialized
        self.assertEqual(get_resource_collection(sample), None)
        with self.assertRaises(LookupError):
            get_resource_collection(sample, fail_silently=False)
示例#3
0
    def test_get_resolwe(self):
        # same resolwe object
        resolwe_mock = MagicMock()
        relation = Relation(id=1, resolwe=resolwe_mock)
        sample = Sample(id=1, resolwe=resolwe_mock)
        self.assertEqual(get_resolwe(relation, sample), resolwe_mock)

        relation = Relation(id=1, resolwe=MagicMock())
        sample = Sample(id=1, resolwe=MagicMock())
        with self.assertRaises(TypeError):
            get_resolwe(relation, sample)
示例#4
0
    def test_get_relation_id(self):
        relation = Relation(id=1, resolwe=MagicMock())
        relation.id = 1  # this is overriden when initialized
        self.assertEqual(get_relation_id(relation), 1)

        self.assertEqual(get_relation_id(2), 2)
示例#5
0
    def test_get_relation_id(self):
        relation = Relation(id=1, resolwe=MagicMock())
        relation.id = 1  # this is overriden when initialized
        self.assertEqual(get_relation_id(relation), 1)

        self.assertEqual(get_relation_id(2), 2)