How to use _get_file method in avocado

Best Python code snippet using avocado_python

test_zipcontent.py

Source:test_zipcontent.py Github

copy

Full Screen

...68 zf.writestr(self.embedded_file_name, self.embedded_file_str)69 self.zip_file_base_url = "/{}/".format(self.filename)70 self.environ = {}71 setup_testing_defaults(self.environ)72 def _get_file(self, file_name, base_url=None, **kwargs):73 if base_url is None:74 base_url = self.zip_file_base_url75 self.environ["PATH_INFO"] = base_url + file_name76 self.environ.update(kwargs)77 return generate_zip_content_response(self.environ)78 def test_zip_file_url_reversal(self):79 from kolibri.utils.conf import OPTIONS80 path_prefix = OPTIONS["Deployment"]["ZIP_CONTENT_URL_PATH_PREFIX"]81 if path_prefix != "/":82 path_prefix = "/" + path_prefix83 file = LocalFile(id=self.hash, extension=self.extension, available=True)84 self.assertEqual(85 file.get_storage_url(),86 "{}content/zipcontent/{}/".format(path_prefix, self.filename),87 )88 def test_non_zip_file_url_reversal(self):89 file = LocalFile(id=self.hash, extension="otherextension", available=True)90 filename = file.get_filename()91 self.assertEqual(92 file.get_storage_url(),93 "/content/storage/{}/{}/{}".format(filename[0], filename[1], filename),94 )95 def test_zip_file_internal_file_access(self):96 # test reading the data from file #1 inside the zip97 response = self._get_file(self.test_name_1)98 self.assertEqual(next(response.streaming_content).decode(), self.test_str_1)99 # test reading the data from file #2 inside the zip100 response = self._get_file(self.test_name_2)101 self.assertEqual(next(response.streaming_content).decode(), self.test_str_2)102 def test_nonexistent_zip_file_access(self):103 bad_base_url = self.zip_file_base_url.replace(104 self.zip_file_base_url[20:25], "aaaaa"105 )106 response = self._get_file(self.test_name_1, base_url=bad_base_url)107 self.assertEqual(response.status_code, 404)108 def test_zip_file_nonexistent_internal_file_access(self):109 response = self._get_file("qqq" + self.test_name_1)110 self.assertEqual(response.status_code, 404)111 def test_non_allowed_file_internal_file_access(self):112 response = self._get_file(113 self.test_name_1, base_url=self.zip_file_base_url.replace("zip", "png")114 )115 self.assertEqual(response.status_code, 404)116 def test_not_modified_response_when_if_modified_since_header_set(self):117 response = self._get_file(118 self.test_name_1, HTTP_IF_MODIFIED_SINCE=caching_http_date119 )120 self.assertEqual(response.status_code, 304)121 def test_last_modified_set_on_response(self):122 response = self._get_file(self.test_name_1)123 self.assertIsNotNone(response.get("Last-Modified"))124 def test_expires_set_on_response(self):125 response = self._get_file(self.test_name_1)126 self.assertIsNotNone(response.get("Expires"))127 def test_content_security_policy_header_http_host(self):128 response = self._get_file(self.test_name_1, HTTP_HOST="testserver.com")129 self.assertEqual(130 response.get("Content-Security-Policy"),131 "default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob:",132 )133 def test_content_security_policy_header_server_name(self):134 self.environ.pop("HTTP_HOST")135 response = self._get_file(self.test_name_1, SERVER_NAME="testserver.com")136 self.assertEqual(137 response.get("Content-Security-Policy"),138 "default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob:",139 )140 @override_settings(USE_X_FORWARDED_HOST=True)141 def test_content_security_policy_header_forward_for(self):142 response = self._get_file(143 self.test_name_1,144 HTTP_X_FORWARDED_HOST="testserver:1234",145 )146 self.assertEqual(147 response.get("Content-Security-Policy"),148 "default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob:",149 )150 def test_access_control_allow_origin_header(self):151 response = self._get_file(self.test_name_1)152 self.assertEqual(response.get("Access-Control-Allow-Origin"), "*")153 response = self._get_file(self.test_name_1, REQUEST_METHOD="OPTIONS")154 self.assertEqual(response.get("Access-Control-Allow-Origin"), "*")155 def test_options_returns_empty(self):156 response = self._get_file(self.test_name_1, REQUEST_METHOD="OPTIONS")157 self.assertEqual(response.content.decode(), "")158 def test_x_frame_options_header(self):159 response = response = self._get_file(self.test_name_1)160 self.assertEqual(response.get("X-Frame-Options", ""), "")161 def test_access_control_allow_headers(self):162 headerval = "X-Penguin-Dance-Party"163 response = self._get_file(164 self.test_name_1,165 REQUEST_METHOD="OPTIONS",166 HTTP_ACCESS_CONTROL_REQUEST_HEADERS=headerval,167 )168 self.assertEqual(response.get("Access-Control-Allow-Headers", ""), headerval)169 response = self._get_file(170 self.test_name_1,171 HTTP_ACCESS_CONTROL_REQUEST_HEADERS=headerval,172 )173 self.assertEqual(response.get("Access-Control-Allow-Headers", ""), headerval)174 def test_request_for_html_no_head_return_hashi_modified_html(self):175 response = self._get_file("")176 self.assertEqual(response.content.decode("utf-8"), empty_content)177 def test_request_for_html_body_no_script_return_hashi_modified_html(self):178 response = self._get_file(self.other_name)179 self.assertEqual(response.content.decode("utf-8"), empty_content)180 def test_request_for_html_body_script_return_hashi_modified_html(self):181 response = self._get_file(self.script_name)182 content = (183 "<html><head>{}<script>test</script></head><body></body></html>".format(184 hashi_injection185 )186 )187 self.assertEqual(response.content.decode("utf-8"), content)188 def test_request_for_html_body_script_with_extra_slash_return_hashi_modified_html(189 self,190 ):191 response = self._get_file("/" + self.script_name)192 content = (193 "<html><head>{}<script>test</script></head><body></body></html>".format(194 hashi_injection195 )196 )197 self.assertEqual(response.content.decode("utf-8"), content)198 def test_request_for_embedded_file_return_embedded_file(self):199 response = self._get_file(self.embedded_file_name)200 self.assertEqual(201 next(response.streaming_content).decode(), self.embedded_file_str202 )203 def test_request_for_embedded_file_with_double_slashes_return_embedded_file(self):204 response = self._get_file(self.embedded_file_name.replace("/", "//"))205 self.assertEqual(206 next(response.streaming_content).decode(), self.embedded_file_str207 )208 def test_request_for_html_doctype_return_with_doctype(self):209 response = self._get_file(self.doctype_name)210 content = response.content.decode("utf-8")211 self.assertEqual(212 content[:92].lower().replace(" ", " "), self.doctype.strip().lower()213 )214 def test_request_for_html5_doctype_return_with_doctype(self):215 response = self._get_file(self.html5_doctype_name)216 content = response.content.decode("utf-8")217 self.assertEqual(content[:15].lower(), self.html5_doctype.strip().lower())218 def test_request_for_html_body_script_return_correct_length_header(self):219 response = self._get_file(self.script_name)220 expected_content = (221 "<html><head>{}<script>test</script></head><body></body></html>".format(222 hashi_injection223 )224 )225 file_size = len(expected_content)226 self.assertEqual(int(response["Content-Length"]), file_size)227 def test_request_for_html_empty_html(self):228 response = self._get_file(self.empty_html_name)229 self.assertEqual(response.content.decode("utf-8"), empty_content)230 def test_not_modified_response_when_if_modified_since_header_set_index_file(self):231 response = self._get_file("", HTTP_IF_MODIFIED_SINCE=caching_http_date)232 self.assertEqual(response.status_code, 304)233 def test_not_modified_response_when_if_modified_since_header_set_other_html_file(234 self,235 ):236 response = self._get_file(237 self.other_name, HTTP_IF_MODIFIED_SINCE=caching_http_date238 )239 self.assertEqual(response.status_code, 304)240 def test_post_not_allowed(self):241 response = self._get_file(self.test_name_1, REQUEST_METHOD="POST")242 self.assertEqual(response.status_code, 405)243 def test_put_not_allowed(self):244 response = self._get_file(self.test_name_1, REQUEST_METHOD="PUT")245 self.assertEqual(response.status_code, 405)246 def test_patch_not_allowed(self):247 response = self._get_file(self.test_name_1, REQUEST_METHOD="PATCH")248 self.assertEqual(response.status_code, 405)249 def test_delete_not_allowed(self):250 response = self._get_file(self.test_name_1, REQUEST_METHOD="DELETE")251 self.assertEqual(response.status_code, 405)252@override_option("Deployment", "ZIP_CONTENT_URL_PATH_PREFIX", "prefix_test/")253class UrlPrefixZipContentTestCase(ZipContentTestCase):...

