예제 #1
0
 def test_patch_plate_discarded_handler(self):
     tester = Plate(21)
     data = {'op': 'replace', 'path': '/discarded/', 'value': True}
     response = self.patch('/plate/21/', data)
     self.assertEqual(response.code, 200)
     self.assertEqual(tester.discarded, True)
     tester.discarded = False
예제 #2
0
    def test_plate_handler_patch_request(self):
        tester = Plate(21)
        user = User('*****@*****.**')

        # Incorrect path parameter
        regex = 'Incorrect path parameter'
        with self.assertRaisesRegex(HTTPError, regex):
            plate_handler_patch_request(user, 21, 'replace', '/name/newname',
                                        'NewName', None)

        # Unknown attribute
        regex = 'Attribute unknown not recognized'
        with self.assertRaisesRegex(HTTPError, regex):
            plate_handler_patch_request(user, 21, 'replace', '/unknown/',
                                        'NewName', None)

        # Unknown operation
        regex = ('Operation add not supported. Current supported '
                 'operations: replace')
        with self.assertRaisesRegex(HTTPError, regex):
            plate_handler_patch_request(user, 21, 'add', '/name/', 'NewName',
                                        None)

        # Plate doesn't exist
        regex = 'Plate 100 doesn\'t exist'
        with self.assertRaisesRegex(HTTPError, regex):
            plate_handler_patch_request(user, 100, 'replace', '/name/',
                                        'NewName', None)

        # Test success - Name
        plate_handler_patch_request(user, 21, 'replace', '/name/', 'NewName',
                                    None)
        self.assertEqual(tester.external_id, 'NewName')
        tester.external_id = 'Test plate 1'

        # Test success - discarded
        plate_handler_patch_request(user, 21, 'replace', '/discarded/', True,
                                    None)
        self.assertEqual(tester.discarded, True)
        tester.discarded = False
