Best Python code snippet using localstack_python
test_security.py
Source:test_security.py  
...1415@responses.activate16def test_get_encrypted_password():17    data = PASSWORD.dict()18    data["password"] = PASSWORD.password.get_secret_value()19    responses.add(20        responses.GET, f"{URL}/api/security/encryptedPassword", json=data, status=20021    )2223    artifactory_security = ArtifactorySecurity(AuthModel(url=URL, auth=AUTH))24    enc_pass = artifactory_security.get_encrypted_password()25    assert enc_pass.password.get_secret_value() == PASSWORD.password.get_secret_value()262728@responses.activate29def test_create_api_key():30    data = API_KEY.dict()31    data["apiKey"] = API_KEY.apiKey.get_secret_value()32    responses.add(responses.POST, f"{URL}/api/security/apiKey", json=data, status=200)3334    artifactory_security = ArtifactorySecurity(AuthModel(url=URL, auth=AUTH))35    api_key = artifactory_security.create_api_key()36    assert api_key.apiKey.get_secret_value() == API_KEY.apiKey.get_secret_value()373839@responses.activate40def test_regenerate_api_key():41    data = API_KEY.dict()42    data["apiKey"] = API_KEY.apiKey.get_secret_value()43    responses.add(responses.PUT, f"{URL}/api/security/apiKey", json=data, status=200)4445    artifactory_security = ArtifactorySecurity(AuthModel(url=URL, auth=AUTH))46    api_key = artifactory_security.regenerate_api_key()47    assert api_key.apiKey.get_secret_value() == API_KEY.apiKey.get_secret_value()484950@responses.activate51def test_get_api_key():52    data = API_KEY.dict()53    data["apiKey"] = API_KEY.apiKey.get_secret_value()54    responses.add(responses.GET, f"{URL}/api/security/apiKey", json=data, status=200)5556    artifactory_security = ArtifactorySecurity(AuthModel(url=URL, auth=AUTH))57    api_key = artifactory_security.get_api_key()58    assert api_key.apiKey.get_secret_value() == API_KEY.apiKey.get_secret_value()596061@responses.activate62def test_revoke_api_key():63    responses.add(responses.DELETE, f"{URL}/api/security/apiKey", status=200)6465    artifactory_security = ArtifactorySecurity(AuthModel(url=URL, auth=AUTH))66    artifactory_security.revoke_api_key()676869@responses.activate70def test_revoke_user_api_key():71    responses.add(responses.DELETE, f"{URL}/api/security/apiKey/test_user", status=200)72
...test_secretsmanager.py
Source:test_secretsmanager.py  
...4from botocore.exceptions import ClientError5from kolvir.aws import secretsmanager6class StubException(Exception):7    pass8def test_get_secret_value():9    secret_id = "get_secret_value"10    secret_data = {"secret": "data"}11    with pytest.raises(secretsmanager.AwsNotFoundException):12        secret = secretsmanager.get_secret_value(secret_id)13    secretsmanager.put_secret_value(secret_id, secret_data)14    secret = secretsmanager.get_secret_value(secret_id)15    assert secret["secret"] == "data"16    with patch("kolvir.aws.secretsmanager.get_client") as client:17        client.return_value.exceptions.ResourceNotFoundException = StubException18        client.return_value.get_secret_value.side_effect = ClientError(19            {"Error": {"Code": 429}}, "test"20        )21        with pytest.raises(secretsmanager.AwsException):22            secretsmanager.get_secret_value(secret_id)23    secretsmanager.put_secret_value(secret_id, "data")24    assert secretsmanager.get_secret_value(secret_id) == "data"25def test_put_secret_value():26    secret_id = "put_secret_value"27    secret_data = {"secret": "data"}28    with pytest.raises(secretsmanager.AwsNotFoundException):29        secret = secretsmanager.get_secret_value(secret_id)30    secretsmanager.put_secret_value(secret_id, secret_data)31    secret = secretsmanager.get_secret_value(secret_id)32    assert secret["secret"] == "data"33    with patch("kolvir.aws.secretsmanager.get_client") as client:34        client.return_value.exceptions.ResourceNotFoundException = StubException35        client.return_value.put_secret_value.side_effect = ClientError(36            {"Error": {"Code": 429}}, "test"37        )38        with pytest.raises(secretsmanager.AwsException):39            secretsmanager.put_secret_value(secret_id, secret_data)40    secretsmanager.put_secret_value(secret_id, "data")41    assert secretsmanager.get_secret_value(secret_id) == "data"42def test_create_secret():43    secret_id = "create_secret"44    secret_data = {"secret": "data"}45    with pytest.raises(secretsmanager.AwsNotFoundException):46        secretsmanager.get_secret_value(secret_id)47    secretsmanager.create_secret(secret_id, secret_data)48    with pytest.raises(secretsmanager.AwsResourceExistsException):49        secretsmanager.create_secret(secret_id, secret_data)50    with patch("kolvir.aws.secretsmanager.get_client") as client:51        client.return_value.exceptions.ResourceExistsException = StubException52        client.return_value.create_secret.side_effect = ClientError(53            {"Error": {"Code": 429}}, "test"54        )55        with pytest.raises(secretsmanager.AwsException):...settings.py
Source:settings.py  
...9        env_prefix = "POSTGRES_"10    @property11    def url(self):12        return "postgresql://{user}:{password}@{host}:{port}/{database}".format(13            user=self.user.get_secret_value(),14            password=self.password.get_secret_value(),15            host=self.host.get_secret_value(),16            port=self.port.get_secret_value(),17            database=self.db.get_secret_value(),...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!!
