def testAddPIandUserToLab(self): userPI = setUpUser(self) lab = api.get_labs()[0] data = urlencode({ 'user': userPI.username, 'role': 1, 'redirect_url': ['/labs/5', '/labs/5'] }) self.client.post('/api/labs/' + str(lab['id']) + '/users/', data=data, content_type="application/x-www-form-urlencoded") user = setUpUser(self) lab = api.get_labs()[0] data = urlencode({ 'user': user.username, 'role': 0, 'redirect_url': ['/labs/5', '/labs/5'] }) self.client.post('/api/labs/' + str(lab['id']) + '/users/', data=data, content_type="application/x-www-form-urlencoded") userLabsPI = api.get_user_labs(userPI.id, is_principal_investigator=True) self.assertEqual(userLabsPI[0]['name'], 'test') userLabs = api.get_user_labs(user.id) self.assertEqual(userLabs[0]['name'], 'test')
def get(self, request, *args, **kwargs): user_id = kwargs['user_id'] if request.user.id != user_id: # Add next string to session if request.GET.get('next'): next = request.get_full_path().split('next=') request.session['next'] = next[1] viewing = {} if request.user.id != user_id and request.session.get('next'): viewing = uApi.get_viewing(request.session.get('next')) return render( request, 'users/user_details.html', { 'app_user': uApi.get_user(kwargs['user_id']), 'user_lab_list': api.get_user_labs(user_id), 'pi_user_lab_list': api.get_user_labs(user_id, is_principal_investigator=True), 'user_certs': api.get_user_certs_404(user_id), 'missing_cert_list': api.get_missing_certs(user_id), 'expired_cert_list': api.get_expired_certs(user_id), 'welcome_message': uApi.welcome_message(), 'viewing': viewing })
def get(self, request, *args, **kwargs): return render( request, 'areas/user_areas.html', { 'user_lab_list': api.get_user_labs(request.user.id), 'pi_user_lab_list': api.get_user_labs(request.user.id, is_principal_investigator=True) })
def user_report(request, user_id): """ Download user's report as PDF """ app_user = uApi.get_user(user_id) missing_cert_list = api.get_missing_certs(user_id) user_cert_list = api.get_user_certs(user_id) user_cert_ids = set([uc['id'] for uc in user_cert_list]) expired_cert_ids = set([ec['id'] for ec in api.get_expired_certs(user_id)]) user_lab_list = api.get_user_labs(user_id) user_labs = [] for user_lab in user_lab_list: lab_certs = api.get_lab_certs(user_lab['id']) missing_lab_certs = [] for lc in lab_certs: if lc['id'] not in user_cert_ids or lc['id'] in expired_cert_ids: missing_lab_certs.append(lc) user_labs.append((user_lab, lab_certs, missing_lab_certs)) for uc in user_cert_list: no_expiry_date = False if uc['completion_date'] == uc['expiry_date']: no_expiry_date = True uc['no_expiry_date'] = no_expiry_date return render_to_pdf( 'users/user_report.html', { 'app_user': app_user, 'user_labs': user_labs, 'user_cert_list': user_cert_list })
def testAddUserToLab(self): user = setUpUser(self) lab = api.get_labs()[0] data = urlencode({ 'user': user.username, 'role': 0, 'redirect_url': ['/labs/5', '/labs/5'] }) response = self.client.post( '/api/labs/' + str(lab['id']) + '/users/', data=data, content_type="application/x-www-form-urlencoded") self.assertEqual(response.status_code, 302) userLabs = api.get_user_labs(user.id) self.assertEqual(userLabs[0]['name'], 'test')
def testAddUserTo2Labs(self): user = setUpUser(self) lab1 = api.get_labs()[0] lab2 = api.get_labs()[1] data = urlencode({ 'user': user.username, 'role': 0, 'redirect_url': ['/labs/5', '/labs/5'] }) self.client.post('/api/labs/' + str(lab1['id']) + '/users/', data=data, content_type="application/x-www-form-urlencoded") self.client.post('/api/labs/' + str(lab2['id']) + '/users/', data=data, content_type="application/x-www-form-urlencoded") userLabs = api.get_user_labs(user.id) self.assertEqual(len(userLabs), 2)
def testSwitchToLabUser(self): user = api.get_user_by_username('admin') lab = api.get_labs()[0] data = urlencode({ 'user': user.username, 'role': 1, 'redirect_url': ['/labs/5', '/labs/5'] }) self.client.post('/api/labs/' + str(lab['id']) + '/users/', data=data, content_type="application/x-www-form-urlencoded") data = urlencode({'redirect_url': '/labs/3/'}) self.client.post('/api/users/' + str(user.id) + '/labs/' + str(lab['id']) + '/switch_lab_role/', data=data, content_type="application/x-www-form-urlencoded") self.assertEqual( len(api.get_user_labs(user.id, is_principal_investigator=True)), 0)
def testRemovePIFromLab(self): user = setUpUser(self) lab = api.get_labs()[0] data = urlencode({ 'user': user.username, 'role': 1, 'redirect_url': ['/labs/5', '/labs/5'] }) self.client.post('/api/labs/' + str(lab['id']) + '/users/', data=data, content_type="application/x-www-form-urlencoded") data = urlencode({'redirect_url': '/area/' + str(lab['id'])}) self.client.post('/api/users/' + str(user.id) + '/labs/' + str(lab['id']) + '/delete/', data=data, content_type="application/x-www-form-urlencoded") userLabs = api.get_user_labs(user.id) self.assertEqual(len(userLabs), 0)