def testUserMissingOneCert(self): user = api.get_user_by_username('bobjones2019') cert1 = api.get_certs()[0] cert2 = api.get_certs()[1] lab = api.get_labs()[0] data = urlencode({'cert': cert1['id'], 'redirect_url': '/labs/'}) self.client.post('/api/labs/' + str(lab['id']) + '/certificates/', data=data, content_type="application/x-www-form-urlencoded") data = urlencode({'cert': cert2['id'], 'redirect_url': '/labs/'}) self.client.post('/api/labs/' + str(lab['id']) + '/certificates/', data=data, content_type="application/x-www-form-urlencoded") data = urlencode({ 'redirect_url': '/users', 'user': user.username, 'role': 0 }) self.client.post('/api/labs/' + str(lab['id']) + '/users/', data=data, content_type="application/x-www-form-urlencoded") api.update_or_create_user_cert(user_id=user.id, cert_id=cert1['id'], cert_file='testCert.pdf', completion_date="2019-07-03", expiry_date="2019-07-03") missingCerts = api.get_missing_lab_certs(user.id, lab['id']) self.assertEqual(missingCerts[0]['name'], cert2['name'])
def testUserMissing2CertsFrom2Labs(self): user = api.get_user_by_username('bobjones2019') cert1 = api.get_certs()[0] cert2 = api.get_certs()[1] lab1 = api.get_labs()[0] lab2 = api.get_labs()[1] data = urlencode({'cert': cert1['id'], 'redirect_url': '/labs/'}) self.client.post('/api/labs/' + str(lab1['id']) + '/certificates/', data=data, content_type="application/x-www-form-urlencoded") data = urlencode({'cert': cert2['id'], 'redirect_url': '/labs/'}) self.client.post('/api/labs/' + str(lab2['id']) + '/certificates/', data=data, content_type="application/x-www-form-urlencoded") data = urlencode({ 'redirect_url': '/users', 'user': user.username, 'role': 0 }) self.client.post('/api/labs/' + str(lab1['id']) + '/users/', data=data, content_type="application/x-www-form-urlencoded") data = urlencode({ 'redirect_url': '/users', 'user': user.username, 'role': 0 }) self.client.post('/api/labs/' + str(lab2['id']) + '/users/', data=data, content_type="application/x-www-form-urlencoded") missingCerts = api.get_missing_certs(user.id) self.assertEqual(len(missingCerts), 2)
def test2Certs1Expired(self): data = urlencode({ 'name': 'testexpire', 'expiry_in_years': 1, 'redirect_url': '/certificates/' }) self.client.post('/api/certificates/', content_type="application/x-www-form-urlencoded", data=data) certexpired = list( filter(lambda x: x['name'] == 'testexpire', api.get_certs()))[0] cert = list( filter(lambda x: x['name'] != 'testexpire', api.get_certs()))[0] user = api.get_user_by_username('admin') api.update_or_create_user_cert(user_id=user.id, cert_id=certexpired['id'], cert_file='testCert.pdf', completion_date="2017-07-03", expiry_date="2018-07-03") api.update_or_create_user_cert(user_id=user.id, cert_id=cert['id'], cert_file='testCert.pdf', completion_date="2018-07-03", expiry_date="2018-07-03") expiredCerts = api.get_expired_certs(user.id) certsAll = api.get_user_certs(user.id) self.assertEqual(expiredCerts[0]['name'], 'testexpire') self.assertEqual(len(certsAll), 2)
def testDeleteCert(self): certs = api.get_certs() cert = certs[0] certNumber = len(certs) self.client.post('/api/certificates/' + str(cert['id']) + '/delete/') certs = api.get_certs() self.assertEqual(len(certs), certNumber - 1)
def testAdd2CertToUser(self): cert1 = api.get_certs()[0] cert2 = api.get_certs()[1] user = api.get_user_by_username('admin') api.update_or_create_user_cert(user_id=user.id, cert_id=cert1['id'], cert_file='testCert.pdf', completion_date="2019-07-03", expiry_date="2019-07-03") api.update_or_create_user_cert(user_id=user.id, cert_id=cert2['id'], cert_file='testCert.pdf', completion_date="2019-07-03", expiry_date="2019-07-03") userCert = api.get_user_certs(user.id) self.assertEqual(len(userCert), 2)
def testAddSameCertTwice(self): user = api.get_user_by_username('admin') cert = api.get_certs()[0] api.update_or_create_user_cert(user_id=user.id, cert_id=cert['id'], cert_file='testCert.pdf', completion_date="2017-07-03", expiry_date="2018-07-03") api.update_or_create_user_cert(user_id=user.id, cert_id=cert['id'], cert_file='testCert.pdf', completion_date="2017-07-03", expiry_date="2018-07-03") self.assertEqual(len(api.get_user_certs(user.id)), 1)
def testAddCertToLab(self): setUpLab(self) cert = api.get_certs()[0] lab = api.get_labs()[0] data = urlencode({ 'cert': cert['id'], 'redirect_url': ['/area/' + str(lab['id'])] }) response = self.client.post( '/api/labs/' + str(lab['id']) + '/certificates/', data=data, content_type="application/x-www-form-urlencoded") self.assertEqual(response.status_code, 302) labCerts = api.get_lab_certs(lab['id']) self.assertEqual(labCerts[0]['name'], 'testing')
def testUserMissingCerts(self): user = api.get_user_by_username('bobjones2019') cert = api.get_certs()[0] lab = api.get_labs()[0] data = urlencode({'cert': cert['id'], 'redirect_url': '/labs/'}) self.client.post('/api/labs/' + str(lab['id']) + '/certificates/', data=data, content_type="application/x-www-form-urlencoded") data = urlencode({ 'redirect_url': '/area/' + str(lab['id']), 'user': user.username, 'role': 0 }) 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) missingCerts = api.get_missing_lab_certs(user.id, lab['id']) self.assertEqual(missingCerts[0]['name'], 'testing')
def testAddCert(self): cert = api.get_certs()[0] self.assertEqual(cert['name'], 'testing') self.assertEqual(cert['expiry_in_years'], 0)