How to use get_http method in gabbi

Best Python code snippet using gabbi_python

test_http.py

Source:test_http.py Github

copy

Full Screen

...5import requests6import pycurl7class CommonHttpTests(object):8 def test_successful_connection_sandbox(self):9 http = self.get_http(Environment.Sandbox)10 try:11 http.get("/")12 except AuthenticationError:13 pass14 else:15 self.assertTrue(False)16 def test_successful_connection_production(self):17 http = self.get_http(Environment.Production)18 try:19 http.get("/")20 except AuthenticationError:21 pass22 else:23 self.assertTrue(False)24 def test_unsafe_ssl_connection(self):25 Configuration.use_unsafe_ssl = True;26 environment = Environment(Environment.Sandbox.server, "443", "http://auth.venmo.dev:9292", True, Environment.Production.ssl_certificate)27 http = self.get_http(environment)28 try:29 http.get("/")30 except AuthenticationError:31 pass32 finally:33 Configuration.use_unsafe_ssl = False;34class TestPyCurl(CommonHttpTests, unittest.TestCase):35 def get_http(self, environment):36 config = Configuration(environment, "merchant_id", "public_key", "private_key")37 config._http_strategy = braintree.util.http_strategy.pycurl_strategy.PycurlStrategy(config, config.environment)38 return config.http()39 def test_unsuccessful_connection_to_good_ssl_server_with_wrong_cert(self):40 if platform.system() == "Darwin":41 return42 environment = Environment("www.google.com", "443", "http://auth.venmo.dev:9292", True, Environment.Production.ssl_certificate)43 http = self.get_http(environment)44 try:45 http.get("/")46 except pycurl.error, e:47 error_code, error_msg = e48 self.assertEquals(pycurl.E_SSL_CACERT, error_code)49 self.assertTrue(re.search('verif(y|ication) failed', error_msg))50 except AuthenticationError:51 self.fail("Expected to receive an SSL error but received an Authentication Error instead, check your local openssl installation")52 else:53 self.fail("Expected to receive an SSL error but no exception was raised")54 def test_unsuccessful_connection_to_ssl_server_with_wrong_domain(self):55 #ip address of api.braintreegateway.com56 environment = Environment("204.109.13.121", "443", "http://auth.venmo.dev:9292", True, Environment.Production.ssl_certificate)57 http = self.get_http(environment)58 try:59 http.get("/")60 except pycurl.error, e:61 error_code, error_msg = e62 self.assertEquals(pycurl.E_SSL_PEER_CERTIFICATE, error_code)63 self.assertTrue(re.search("SSL: certificate subject name", error_msg))64 else:65 self.fail("Expected to receive an SSL error but no exception was raised")66class TestRequests(CommonHttpTests, unittest.TestCase):67 if LooseVersion(requests.__version__) >= LooseVersion('1.0.0'):68 SSLError = requests.exceptions.SSLError69 else:70 SSLError = requests.models.SSLError71 def get_http(self, environment):72 config = Configuration(environment, "merchant_id", "public_key", "private_key")73 config._http_strategy = braintree.util.http_strategy.requests_strategy.RequestsStrategy(config, config.environment)74 return config.http()75 def test_unsuccessful_connection_to_good_ssl_server_with_wrong_cert(self):76 if platform.system() == "Darwin":77 return78 environment = Environment("www.google.com", "443", "http://auth.venmo.dev:9292", True, Environment.Production.ssl_certificate)79 http = self.get_http(environment)80 try:81 http.get("/")82 except self.SSLError, e:83 self.assertTrue("SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" in str(e.message))84 except AuthenticationError:85 self.fail("Expected to receive an SSL error but received an Authentication Error instead, check your local openssl installation")86 else:87 self.fail("Expected to receive an SSL error but no exception was raised")88 def test_unsuccessful_connection_to_ssl_server_with_wrong_domain(self):89 #ip address of api.braintreegateway.com90 environment = Environment("204.109.13.121", "443", "http://auth.venmo.dev:9292", True, Environment.Production.ssl_certificate)91 http = self.get_http(environment)92 try:93 http.get("/")94 except self.SSLError, e:95 pass96 else:...

Full Screen

Full Screen

exceptions.py

Source:exceptions.py Github

copy

