How to use resolve_uri method in autotest

Best Python code snippet using autotest_python

test_dict.py

Source: test_dict.py Github

copy

Full Screen

...95class TestResolveURI:96 @staticmethod97 def test_get_no_ref():98 uri = URI.from_string("base/​file1.json#/​definitions/​foo")99 data = resolve_uri(uri)100 assert data == {"type": "string"}101 @staticmethod102 def test_get_local_ref():103 local_ref_uri = URI.from_string(104 "base/​file1.json#/​definitions/​local_ref"105 )106 local_ref = resolve_uri(local_ref_uri)107 assert local_ref == {"type": "number"}108 @staticmethod109 def test_get_remote_ref():110 remote_ref_uri = URI.from_string(111 "base/​file1.json#/​definitions/​remote_ref"112 )113 remote_ref = resolve_uri(remote_ref_uri)114 assert remote_ref == {"type": "integer"}115 @staticmethod116 def test_get_remote_ref_cache_clear_reloads():117 remote_ref_uri = URI.from_string(118 "base/​file1.json#/​definitions/​remote_ref"119 )120 resolve_uri.cache_clear()121 with patch(f"{resolve_uri.__module__}.get_document") as mock_doc:122 mock_doc.side_effect = get_document123 _ = [resolve_uri(remote_ref_uri) for _ in range(3)]124 assert mock_doc.call_count == 2 # file1 and file2 loaded125 resolve_uri.cache_clear()126 remote_ref = resolve_uri(remote_ref_uri)127 assert mock_doc.call_count == 4128 assert remote_ref == {"type": "integer"}129 @staticmethod130 def test_get_backref():131 backref_uri = URI.from_string("base/​file1.json#/​definitions/​backref")132 backref = resolve_uri(backref_uri)133 assert backref == {"type": "null"}134 @staticmethod135 def test_get_nested_remote_ref():136 nested_remote_uri = URI.from_string(137 "base/​file1.json#/​definitions/​remote_nested/​foo"138 )139 nested_remote = resolve_uri(nested_remote_uri)140 assert nested_remote == {"type": "array"}141 @staticmethod142 def test_get_non_reference():143 non_ref_uri = URI.from_string("base/​nonref.json#/​definitions")144 non_ref = resolve_uri(non_ref_uri)145 assert non_ref["$ref"] == {"type": "string"}146 @staticmethod147 @pytest.mark.parametrize(148 "reference",149 [150 "base/​with-spaces.json#/​top/​with spaces",151 "base/​with-spaces.json#/​top/​with%20spaces",152 ],153 )154 def test_get_uri_with_spaces(reference: str):155 uri = URI.from_string(reference)156 result = resolve_uri(uri)157 assert result == {"foo": "bar"}158 @staticmethod159 @pytest.mark.parametrize(160 "base", ["base/​with-spaces.json", "base/​with-spaces-encoded.json"]161 )162 def test_get_ref_with_spaces(base: str):163 uri = URI.from_string(f"{base}#/​top/​ref to spaces/​foo")164 result = resolve_uri(uri)165 assert result == "bar"166 @staticmethod167 @pytest.mark.parametrize(168 "reference",169 [170 "base/​with-newline.json#/​top/​with\nnewline",171 "base/​with-newline.json#/​top/​with%0Anewline",172 ],173 )174 def test_get_uri_with_newline(reference: str):175 uri = URI.from_string(reference)176 result = resolve_uri(uri)177 assert result == {"foo": "bar"}178 @staticmethod179 @pytest.mark.parametrize(180 "base", ["base/​with-newline.json", "base/​with-newline-encoded.json"]181 )182 def test_get_ref_with_newline(base: str):183 uri = URI.from_string(f"{base}#/​top/​ref\nto\nnewline/​foo")184 result = resolve_uri(uri)185 assert result == "bar"186 @staticmethod187 @pytest.mark.parametrize("field", ["tilda", "slash", "percent"])188 def test_get_ref_with_escaped_chars(field: str):189 uri = URI.from_string(190 f"base/​with-escaped-chars.json#/​properties/​{field}"191 )192 result = resolve_uri(uri)193 assert result == {"type": "integer"}194class TestRefDict:195 @staticmethod196 @pytest.fixture(scope="class")197 def ref_dict():198 return RefDict(URI.from_string("base/​file1.json#/​definitions"))199 @staticmethod200 def test_load_dict_no_ref(ref_dict: RefDict):201 assert ref_dict["foo"] == {"type": "string"}202 @staticmethod203 def test_load_dict_local_ref(ref_dict: RefDict):204 assert ref_dict["local_ref"] == {"type": "number"}205 @staticmethod206 def test_load_dict_remote_ref(ref_dict: RefDict):...

