Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_action_needs_a_name():
step = {
"action": {
"parameters": {
"name": "cherrypy-webapp"
}
}
}
with pytest.raises(InvalidPlan) as excinfo:
apply_action(step, layers)
assert "action requires a name" in str(excinfo)
def test_json_encoder_failure():
class Dummy:
pass
with pytest.raises(TypeError) as x:
encoder(Dummy())
def test_encode_decimal():
d = decimal.Decimal("6.7")
doc = json.dumps({"d": d}, default=encoder)
assert str(d) in doc
def test_json_encoder_decimal():
d = Decimal('1.38')
assert encoder(d) == '1.38'
def test_json_encoder_datetime():
now = datetime.utcnow()
assert encoder(now) == now.isoformat()
def test_json_encoder_uuid():
u = uuid.uuid4()
assert encoder(u) == str(u)
def test_encode_date_and_datetime():
now = datetime.now()
utcnow = datetime.utcnow()
today = datetime.today()
d = {"now": now, "utcnow": utcnow, "today": today}
doc = json.dumps(d, default=encoder)
assert now.isoformat() in doc
assert utcnow.isoformat() in doc
assert today.isoformat() in doc
def test_unhealthy_system_should_be_reported():
step = {
"layer": "fixtures.failing_probe_backend",
"name": "all-microservices-healthy"
}
with pytest.raises(FailedProbe) as excinfo:
microservices_all_healthy(step, layers[step["layer"]])
"layer": "fixtures.failing_probe_backend",
"name": "microservice-available-and-healthy"
}
with pytest.raises(InvalidProbe) as excinfo:
microservice_available_and_healthy(step, layers[step["layer"]])
step = {
"layer": "fixtures.failing_probe_backend",
"name": "microservice-available-and-healthy",
"parameters": {
"name": "cherrypy-webapp"
}
}
with pytest.raises(FailedProbe) as excinfo:
microservice_available_and_healthy(step, layers[step["layer"]])
assert "microservice 'cherrypy-webapp' is not healthy" in str(excinfo)
def test_version_is_not_newer(requests):
requests.get.return_value = FakeResponse(
200,
"https://releases.chaostoolkit.org/latest",
{"version": __version__, "up_to_date": True}
)
latest_version = check_newer_version(command="init")
assert latest_version is None