Best Python code snippet using localstack_python
test_config.py
Source: test_config.py
2from contextlib import contextmanager3from typing import Any, Dict4from localstack import config5@contextmanager6def temporary_env(env: Dict[str, Any]):7 old = os.environ.copy()8 try:9 os.environ.update(env)10 yield os.environ11 finally:12 os.environ.clear()13 os.environ.update(old)14class TestProviderConfig:15 def test_provider_default_value(self):16 default_value = "default_value"17 override_value = "override_value"18 provider_config = config.ServiceProviderConfig(default_value=default_value)19 assert provider_config.get_provider("ec2") == default_value20 provider_config.set_provider("ec2", override_value)21 assert provider_config.get_provider("ec2") == override_value22 def test_provider_set_if_not_exists(self):23 default_value = "default_value"24 override_value = "override_value"25 provider_config = config.ServiceProviderConfig(default_value=default_value)26 provider_config.set_provider("ec2", default_value)27 provider_config.set_provider_if_not_exists("ec2", override_value)28 assert provider_config.get_provider("ec2") == default_value29 def test_provider_config_overrides(self, monkeypatch):30 default_value = "default_value"31 override_value = "override_value"32 provider_config = config.ServiceProviderConfig(default_value=default_value)33 monkeypatch.setenv("PROVIDER_OVERRIDE_EC2", override_value)34 provider_config.load_from_environment()35 assert provider_config.get_provider("ec2") == override_value36 assert provider_config.get_provider("sqs") == default_value37 monkeypatch.setenv("PROVIDER_OVERRIDE_SQS", override_value)38 provider_config.load_from_environment()39 assert provider_config.get_provider("sqs") == override_value40 def test_bulk_set_if_not_exists(self):41 default_value = "default_value"42 custom_value = "custom_value"43 override_value = "override_value"44 override_services = ["sqs", "sns", "lambda", "ec2"]45 provider_config = config.ServiceProviderConfig(default_value=default_value)46 provider_config.set_provider("ec2", default_value)47 provider_config.set_provider("lambda", custom_value)48 provider_config.bulk_set_provider_if_not_exists(override_services, override_value)49 assert provider_config.get_provider("sqs") == override_value50 assert provider_config.get_provider("sns") == override_value51 assert provider_config.get_provider("lambda") == custom_value52 assert provider_config.get_provider("ec2") == default_value53 assert provider_config.get_provider("kinesis") == default_value54class TestParseServicePorts:55 def test_returns_default_service_ports(self):56 result = config.parse_service_ports()57 assert result == config.DEFAULT_SERVICE_PORTS58 def test_with_service_subset(self):59 with temporary_env({"SERVICES": "s3,sqs"}):60 result = config.parse_service_ports()61 assert len(result) == 262 assert "s3" in result63 assert "sqs" in result64 assert result["s3"] == 456665 assert result["sqs"] == 456666 def test_custom_service_default_port(self):67 with temporary_env({"SERVICES": "foobar"}):68 result = config.parse_service_ports()69 assert len(result) == 170 assert "foobar" not in config.DEFAULT_SERVICE_PORTS71 assert "foobar" in result72 # foobar is not a default service so it is assigned 073 assert result["foobar"] == 074 def test_custom_port_mapping(self):75 with temporary_env({"SERVICES": "foobar", "FOOBAR_PORT": "1234"}):76 result = config.parse_service_ports()77 assert len(result) == 178 assert "foobar" not in config.DEFAULT_SERVICE_PORTS79 assert "foobar" in result80 assert result["foobar"] == 123481 def test_custom_illegal_port_mapping(self):82 with temporary_env({"SERVICES": "foobar", "FOOBAR_PORT": "asdf"}):83 result = config.parse_service_ports()84 assert len(result) == 185 assert "foobar" not in config.DEFAULT_SERVICE_PORTS86 assert "foobar" in result87 # FOOBAR_PORT cannot be parsed88 assert result["foobar"] == 089 def test_custom_port_mapping_in_services_env(self):90 with temporary_env({"SERVICES": "foobar:1235"}):91 result = config.parse_service_ports()92 assert len(result) == 193 assert "foobar" not in config.DEFAULT_SERVICE_PORTS94 assert "foobar" in result95 # FOOBAR_PORT cannot be parsed...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!