コード例 #1
0
ファイル: test_utils.py プロジェクト: genialis/resolwe-bio-py
    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_samples(self):
        collection = Collection(id=1, resolwe=MagicMock())
        collection._samples = ['sample_1', 'sample_2']
        self.assertEqual(get_samples(collection), ['sample_1', 'sample_2'])

        collection_1 = Collection(id=1, resolwe=MagicMock())
        collection_1._samples = ['sample_1']
        collection_2 = Collection(id=2, resolwe=MagicMock())
        collection_2._samples = ['sample_2']
        self.assertEqual(get_samples([collection_1, collection_2]),
                         ['sample_1', 'sample_2'])

        data = Data(id=1, resolwe=MagicMock())
        data._sample = 'sample_1'
        self.assertEqual(get_samples(data), ['sample_1'])

        data1 = Data(id=1, resolwe=MagicMock())
        data1._sample = 'sample1'
        data2 = Data(id=2, resolwe=MagicMock())
        data2._sample = 'sample2'
        self.assertEqual(get_samples([data1, data2]), ['sample1', 'sample2'])

        data = Data(id=1,
                    resolwe=MagicMock(**{'sample.filter.return_value': None}))
        data._sample = None
        with self.assertRaises(TypeError):
            get_samples(data)

        sample = Sample(id=1, resolwe=MagicMock())
        self.assertEqual(get_samples(sample), [sample])

        sample_1 = Sample(id=1, resolwe=MagicMock())
        sample_2 = Sample(id=3, resolwe=MagicMock())
        self.assertEqual(get_samples([sample_1, sample_2]),
                         [sample_1, sample_2])
コード例 #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_samples(self):
        collection = Collection(id=1, resolwe=MagicMock())
        collection._samples = ['sample_1', 'sample_2']
        self.assertEqual(get_samples(collection), ['sample_1', 'sample_2'])

        collection_1 = Collection(id=1, resolwe=MagicMock())
        collection_1._samples = ['sample_1']
        collection_2 = Collection(id=2, resolwe=MagicMock())
        collection_2._samples = ['sample_2']
        self.assertEqual(get_samples([collection_1, collection_2]),
                         ['sample_1', 'sample_2'])

        sample = Sample(id=1, resolwe=MagicMock())
        self.assertEqual(get_samples(sample), [sample])

        sample_1 = Sample(id=1, resolwe=MagicMock())
        sample_2 = Sample(id=3, resolwe=MagicMock())
        self.assertEqual(get_samples([sample_1, sample_2]),
                         [sample_1, sample_2])
コード例 #5
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)
コード例 #6
0
    def test_get_samples(self):
        collection = Collection(id=1, resolwe=MagicMock())
        collection._samples = ['sample_1', 'sample_2']
        self.assertEqual(get_samples(collection), ['sample_1', 'sample_2'])

        collection_1 = Collection(id=1, resolwe=MagicMock())
        collection_1._samples = ['sample_1']
        collection_2 = Collection(id=2, resolwe=MagicMock())
        collection_2._samples = ['sample_2']
        self.assertEqual(get_samples([collection_1, collection_2]),
                         ['sample_1', 'sample_2'])

        data = Data(id=1, resolwe=MagicMock())
        data.api(data.id).get = MagicMock(return_value={'entities': [7]})
        data.resolwe.sample.get = MagicMock(return_value='sample_1')
        self.assertEqual(get_samples(data), ['sample_1'])

        data1 = Data(id=1, resolwe=MagicMock())
        data1.api(data.id).get = MagicMock(return_value={'entities': [7]})
        data1.resolwe.sample.get = MagicMock(return_value='sample1')

        data2 = Data(id=2, resolwe=MagicMock())
        data2.api(data.id).get = MagicMock(return_value={'entities': [8]})
        data2.resolwe.sample.get = MagicMock(return_value='sample2')
        self.assertEqual(get_samples([data1, data2]), ['sample1', 'sample2'])

        data = Data(id=1,
                    resolwe=MagicMock(**{'sample.get.return_value': None}))
        data._sample = None
        with self.assertRaises(TypeError):
            get_samples(data)

        sample = Sample(id=1, resolwe=MagicMock())
        self.assertEqual(get_samples(sample), [sample])

        sample_1 = Sample(id=1, resolwe=MagicMock())
        sample_2 = Sample(id=3, resolwe=MagicMock())
        self.assertEqual(get_samples([sample_1, sample_2]),
                         [sample_1, sample_2])
コード例 #7
0
    def test_get_sample_id(self):
        sample = Sample(id=1, resolwe=MagicMock())
        sample.id = 1  # this is overriden when initialized
        self.assertEqual(get_sample_id(sample), 1)

        self.assertEqual(get_sample_id(2), 2)
コード例 #8
0
    def test_new_presample(self):
        presample = Sample(resolwe=self.res, presample=True)
        self.remove.append(presample)

        presample.name = 'my-presample'
        presample.save()

        response = presample.api(presample.id).get()
        unsupported = set(presample.fields()).symmetric_difference(
            response.keys())
        self.assertEqual(len(unsupported),
                         0,
                         msg="Some fields are not supported: {}".format(
                             ', '.join(unsupported)))

        presample.slug = 'my-test'
        presample.save()

        response = presample.api(presample.id).get()
        self.assertEqual(response['slug'], presample.slug)
コード例 #9
0
    def test_new_sample(self):
        sample = Sample(resolwe=self.res)
        self.remove.append(sample)

        sample.name = 'my-sample'
        sample.save()

        response = sample.api(sample.id).get()
        unsupported = set(sample.fields()).symmetric_difference(
            response.keys())

        self.assertEqual(
            len(unsupported),
            1,  # presample field is not supported in Sample
            msg="Some fields are not supported: {}".format(
                ', '.join(unsupported)))

        sample.slug = 'my-test'
        sample.save()

        response = sample.api(sample.id).get()
        self.assertEqual(response['slug'], sample.slug)
コード例 #10
0
ファイル: test_utils.py プロジェクト: genialis/resolwe-bio-py
    def test_get_sample_id(self):
        sample = Sample(id=1, resolwe=MagicMock())
        sample.id = 1  # this is overriden when initialized
        self.assertEqual(get_sample_id(sample), 1)

        self.assertEqual(get_sample_id(2), 2)