def test_to_archive(self): info = { 'type_choice': 'transcript', 'directory_choices': 1, 'upload': (BytesIO(b'adawfaf'), 'filenamehere.txt') } self.client.post(url_for('login'), data={ 'email': '*****@*****.**', 'password': '******' }) current_user.delete_role() current_user.create_role("admin") self.client.post(url_for('index'), data=info, content_type='multipart/form-data') for num in range(1, 4): StageOneDownload.create_entry( User.get_user(num), StageOneUpload.get_file('filenamehere.txt', 'transcript')) self.client.get( url_for('to_archive', directory=fix_format(UPLOAD_FOLDER + upload_path["stageone"]), filename="filenamehere.txt", filetype="transcript")) self.assertTrue(StageOneArchive.select().count()) self.assertEquals(StageOneArchiveDownload.select().count(), 3) self.assertEquals(User.get_user(1), StageOneArchiveDownload.select().get().downloaded_by) self.assertTrue( os.path.isfile("{}{}[{}]{}".format(archive_path, upload_path['stageone'], 1, "filenamehere.txt")))
def test_admin_download_log_view(self): self.client.post(url_for('login'), data={ 'email': '*****@*****.**', 'password': '******' }) current_user.delete_role() current_user.create_role("admin") response = self.client.get(url_for('download_log')) self.assert200(response) self.assertEquals(self.get_context_variable("get_started"), User.select()) self.assertTemplateUsed('admin/downloads.html')
def test_admin_can_toggle_admin_confirmed_on_user(self): self.client.post(url_for('login'), data={ 'email': '*****@*****.**', 'password': '******' }) current_user.delete_role() current_user.create_role("admin") info = {'name': "tom"} response = self.client.post( url_for('toggle_admin_confirmed'), data=json.dumps(info), content_type='application/json;charset=UTF-8') self.assert200(response) self.assertEquals(current_user.username, response.json)
def test_delete_role(self): self.client.post(url_for('login'), data={ 'email': '*****@*****.**', 'password': '******' }) current_user.delete_role() current_user.create_role("admin") info = {"name": "mary"} self.assertTrue(User.get_user(2).get_role()) response = self.client.post( url_for('delete_role'), data=json.dumps(info), content_type='application/json;charset=UTF-8') self.assertFalse(User.get_user(2).get_role()) self.assert200(response)
def test_assign_role(self): self.client.post(url_for('login'), data={ 'email': '*****@*****.**', 'password': '******' }) current_user.delete_role() current_user.create_role("admin") self.assertEquals(User.get_user(2).get_role().role.name, "stageone") info = {"name": "mary", "role": "admin"} response = self.client.post( url_for('assign_role'), data=json.dumps(info), content_type='application/json;charset=UTF-8') self.assertEquals(User.get_user(2).get_role().role.name, "admin") self.assert200(response)
def test_confirm_and_assign(self): self.client.post(url_for('login'), data={ 'email': '*****@*****.**', 'password': '******' }) current_user.delete_role() current_user.create_role("admin") second_user = User.get_user(2) second_user.delete_role() self.assertFalse(second_user.get_role()) self.assertFalse(User.get_user(2).admin_confirmed) assigned_user = {"name": "mary", "role": "stageone"} response = self.client.post( url_for('confirm_assign'), data=json.dumps(assigned_user), content_type='application/json;charset=UTF-8') self.assert200(response) self.assertTrue(User.get_user(2).get_role()) self.assertTrue(User.get_user(2).admin_confirmed)
def test_admin_togglefile(self): self.client.post(url_for('login'), data={ 'email': '*****@*****.**', 'password': '******' }) current_user.delete_role() current_user.create_role("admin") file_info = { "name": "file1name", "fileType": "file1type", "directory": "stageone" } StageOneUpload.create_stage_entry(current_user.id, "file1name", "file1type", "stageone") response = self.client.post( url_for('toggle_file'), data=json.dumps(file_info), content_type='application/json;charset=UTF-8') self.assertEquals(response.json, "file1name")
def test_admin_can_register_users(self): user_info = { "username": "******", "email": "*****@*****.**", "password": "******", "password2": "password", "roles": "stageone" } self.client.post(url_for('login'), data={ 'email': '*****@*****.**', 'password': '******' }) failed_response = self.client.get(url_for('register_users')) self.assertRedirects(failed_response, url_for('index')) current_user.delete_role() current_user.create_role("admin") response = self.client.get(url_for('register_users')) self.assertTemplateUsed('admin/register.html') new_user = self.client.post(url_for('register_users'), data=user_info) self.assertMessageFlashed("User registered", "success") self.assertRedirects(new_user, url_for('register_users'))