예제 #3
0
    def test_properties(self):
        # Plate 21 - Defined in the test DB
        tester = Plate(21)

        obs = tester.creation_timestamp
        obs = str(datetime.datetime(obs.year, obs.month, obs.day))
        exp = datetime.datetime.now()
        exp = str(datetime.datetime(exp.year, exp.month, exp.day))
        self.assertEqual(obs, exp)
        self.assertEqual(tester.external_id, 'Test plate 1')
        self.assertEqual(tester.plate_configuration, PlateConfiguration(1))
        self.assertFalse(tester.discarded)
        tester.discarded = True
        self.assertTrue(tester.discarded)
        self.assertIsNone(tester.notes)
        obs_layout = tester.layout
        self.assertEqual(len(obs_layout), 8)
        for row in obs_layout:
            self.assertEqual(len(row), 12)
        self.assertEqual(tester.studies, {Study(1)})
        self.assertListEqual(tester.quantification_processes, [])
        self.assertEqual(tester.process, SamplePlatingProcess(11))

        # Test changing the name of the plate
        tester.external_id = 'Some new name'
        self.assertEqual(tester.external_id, 'Some new name')
        tester.external_id = 'Test plate 1'
        self.assertEqual(tester.external_id, 'Test plate 1')

        self.assertEqual(len(Plate(23).quantification_processes), 1)
        self.assertEqual(
            Plate(23).quantification_processes[0], QuantificationProcess(1))
        self.assertEqual(Plate(22).process, GDNAExtractionProcess(1))

        exp = {
            '1.SKB1.640202': [[Well(3073), '1.SKB1.640202.Test.plate.1.A1'],
                              [Well(3121), '1.SKB1.640202.Test.plate.1.A2'],
                              [Well(3169), '1.SKB1.640202.Test.plate.1.A3'],
                              [Well(3217), '1.SKB1.640202.Test.plate.1.A4'],
                              [Well(3265), '1.SKB1.640202.Test.plate.1.A5'],
                              [Well(3313), '1.SKB1.640202.Test.plate.1.A6'],
                              [Well(3361), '1.SKB1.640202.Test.plate.1.A7'],
                              [Well(3409), '1.SKB1.640202.Test.plate.1.A8'],
                              [Well(3457), '1.SKB1.640202.Test.plate.1.A9'],
                              [Well(3505), '1.SKB1.640202.Test.plate.1.A10'],
                              [Well(3553), '1.SKB1.640202.Test.plate.1.A11'],
                              [Well(3601), '1.SKB1.640202.Test.plate.1.A12']],
            '1.SKB2.640194': [[Well(3079), '1.SKB2.640194.Test.plate.1.B1'],
                              [Well(3127), '1.SKB2.640194.Test.plate.1.B2'],
                              [Well(3175), '1.SKB2.640194.Test.plate.1.B3'],
                              [Well(3223), '1.SKB2.640194.Test.plate.1.B4'],
                              [Well(3271), '1.SKB2.640194.Test.plate.1.B5'],
                              [Well(3319), '1.SKB2.640194.Test.plate.1.B6'],
                              [Well(3367), '1.SKB2.640194.Test.plate.1.B7'],
                              [Well(3415), '1.SKB2.640194.Test.plate.1.B8'],
                              [Well(3463), '1.SKB2.640194.Test.plate.1.B9'],
                              [Well(3511), '1.SKB2.640194.Test.plate.1.B10'],
                              [Well(3559), '1.SKB2.640194.Test.plate.1.B11'],
                              [Well(3607), '1.SKB2.640194.Test.plate.1.B12']],
            '1.SKB3.640195': [[Well(3085), '1.SKB3.640195.Test.plate.1.C1'],
                              [Well(3133), '1.SKB3.640195.Test.plate.1.C2'],
                              [Well(3181), '1.SKB3.640195.Test.plate.1.C3'],
                              [Well(3229), '1.SKB3.640195.Test.plate.1.C4'],
                              [Well(3277), '1.SKB3.640195.Test.plate.1.C5'],
                              [Well(3325), '1.SKB3.640195.Test.plate.1.C6'],
                              [Well(3373), '1.SKB3.640195.Test.plate.1.C7'],
                              [Well(3421), '1.SKB3.640195.Test.plate.1.C8'],
                              [Well(3469), '1.SKB3.640195.Test.plate.1.C9'],
                              [Well(3517), '1.SKB3.640195.Test.plate.1.C10'],
                              [Well(3565), '1.SKB3.640195.Test.plate.1.C11'],
                              [Well(3613), '1.SKB3.640195.Test.plate.1.C12']],
            '1.SKB4.640189': [[Well(3091), '1.SKB4.640189.Test.plate.1.D1'],
                              [Well(3139), '1.SKB4.640189.Test.plate.1.D2'],
                              [Well(3187), '1.SKB4.640189.Test.plate.1.D3'],
                              [Well(3235), '1.SKB4.640189.Test.plate.1.D4'],
                              [Well(3283), '1.SKB4.640189.Test.plate.1.D5'],
                              [Well(3331), '1.SKB4.640189.Test.plate.1.D6'],
                              [Well(3379), '1.SKB4.640189.Test.plate.1.D7'],
                              [Well(3427), '1.SKB4.640189.Test.plate.1.D8'],
                              [Well(3475), '1.SKB4.640189.Test.plate.1.D9'],
                              [Well(3523), '1.SKB4.640189.Test.plate.1.D10'],
                              [Well(3571), '1.SKB4.640189.Test.plate.1.D11'],
                              [Well(3619), '1.SKB4.640189.Test.plate.1.D12']],
            '1.SKB5.640181': [[Well(3097), '1.SKB5.640181.Test.plate.1.E1'],
                              [Well(3145), '1.SKB5.640181.Test.plate.1.E2'],
                              [Well(3193), '1.SKB5.640181.Test.plate.1.E3'],
                              [Well(3241), '1.SKB5.640181.Test.plate.1.E4'],
                              [Well(3289), '1.SKB5.640181.Test.plate.1.E5'],
                              [Well(3337), '1.SKB5.640181.Test.plate.1.E6'],
                              [Well(3385), '1.SKB5.640181.Test.plate.1.E7'],
                              [Well(3433), '1.SKB5.640181.Test.plate.1.E8'],
                              [Well(3481), '1.SKB5.640181.Test.plate.1.E9'],
                              [Well(3529), '1.SKB5.640181.Test.plate.1.E10'],
                              [Well(3577), '1.SKB5.640181.Test.plate.1.E11'],
                              [Well(3625), '1.SKB5.640181.Test.plate.1.E12']],
            '1.SKB6.640176': [[Well(3103), '1.SKB6.640176.Test.plate.1.F1'],
                              [Well(3151), '1.SKB6.640176.Test.plate.1.F2'],
                              [Well(3199), '1.SKB6.640176.Test.plate.1.F3'],
                              [Well(3247), '1.SKB6.640176.Test.plate.1.F4'],
                              [Well(3295), '1.SKB6.640176.Test.plate.1.F5'],
                              [Well(3343), '1.SKB6.640176.Test.plate.1.F6'],
                              [Well(3391), '1.SKB6.640176.Test.plate.1.F7'],
                              [Well(3439), '1.SKB6.640176.Test.plate.1.F8'],
                              [Well(3487), '1.SKB6.640176.Test.plate.1.F9'],
                              [Well(3535), '1.SKB6.640176.Test.plate.1.F10'],
                              [Well(3583), '1.SKB6.640176.Test.plate.1.F11']]
        }
        self.assertEqual(tester.duplicates, exp)
        self.assertEqual(tester.unknown_samples, [])
        exp = tester.get_well(1, 1)
        exp.composition.update('Unknown')
        self.assertEqual(tester.unknown_samples, [exp])
        exp.composition.update('1.SKB1.640202')

        # test that the quantification_processes attribute correctly
        # orders multiple processes in order from oldest to newest
        tester2 = Plate(26)
        self.assertEqual(len(tester2.quantification_processes), 2)
        # we are going to test the dates as string because in the database we
        # have the full date (including seconds)
        obs_date = str(tester2.quantification_processes[0].date)
        self.assertEqual(obs_date, "2017-10-25 19:10:25")
        obs_date = str(tester2.quantification_processes[1].date)
        self.assertEqual(obs_date, "2017-10-26 03:10:25")