Full Screen

Full Screen

lahman.py

Source:lahman.py Github

copy

Full Screen

...26 z.extractall(cache.config.cache_directory)27 z = get_lahman_zip()28 # this way we'll now start using the extracted zip directory29 # instead of the session ZipFile object30def _get_file(tablename: str, quotechar: str = "'") -> pd.DataFrame:31 z = get_lahman_zip()32 f = f'{base_string}/{tablename}'33 data = pd.read_csv(34 f"{path.join(cache.config.cache_directory, f)}" if z is None else z.open(f),35 header=0,36 sep=',',37 quotechar=quotechar38 )39 return data40# do this for every table in the lahman db so they can exist as separate functions41def parks() -> pd.DataFrame:42 return _get_file('core/Parks.csv')43def all_star_full() -> pd.DataFrame:44 return _get_file("core/AllstarFull.csv")45def appearances() -> pd.DataFrame:46 return _get_file("core/Appearances.csv")47def awards_managers() -> pd.DataFrame:48 return _get_file("contrib/AwardsManagers.csv")49def awards_players() -> pd.DataFrame:50 return _get_file("contrib/AwardsPlayers.csv")51def awards_share_managers() -> pd.DataFrame:52 return _get_file("contrib/AwardsShareManagers.csv")53def awards_share_players() -> pd.DataFrame:54 return _get_file("contrib/AwardsSharePlayers.csv")55def batting() -> pd.DataFrame:56 return _get_file("core/Batting.csv")57def batting_post() -> pd.DataFrame:58 return _get_file("core/BattingPost.csv")59def college_playing() -> pd.DataFrame:60 return _get_file("contrib/CollegePlaying.csv")61def fielding() -> pd.DataFrame:62 return _get_file("core/Fielding.csv")63def fielding_of() -> pd.DataFrame:64 return _get_file("core/FieldingOF.csv")65def fielding_of_split() -> pd.DataFrame:66 return _get_file("core/FieldingOFsplit.csv")67def fielding_post() -> pd.DataFrame:68 return _get_file("core/FieldingPost.csv")69def hall_of_fame() -> pd.DataFrame:70 return _get_file("contrib/HallOfFame.csv")71def home_games() -> pd.DataFrame:72 return _get_file("core/HomeGames.csv")73def managers() -> pd.DataFrame:74 return _get_file("core/Managers.csv")75def managers_half() -> pd.DataFrame:76 return _get_file("core/ManagersHalf.csv")77def master() -> pd.DataFrame:78 # Alias for people -- the new name for master79 return people()80def people() -> pd.DataFrame:81 return _get_file("core/People.csv")82def pitching() -> pd.DataFrame:83 return _get_file("core/Pitching.csv")84def pitching_post() -> pd.DataFrame:85 return _get_file("core/PitchingPost.csv")86def salaries() -> pd.DataFrame:87 return _get_file("contrib/Salaries.csv")88def schools() -> pd.DataFrame:89 return _get_file("contrib/Schools.csv", quotechar='"') # different here bc of doublequotes used in some school names90def series_post() -> pd.DataFrame:91 return _get_file("core/SeriesPost.csv")92def teams_core() -> pd.DataFrame:93 return _get_file("core/Teams.csv")94def teams_upstream() -> pd.DataFrame:95 return _get_file("upstream/Teams.csv") # manually maintained file96def teams_franchises() -> pd.DataFrame:97 return _get_file("core/TeamsFranchises.csv")98def teams_half() -> pd.DataFrame:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful