def test_get_by_message_id(self, stub_broker, state_middleware, api_client): message_id = "2718281" state = State(message_id, StateNamesEnum.Pending, [], {}) state_middleware.backend.set_state(state, ttl=1000) res = api_client.get("/messages/state/{}".format(message_id)) assert res.json == state.asdict()
def test_get_state_by_name(self, name_state, stub_broker, state_middleware, api_client): state = State("3141516", name_state, [], {}) state_middleware.backend.set_state(state, ttl=1000) res = api_client.get("/messages/states?name={}".format( name_state.value)) assert res.json["result"] == [state.asdict()]
def test_get_states_by_name(self, n, stub_broker, state_middleware, api_client): # generate random test random_states = [] for i in range(n): random_state = State( "id{}".format(i), choice(list(StateNamesEnum)), # random state sample(range(1, 10), randint(0, 5)), # random args {str(i): str(i) for i in range(randint(0, 5))}, # random kwargs ) random_states.append(random_state.asdict()) state_middleware.backend.set_state(random_state, ttl=1000) # check storage res = api_client.get("/messages/states") states = res.json["result"] assert len(states) == n # check integrity for state in states: assert state in random_states