コード例 #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
ファイル: 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)
コード例 #3
0
    def test_dehydrate_data(self, resolwe_mock):
        data_obj = Data(id=1, resolwe=MagicMock())
        data_obj.id = 1  # this is overriden when initialized
        process = self.process_mock

        result = Resolwe._process_inputs(resolwe_mock, {"genome": data_obj}, process)
        self.assertEqual(result, {'genome': 1})

        result = Resolwe._process_inputs(resolwe_mock, {"reads": [data_obj]}, process)
        self.assertEqual(result, {'reads': [1]})
コード例 #4
0
    def test_dehydrate_data(self, resolwe_mock):
        data_obj = Data(id=1, resolwe=MagicMock())
        data_obj.id = 1  # this is overriden when initialized
        process = self.process_json[0]

        result = Resolwe._process_inputs(resolwe_mock, {"genome": data_obj}, process)
        self.assertEqual(result, {'genome': 1})

        result = Resolwe._process_inputs(resolwe_mock, {"reads": [data_obj]}, process)
        self.assertEqual(result, {'reads': [1]})
コード例 #5
0
    def test_dehydrate_data(self, resolwe_mock, copy_mock):
        data_obj = Data(id=1, resolwe=MagicMock())
        data_obj.id = 1  # this is overriden when initialized
        process = self.process_mock

        # I appears it is not possible to deepcopy MagicMocks so we just patch
        # the deepcopy functionality:
        copy_mock.deepcopy = MagicMock(return_value={"genome": data_obj})
        result = Resolwe._process_inputs(resolwe_mock, {"genome": data_obj}, process)
        self.assertEqual(result, {'genome': 1})

        # I appears it is not possible to deepcopy MagicMocks so we just patch
        # the deepcopy functionality:
        copy_mock.deepcopy = MagicMock(return_value={"reads": data_obj})
        result = Resolwe._process_inputs(resolwe_mock, {"reads": [data_obj]}, process)
        self.assertEqual(result, {'reads': [1]})
コード例 #6
0
    def test_dehydrate_data(self, resolwe_mock, copy_mock):
        data_obj = Data(id=1, resolwe=MagicMock())
        data_obj.id = 1  # this is overriden when initialized
        process = self.process_mock

        # I appears it is not possible to deepcopy MagicMocks so we just patch
        # the deepcopy functionality:
        copy_mock.deepcopy = MagicMock(return_value={"genome": data_obj})
        result = Resolwe._process_inputs(resolwe_mock, {"genome": data_obj},
                                         process)
        self.assertEqual(result, {'genome': 1})

        # I appears it is not possible to deepcopy MagicMocks so we just patch
        # the deepcopy functionality:
        copy_mock.deepcopy = MagicMock(return_value={"reads": data_obj})
        result = Resolwe._process_inputs(resolwe_mock, {"reads": [data_obj]},
                                         process)
        self.assertEqual(result, {'reads': [1]})
コード例 #7
0
ファイル: base.py プロジェクト: robertcv/resolwe-bio-py
    def _get_data_uri(self, data: Data, data_type: str) -> str:
        field_name = self.data_type_to_field_name[data_type]
        files = data.files(field_name=field_name)

        if not files:
            raise LookupError(
                f"Data {data.slug} has no files named {field_name}!")
        elif len(files) > 1:
            raise LookupError(
                f"Data {data.slug} has multiple files named {field_name}!")

        return f"{data.id}/{files[0]}"
コード例 #8
0
ファイル: test_utils.py プロジェクト: genialis/resolwe-bio-py
    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])
コード例 #9
0
    def test_get_data_id(self):
        data = Data(id=1, resolwe=MagicMock())
        data.id = 1  # this is overriden when initialized
        self.assertEqual(get_data_id(data), 1)

        self.assertEqual(get_data_id(2), 2)
コード例 #10
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])
コード例 #11
0
ファイル: test_utils.py プロジェクト: genialis/resolwe-bio-py
    def test_get_data_id(self):
        data = Data(id=1, resolwe=MagicMock())
        data.id = 1  # this is overriden when initialized
        self.assertEqual(get_data_id(data), 1)

        self.assertEqual(get_data_id(2), 2)
コード例 #12
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])