+
+ _verify_instance_and_status(client, adm_instance_good, "NOT IN EFFECT", False)
+
+ # delete the instance
+ _delete_instance(client)
+
+ _verify_instance_and_status(client, adm_instance_good, "NOT IN EFFECT", True)
+
+ # instance should be totally gone after a few seconds
+ _instance_is_gone(client)
+
+ # delete the type
+ _delete_ac_type(client)
+
+
+def test_bad_instances(client, monkeypatch, adm_type_good):
+ """
+ test various failure modes
+ """
+ # put the type (needed for some of the tests below)
+ rmr_mocks.patch_rmr(monkeypatch)
+ res = client.put(ADM_CTRL_TYPE, json=adm_type_good)
+ assert res.status_code == 201
+
+ # bad body
+ res = client.put(ADM_CTRL_INSTANCE, json={"not": "expected"})
+ assert res.status_code == 400
+
+ # bad media type
+ res = client.put(ADM_CTRL_INSTANCE, data="notajson")
+ assert res.status_code == 415
+
+ # delete a non existent instance
+ res = client.delete(ADM_CTRL_INSTANCE + "DARKNESS")
+ assert res.status_code == 404
+
+ # get a non existent instance
+ a1rmr.replace_rcv_func(_fake_dequeue)
+ res = client.get(ADM_CTRL_INSTANCE + "DARKNESS")
+ assert res.status_code == 404
+
+ # delete the type (as cleanup)
+ res = client.delete(ADM_CTRL_TYPE)
+ assert res.status_code == 204
+
+ # test 503 handlers
+
+ def monkey_set(ns, key, value):
+ # set a key override function that throws sdl errors on certain keys
+ if key == "a1.policy_type.111":
+ raise RejectedByBackend()
+ if key == "a1.policy_type.112":
+ raise NotConnected()
+ if key == "a1.policy_type.113":
+ raise BackendError()
+
+ monkeypatch.setattr("a1.data.SDL.set", monkey_set)
+
+ res = client.put("/a1-p/policytypes/111", json=adm_type_good)
+ assert res.status_code == 503
+ res = client.put("/a1-p/policytypes/112", json=adm_type_good)
+ assert res.status_code == 503
+ res = client.put("/a1-p/policytypes/113", json=adm_type_good)
+ assert res.status_code == 503
+
+
+def test_illegal_types(client, adm_type_good):
+ """
+ Test illegal types
+ """
+ res = client.put("/a1-p/policytypes/0", json=adm_type_good)
+ assert res.status_code == 400
+ res = client.put("/a1-p/policytypes/2147483648", json=adm_type_good)
+ assert res.status_code == 400
+
+
+def test_healthcheck(client):
+ """
+ test healthcheck
+ """
+ res = client.get("/a1-p/healthcheck")
+ assert res.status_code == 200
+
+
+def teardown_module():
+ """module teardown"""
+ a1rmr.stop_rmr_thread()