Exemplo n.º 1
0
    def test_moleculesjson_nrscaneqfilter(self):
        filter_in = '[{"type":"numeric","comparison":"eq",'
        filter_in += '"value":1,"field":"nhits"}]'
        filter_expected = [{
            "type": "numeric",
            "comparison": "eq",
            "value": 1,
            "field": "nhits"
        }]
        request = testing.DummyRequest(params={
            'start': 0,
            'limit': 10,
            'filter': filter_in
        })
        job = self.fake_job()
        views = JobViews(job, request)

        views.moleculesjson()

        job.db.molecules.assert_called_with(
            start=0,
            limit=10,
            sorts=[],
            scanid=None,
            filters=filter_expected,
            molid=None,
            mz=None,
        )
        job.db.scansWithMolecules.assert_called_with(filters=filter_expected,
                                                     molid=None,
                                                     mz=None,
                                                     scanid=None)
Exemplo n.º 2
0
    def test_moleculesjson_molpage(self):
        request = testing.DummyRequest(params={
            'start': 0,
            'limit': 10,
            'molid': 1,
        })
        job = self.fake_job()
        views = JobViews(job, request)
        job.db.molecules.return_value = {
            'total': 3,
            'rows': [1, 2, 3],
            'page': 1
        }

        response = views.moleculesjson()

        self.assertEqual(
            response, {
                'totalUnfiltered': 3,
                'total': 3,
                'rows': [1, 2, 3],
                'molid': 1,
                'page': 1,
                'scans': [4, 5]
            })
Exemplo n.º 3
0
    def test_moleculesjson_scanidfilter(self):
        request = testing.DummyRequest(params={
            'start': 0,
            'limit': 10,
            'scanid': 641
        })
        job = self.fake_job()
        views = JobViews(job, request)

        views.moleculesjson()

        job.db.molecules.assert_called_with(
            start=0,
            limit=10,
            sorts=[],
            scanid=641,
            filters=[],
            molid=None,
            mz=None,
        )
Exemplo n.º 4
0
    def test_moleculessdf(self):
        job = self.fake_job()
        job.db.molecules2sdf.return_value = 'bla'
        request = testing.DummyRequest(params={'start': 0, 'limit': 10})
        views = JobViews(job, request)
        views.moleculesjson = Mock(return_value={'rows': []})
        response = views.moleculessdf()

        job.db.molecules2sdf.assert_called_with([], cols=[])
        self.assertEqual(response.content_type, 'chemical/x-mdl-sdfile')
        self.assertEqual(response.body, 'bla')
Exemplo n.º 5
0
    def test_moleculesjson_scansfilteredonmol(self):
        request = testing.DummyRequest(params={
            'start': 0,
            'limit': 10,
            'molid': 1,
        })
        job = self.fake_job()
        views = JobViews(job, request)
        job.db.molecules.return_value = {
            'total': 3,
            'rows': [1, 2, 3],
            'page': 1,
            'molid': 1
        }

        views.moleculesjson()

        job.db.scansWithMolecules.assert_called_once_with(filters=[],
                                                          molid=1,
                                                          mz=None,
                                                          scanid=None)
Exemplo n.º 6
0
    def test_moleculessdf_somecols(self):
        job = self.fake_job()
        job.db.molecules2sdf.return_value = 'bla'
        request = testing.DummyRequest(params={
            'start': 0,
            'limit': 10,
            'cols': '["name","score"]'
        })
        views = JobViews(job, request)
        views.moleculesjson = Mock(return_value={'rows': []})
        views.moleculessdf()

        job.db.molecules2sdf.assert_called_with([], cols=['name', 'score'])
Exemplo n.º 7
0
    def test_moleculescsv(self):
        csv = StringIO()
        csv.write('bla')
        job = self.fake_job()
        job.db.molecules2csv.return_value = csv
        request = testing.DummyRequest(params={'start': 0, 'limit': 10})
        views = JobViews(job, request)
        views.moleculesjson = Mock(return_value={'rows': []})

        response = views.moleculescsv()

        self.assertEqual(response.content_type, 'text/csv')
        self.assertEqual(response.body, b'bla')
Exemplo n.º 8
0
    def test_moleculesjson_notfilledreturn(self):
        request = testing.DummyRequest(params={'start': 0, 'limit': 10})
        job = self.fake_job()
        job.db.moleculesTotalCount.return_value = 0
        views = JobViews(job, request)

        response = views.moleculesjson()

        self.assertEqual(response, {
            'totalUnfiltered': 0,
            'total': 3,
            'rows': [1, 2, 3],
            'scans': [4, 5]
        })
Exemplo n.º 9
0
    def test_moleculescsv_somecols(self):
        csv = StringIO()
        csv.write('bla')
        job = self.fake_job()
        job.db.molecules2csv.return_value = csv
        request = testing.DummyRequest(params={
            'start': 0,
            'limit': 10,
            'cols': '["name","score"]'
        })

        views = JobViews(job, request)
        rows = [{'name': 'foo', 'score': 'bar', 'id': 123}]
        views.moleculesjson = Mock(return_value={'rows': rows})

        views.moleculescsv()

        job.db.molecules2csv.assert_called_with(rows, cols=['name', 'score'])