def test_limiter_login_fails(student_user: User): client = webapp.test_client() for _ in range(webapp.config['LIMITS_PER_MINUTE'] - 1): response = client.post('/login', data={ 'username': student_user.username, 'password': '******', }, follow_redirects=True) assert response.status_code == 200 client = webapp.test_client() response = client.post('/login', data={ 'username': student_user.username, 'password': '******', }, follow_redirects=True) assert response.status_code == 429
def get_logged_user(username: str) -> FlaskClient: client = webapp.test_client() client.post('/login', data={ # noqa: S106 'username': username, 'password': '******', }, follow_redirects=True) return client
def test_banned_user(banned_user: User): client = client = webapp.test_client() login_response = client.post('/login', data={ 'username': banned_user.username, 'password': '******', }, follow_redirects=True) assert 'banned' in login_response.get_data(as_text=True)
def test_login_password_fail(student_user: User): client = webapp.test_client() client.post('/login', data={ 'username': student_user.username, 'password': '******', }, follow_redirects=True) fail_login_response = client.get('/exercises') assert fail_login_response.status_code == 302
def test_login_success(student_user: User): client = webapp.test_client() client.post('/login', data={ 'username': student_user.username, 'password': '******', }, follow_redirects=True) success_login_response = client.get('/exercises') assert success_login_response.status_code == 200
def get_logged_user(username: str) -> FlaskClient: client = webapp.test_client() client.post( '/login', data=dict( # noqa: S106 username=username, password='******', ), follow_redirects=True, ) return client
def _send_git_request( self, username: str, method_name: str, url: str, data=None, service=None, password=conftest.FAKE_PASSWORD, ): client = webapp.test_client() encoded_credentials = base64.b64encode( f'{username}:{password}'.encode()).decode() headers = (('Authorization', f'Basic {encoded_credentials}'), ) query_string = {'service': service} if service is not None else None # patch the REPOSITORY_FOLDER to make new repository every test with mock.patch('lms.lmsweb.views.REPOSITORY_FOLDER', self.temp_folder): return getattr(client, method_name)(url, query_string=query_string, headers=headers, data=data)
def test_download_solution( self, exercise: Exercise, student_user: User, ): storage = self.create_zipfile_storage() hash_ = hashing.by_file(storage) conftest.create_solution( exercise=exercise, student_user=student_user, files=list(TestDownloadSolution.get_zip_files()), hash_=hash_, ) client = webapp.test_client() client.post( '/login', data=dict( # noqa: S106 username=student_user.username, password='******', ), follow_redirects=True, ) download_response = client.get('/download/1') downloaded_bytes_file = BytesIO(download_response.data) downloaded_zipfile = ZipFile(downloaded_bytes_file, 'r') exist_zipfile = ZipFile(self.zipfile_file, 'r') for exist_filename, downloaded_filename in zip( exist_zipfile.namelist(), downloaded_zipfile.namelist(), ): assert exist_filename == downloaded_filename with exist_zipfile.open(exist_filename, 'r') as exist_file: with downloaded_zipfile.open( downloaded_filename, 'r', ) as downloaded_file: assert exist_file.read() == downloaded_file.read()
def client(): return webapp.test_client()
def test_limiter_login_refreshes(): client = webapp.test_client() for _ in range(webapp.config['LIMITS_PER_MINUTE'] + 1): response = client.get('/login') assert response.status_code == 200