Full Screen

1"""Exceptions for the crud operations."""2from typing import Dict, Tuple, Union3class ClassNotFound(Exception):4 """Error when the RDFClass is not found."""5 def __init__(self, type_: str) -> None:6 """Constructor."""7 self.type_ = type_8 def get_HTTP(self) -> Tuple[int, Dict[str, str]]:9 """Return the HTTP response for the Exception."""10 return 400, {11 "message": "The class {} is not a valid/defined RDFClass".format(self.type_)}12class InstanceNotFound(Exception):13 """Error when the Instance is not found."""14 def __init__(self, type_: str, id_: Union[str, None]=None) -> None:15 """Constructor."""16 self.type_ = type_17 self.id_ = id_18 def get_HTTP(self) -> Tuple[int, Dict[str, str]]:19 """Return the HTTP response for the Exception."""20 if str(self.id_) is None:21 return 404, {22 "message": "Instance of type {} not found".format(self.type_)}23 else:24 return 404, {"message": "Instance of type {} with ID {} not found".format(25 self.type_, str(self.id_))}26class PropertyNotFound(Exception):27 """Error when the Property is not found."""28 def __init__(self, type_: str) -> None:29 """Constructor."""30 self.type_ = type_31 def get_HTTP(self) -> Tuple[int, Dict[str, str]]:32 """Return the HTTP response for the Exception."""33 return 400, {34 "message": "The property {} is not a valid/defined Property".format(self.type_)}35class InstanceExists(Exception):36 """Error when the Instance already exists."""37 def __init__(self, type_: str, id_: Union[str, None]=None) -> None:38 """Constructor."""39 self.type_ = type_40 self.id_ = id_41 def get_HTTP(self) -> Tuple[int, Dict[str, str]]:42 """Return the HTTP response for the Exception."""43 if str(self.id_) is None:44 return 400, {45 "message": "Instance of type {} already exists".format(self.type_)}46 else:47 return 400, {"message": "Instance of type {} with ID {} already exists".format(48 self.type_, str(self.id_))}49class NotInstanceProperty(Exception):50 """Error when the property is not an Instance property."""51 def __init__(self, type_: str) -> None:52 """Constructor."""53 self.type_ = type_54 def get_HTTP(self) -> Tuple[int, Dict[str, str]]:55 """Return the HTTP response for the Exception."""56 return 400, {57 "message": "The property {} is not an Instance property".format(self.type_)}58class NotAbstractProperty(Exception):59 """Error when the property is not an Abstract property."""60 def __init__(self, type_: str) -> None:61 """Constructor."""62 self.type_ = type_63 def get_HTTP(self) -> Tuple[int, Dict[str, str]]:64 """Return the HTTP response for the Exception."""65 return 400, {66 "message": "The property {} is not an Abstract property".format(self.type_)}67class UserExists(Exception):68 """Error when the User already exitst."""69 def __init__(self, id_: int) -> None:70 """Constructor."""71 self.id_ = id_72 def get_HTTP(self) -> Tuple[int, Dict[str, str]]:73 """Return the HTTP response for the Exception."""74 return 400, {75 "message": "The user with ID {} already exists".format(self.id_)}76class UserNotFound(Exception):77 """Error when the User is not found."""78 def __init__(self, id_: int) -> None:79 """Constructor."""80 self.id_ = id_81 def get_HTTP(self) -> Tuple[int, Dict[str, str]]:82 """Return the HTTP response for the Exception."""83 return 400, {...

Full Screen

Full Screen

configHttp.py

Source:configHttp.py Github

copy

Full Screen

...3readconfig = readConfig.ReadConfig()4class configHttp:5 def __init__(self):6 global scheme, baseurl, port, timeout7 scheme = readconfig.get_http('scheme')8 baseurl = readconfig.get_http('baseurl')9 port = readconfig.get_http('port')10 timeout = readconfig.get_http('timeout')11 self.url = None12 self.headers = {}13 self.params = {}14 def set_all_url(self, url):15 self.url = url16 def set_url(self, url):17 self.url = scheme + '://' + baseurl + ':' + port + url18 def set_params(self, param):19 self.params = param20 def set_headers(self, headers):21 self.headers = headers22 def post(self, cookies=''):23 """24 定义 post...

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