Full Screen

Full Screen

test_servers.py

Source: test_servers.py Github

copy

Full Screen

...30 parse_request(req)31def test_resolve_uri_works_with_txt():32 """Test proper response with txt file."""33 from server import resolve_uri34 assert resolve_uri('/​sample.txt')[0] == 'text/​plain'35def test_resolve_uri_works_with_png():36 """Test proper URI resolution with PNG file."""37 from server import resolve_uri38 assert resolve_uri('/​images/​sample_1.png')[0] == 'image/​png'39def test_resolve_uri_works_with_jpg():40 """Test proper URI resolution with jpeg file."""41 from server import resolve_uri42 assert resolve_uri('/​images/​JPEG_example.jpg')[0] == 'image/​jpeg'43def test_resolve_uri_works_with_html():44 """Test proper URI resolution with html file."""45 from server import resolve_uri46 assert resolve_uri('/​a_web_page.html')[0] == 'text/​html'47def test_resolve_uri_works_with_python_file():48 """Test proper URI resolution with .py file."""49 from server import resolve_uri50 assert resolve_uri('/​make_time.py')[0] == 'text/​plain'51def test_resolve_uri_works_with_directory():52 """Test proper URI resolution with directory input."""53 from server import resolve_uri54 assert resolve_uri('/​images')[0] == 'text/​directory'55def test_resolve_uri_raises_415():56 """Test unsupported file type raises 415 error."""57 from server import resolve_uri58 with pytest.raises(TypeError):59 resolve_uri('/​images/​sample.bmp')60def test_resolve_uri_raises_404():61 """Test bad directory raises 404 error."""62 from server import resolve_uri63 with pytest.raises(IOError):64 resolve_uri('/​your_mom')65# Client side testing follows:66def test_client_sending_valid_request():67 """Test 200 ok response when client sends proper request."""68 from client import client69 assert client('sample.txt')[:15] == 'HTTP/​1.1 200 OK'70def test_client_receives_requested_content_type():71 """Test that client gets content of the requested type."""72 from client import client73 assert 'Content-Type: text/​plain' in client('sample.txt')74def test_client_receives_directory_list():75 """Test that client gets a listing of directory contents."""76 from client import client77 dir_list = ('<li>JPEG_example.jpg</​li>')78 assert dir_list in client('images/​')...

Full Screen

Full Screen

common.py

Source: common.py Github

copy

Full Screen

...27 def __exit__(self, exc_type, exc_val, exc_tb):28 pass29 def get_lines(self):30 return self.get().splitlines()31 def resolve_uri(self, uri: str) -> SimpleCall:32 uri = ensure_str(uri)33 slash = '/​'34 calling_map = {35 'get': SimpleCall(self.get),36 'get/​path': SimpleCall(self.get_path),37 'get/​lines': SimpleCall(self.get_lines),38 'set': SimpleCall(self.set)39 }40 pr = urlparse(uri)41 if pr.scheme not in ('clip', 'clipboard'):42 raise ClipboardURIError('invalid scheme', pr.scheme)43 if pr.netloc not in ('', 'localhost'):44 raise NotImplementedError('remote clipboard')45 if pr.params or pr.query:46 raise NotImplementedError('URL parameters & query string')47 entry = pr.path.strip(slash)48 if entry in calling_map:49 return calling_map[entry]50 else:51 raise NotImplementedError('URI path entry', entry)52 def check_uri(self, uri: str):53 uri = ensure_str(uri)54 try:55 if self.resolve_uri(uri):56 return True57 except (ClipboardURIError, NotImplementedError):58 return False59 def uri_api(self, uri: str, *args, **kwargs):60 call = self.resolve_uri(uri)61 if args or kwargs:62 call.args = args63 call.kwargs = kwargs...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Scala Testing: A Comprehensive Guide

Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.

What Agile Testing (Actually) Is

So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.

How To Choose The Right Mobile App Testing Tools

Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools

A Complete Guide To CSS Houdini

As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????

Appium Testing Tutorial For Mobile Applications

The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.

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 autotest 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