Esempio n. 1
0
    def test_search(self):
        with self.assertRaises(ValueError):
            Plate.search()

        with self.assertRaises(ValueError):
            Plate.search(samples=['1.SKB1.640202'], query_type='WRONG')

        plate21 = Plate(21)
        plate22 = Plate(22)
        plate23 = Plate(23)
        plate27 = Plate(27)
        plate30 = Plate(30)
        plate33 = Plate(33)

        self.assertEqual(
            Plate.search(samples=['1.SKB1.640202', '1.SKB2.640194']),
            [plate21, plate27, plate30, plate33])
        self.assertEqual(Plate.search(samples=['1.SKB1.640202']),
                         [plate21, plate27, plate30, plate33])

        self.assertEqual(Plate.search(plate_notes='interesting'), [])
        # Add comments to a plate so we can actually test the
        # search functionality
        plate22.notes = 'Some interesting notes'
        plate23.notes = 'More boring notes'

        self.assertEqual(Plate.search(plate_notes='interesting'), [plate22])
        self.assertCountEqual(Plate.search(plate_notes='interesting boring'),
                              [])
        self.assertEqual(
            Plate.search(samples=['1.SKB1.640202'], plate_notes='interesting'),
            [])
        # sample '1.SKB1.640202' is on 4 sample plates, plus there is a
        # gdna plate with a note containing the word 'interesting'
        self.assertCountEqual(
            Plate.search(samples=['1.SKB1.640202'],
                         plate_notes='interesting',
                         query_type='UNION'),
            [plate21, plate22, plate27, plate30, plate33])

        # The search engine ignores common english words
        self.assertEqual(Plate.search(plate_notes='more'), [])

        # Add comments to some wells
        plate23.get_well(1, 1).composition.notes = 'What else should I write?'
        self.assertEqual(Plate.search(well_notes='write'), [plate23])
        self.assertEqual(
            Plate.search(plate_notes='interesting', well_notes='write'), [])
        self.assertCountEqual(
            Plate.search(plate_notes='interesting',
                         well_notes='write',
                         query_type='UNION'), [plate22, plate23])
Esempio n. 2
0
    def test_post_plate_search_handler(self):
        # Note: these tests don't exercise all the cases covered in
        # db/tests/test_plate.py test_search; instead, they focus on
        # testing at least one search based on each of the input
        # fields, to verify that these are being passed through
        # correctly to the db's Plate.search method.

        # Test search by sample names:
        post_data = {
            'sample_names': dumps(['1.SKB1.640202', '1.SKB2.640194']),
            'plate_comment_keywords': "",
            'well_comment_keywords': "",
            'operation': "INTERSECT"
        }

        response = self.post('/plate_search', post_data)
        self.assertEqual(response.code, 200)
        obs = json_decode(response.body)
        self.assertCountEqual(obs.keys(), ['data'])
        obs_data = obs['data']
        self.assertEqual(len(obs_data), 4)
        self.assertEqual(obs_data[0], [21, 'Test plate 1'])

        # Test search by plate comment keywords:
        # It looks like none of the plates in the test database have
        # any notes, so it is necessary to add some to be able to
        # test the keywords search functionality; the below is lifted
        # verbatim from db/tests/test_plate.py test_search
        plate22 = Plate(22)
        plate23 = Plate(23)

        # Add comments to a plate so we can actually test the
        # search functionality
        plate22.notes = 'Some interesting notes'
        plate23.notes = 'More boring notes'
        # end verbatim lift

        post_data = {
            'sample_names': dumps([]),
            'plate_comment_keywords': 'interesting boring',
            'well_comment_keywords': "",
            'operation': "INTERSECT"
        }
        response = self.post('/plate_search', post_data)
        self.assertEqual(response.code, 200)
        obs = json_decode(response.body)
        self.assertCountEqual(obs.keys(), ['data'])
        obs_data = obs['data']
        self.assertEqual(len(obs_data), 0)

        # Test search by intersecting or unioning multiple search terms:
        post_data = {
            'sample_names': dumps(['1.SKB1.640202']),
            'plate_comment_keywords': 'interesting boring',
            'well_comment_keywords': "",
            'operation': "INTERSECT"
        }
        response = self.post('/plate_search', post_data)
        self.assertEqual(response.code, 200)
        obs = json_decode(response.body)
        self.assertCountEqual(obs.keys(), ['data'])
        obs_data = obs['data']
        self.assertEqual(len(obs_data), 0)

        post_data = {
            'sample_names': dumps(['1.SKB1.640202']),
            'plate_comment_keywords': 'interesting boring',
            'well_comment_keywords': "",
            'operation': "UNION"
        }
        response = self.post('/plate_search', post_data)
        self.assertEqual(response.code, 200)
        obs = json_decode(response.body)
        self.assertCountEqual(obs.keys(), ['data'])
        obs_data = obs['data']
        self.assertEqual(len(obs_data), 4)
        self.assertEqual(obs_data[0], [21, 'Test plate 1'])

        # Test search by well comment keywords:
        # Add comments to some wells so can test well comment search
        plate23.get_well(1, 1).composition.notes = 'What should I write?'

        post_data = {
            'sample_names': dumps([]),
            'plate_comment_keywords': '',
            'well_comment_keywords': "write",
            'operation': "INTERSECT"
        }
        response = self.post('/plate_search', post_data)
        self.assertEqual(response.code, 200)
        obs = json_decode(response.body)
        self.assertCountEqual(obs.keys(), ['data'])
        obs_data = obs['data']
        self.assertEqual(len(obs_data), 1)
        self.assertEqual(obs_data[0], [23, 'Test 16S plate 1'])