def post(self): email = self.get_argument('email') op = self.get_argument('operation') if op == 'grant': User(email).grant_access() elif op == 'revoke': User(email).revoke_access() else: raise HTTPError(400, 'Operation %s not recognized') self.finish()
def create_sequencing_process(user, pools): seq_process = SequencingProcess.create( user, pools, 'New sequencing run %s' % datetime.now(), 'Run experiment %s' % datetime.now(), Equipment(18), 151, 151, User('*****@*****.**'), contacts=[User('*****@*****.**'), User('*****@*****.**')]) return seq_process
def post(self, _): pools = self.get_argument('pools') run_name = self.get_argument('run_name') experiment = self.get_argument('experiment') sequencer_id = self.get_argument('sequencer') fwd_cycles = int(self.get_argument('fwd_cycles')) rev_cycles = int(self.get_argument('rev_cycles')) pi = self.get_argument('principal_investigator') contacts = self.get_argument('additional_contacts') pools = [PoolComposition(x) for x in json_decode(pools)] contacts = [User(x) for x in json_decode(contacts)] process = SequencingProcess.create(self.current_user, pools, run_name, experiment, Equipment(sequencer_id), fwd_cycles, rev_cycles, User(pi), contacts) self.write({'process': process.id})
def get_current_user(self): """Get the current connected user""" username = self.get_secure_cookie("user") if username is not None: # strip off quotes added by get_secure_cookie and decode # becuase it is stored as character varying in the DB return User(username.strip(b"\"' ").decode()) else: self.clear_cookie("user") return None
def test_grant_revoke_access(self): tester = User('*****@*****.**') with self.assertRaises(LabControlLoginDisabledError): User.login('*****@*****.**', 'password') tester.grant_access() obs = User.login('*****@*****.**', 'password') self.assertEqual(obs, tester) tester.revoke_access() with self.assertRaises(LabControlLoginDisabledError): User.login('*****@*****.**', 'password')
def integration_tests(): """Creates one amplicon and one shotgun workflow from plating to sequencing """ samples = get_samples() user = User('*****@*****.**') amplicon_seq_process = integration_tests_amplicon_workflow(user, samples) obs = amplicon_seq_process.generate_sample_sheet() res = re.match(EXP_AMPLICON_SAMPLE_SHEET, obs) if res is None: raise ValueError( 'Amplicon sample sheet does not match expected regex:\n%s' % obs)
def test_login(self): exp = User('*****@*****.**') obs = User.login('*****@*****.**', 'password') self.assertEqual(obs, exp) with self.assertRaises(LabControlUnknownIdError): User.login('*****@*****.**', 'password') with self.assertRaises(LabControlLoginError): User.login('*****@*****.**', 'wrongpassword') with self.assertRaises(LabControlLoginDisabledError): User.login('*****@*****.**', 'password')
def stress_tests(num_plates_amplicon, num_plates_shotgun, user): """Creates num_plates plates and complete the amplicon/shotgun workflow """ samples = get_samples() user = User(user) if num_plates_amplicon: stress_tests_amplicon_workflow(user, samples, num_plates=num_plates_amplicon) if num_plates_shotgun: stress_tests_shotgun_workflow(user, samples, num_plates=num_plates_shotgun)
def test_access_handler_post(self): tester = User('*****@*****.**') response = self.post('/auth/access/', {'email': '*****@*****.**', 'operation': 'grant'}) self.assertEqual(response.code, 200) self.assertEqual(User.login('*****@*****.**', 'password'), tester) response = self.post('/auth/access/', {'email': '*****@*****.**', 'operation': 'revoke'}) self.assertEqual(response.code, 200) with self.assertRaises(LabControlLoginDisabledError): User.login('*****@*****.**', 'password') response = self.post('/auth/access/', {'email': '*****@*****.**', 'operation': 'unknown'}) self.assertEqual(response.code, 400)
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
def test_attributes(self): s = Study(1) self.assertEqual( s.title, 'Identification of the Microbiomes ' 'for Cannabis Soils') self.assertEqual(s.creator, User('*****@*****.**')) self.assertEqual(s.num_samples, 27) exp = { 'num_samples': 27, 'number_samples_plated': 10, 'number_samples_extracted': 10, 'number_samples_amplicon_libraries': 10, 'number_samples_amplicon_pools': 10, 'number_samples_amplicon_sequencing_pools': 10, 'number_samples_amplicon_sequencing_runs': 10, 'number_samples_compressed': 10, 'number_samples_normalized': 10, 'number_samples_shotgun_libraries': 10, 'number_samples_shotgun_pool': 10, 'number_samples_shotgun_sequencing_runs': 10 } self.assertEqual(s.sample_numbers_summary, exp)
def test_get_previously_plated_wells(self): tester = Plate(21) three_plates_list = [Plate(27), Plate(30), Plate(33)] exp = { Well(3073): three_plates_list, Well(3079): three_plates_list, Well(3085): three_plates_list, Well(3091): three_plates_list, Well(3097): three_plates_list, Well(3103): three_plates_list, Well(3121): three_plates_list, Well(3127): three_plates_list, Well(3133): three_plates_list, Well(3139): three_plates_list, Well(3145): three_plates_list, Well(3151): three_plates_list, Well(3169): three_plates_list, Well(3175): three_plates_list, Well(3181): three_plates_list, Well(3187): three_plates_list, Well(3193): three_plates_list, Well(3199): three_plates_list, Well(3217): three_plates_list, Well(3223): three_plates_list, Well(3229): three_plates_list, Well(3235): three_plates_list, Well(3241): three_plates_list, Well(3247): three_plates_list, Well(3265): three_plates_list, Well(3271): three_plates_list, Well(3277): three_plates_list, Well(3283): three_plates_list, Well(3289): three_plates_list, Well(3295): three_plates_list, Well(3313): three_plates_list, Well(3319): three_plates_list, Well(3325): three_plates_list, Well(3331): three_plates_list, Well(3337): three_plates_list, Well(3343): three_plates_list, Well(3361): three_plates_list, Well(3367): three_plates_list, Well(3373): three_plates_list, Well(3379): three_plates_list, Well(3385): three_plates_list, Well(3391): three_plates_list, Well(3409): three_plates_list, Well(3415): three_plates_list, Well(3421): three_plates_list, Well(3427): three_plates_list, Well(3433): three_plates_list, Well(3439): three_plates_list, Well(3457): three_plates_list, Well(3463): three_plates_list, Well(3469): three_plates_list, Well(3475): three_plates_list, Well(3481): three_plates_list, Well(3487): three_plates_list, Well(3505): three_plates_list, Well(3511): three_plates_list, Well(3517): three_plates_list, Well(3523): three_plates_list, Well(3529): three_plates_list, Well(3535): three_plates_list, Well(3553): three_plates_list, Well(3559): three_plates_list, Well(3565): three_plates_list, Well(3571): three_plates_list, Well(3577): three_plates_list, Well(3583): three_plates_list, Well(3601): three_plates_list, Well(3607): three_plates_list, Well(3613): three_plates_list, Well(3619): three_plates_list, Well(3625): three_plates_list } obs = tester.get_previously_plated_wells() self.assertEqual(obs, exp) # Create another plate and put a sample on it that isn't anywhere else spp = SamplePlatingProcess.create(User('*****@*****.**'), PlateConfiguration(1), 'New Plate For Prev') spp.update_well(1, 1, '1.SKM1.640184') obs = spp.plate.get_previously_plated_wells() self.assertEqual(obs, {})
def setUp(self): super().setUp() self.user = User('*****@*****.**')
def test_attributes(self): tester = User('*****@*****.**') self.assertEqual(tester.name, 'Dude') self.assertEqual(tester.email, '*****@*****.**')
def test_init(self): with self.assertRaises(LabControlUnknownIdError): User('Dude')
def get_app(self): BaseHandler.get_current_user = Mock(return_value=User("*****@*****.**")) self.app.settings['debug'] = False return self.app