How to use _environment_by_version method in testcontainers-python

Best Python code snippet using testcontainers-python_python

elasticsearch.py

Source:elasticsearch.py Github

copy

Full Screen

...31 image_name, _FALLBACK_VERSION)32 return _FALLBACK_VERSION33 else:34 return int(regex_match.group(1))35def _environment_by_version(version: int) -> Dict[str, str]:36 """Returns environment variables required for each major version to work."""37 if version == 6:38 # This setting is needed to avoid the check for the kernel parameter39 # vm.max_map_count in the BootstrapChecks40 return {"discovery.zen.minimum_master_nodes": "1"}41 elif version == 7:42 return {}43 elif version == 8:44 # Elasticsearch uses https now by default. However, our readiness45 # check uses http, which does not work. Hence we disable security46 # which should not be an issue for our context47 return {"xpack.security.enabled": "false"}48 else:49 raise ValueError(f"Unknown elasticsearch version given: {version}")50class ElasticSearchContainer(DockerContainer):51 """52 ElasticSearch container.53 Example54 -------55 ::56 with ElasticSearchContainer() as es:57 connection_url = es.get_url()58 """59 def __init__(self, image="elasticsearch", port_to_expose=9200, **kwargs):60 super(ElasticSearchContainer, self).__init__(image, **kwargs)61 self.port_to_expose = port_to_expose62 self.with_exposed_ports(self.port_to_expose)63 self.with_env('transport.host', '127.0.0.1')64 self.with_env('http.host', '0.0.0.0')65 major_version = _major_version_from_image_name(image)66 for key, value in _environment_by_version(major_version).items():67 self.with_env(key, value)68 @wait_container_is_ready()69 def _connect(self):70 res = urllib.request.urlopen(self.get_url())71 if res.status != 200:72 raise Exception()73 def get_url(self):74 host = self.get_container_host_ip()75 port = self.get_exposed_port(self.port_to_expose)76 return 'http://{}:{}'.format(host, port)77 def start(self):78 super().start()79 self._connect()80 return self...

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 testcontainers-python 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