def test_invalid_json_action(): input1 = {"act": "jump", "time": 100} input1_json = json.dumps(input1) actions = Actions(conn) with pytest.raises(KeyError): actions.add_action(input1_json)
def test_add_jump_action(): input1 = {"action": "jump", "time": 100} input1_json = json.dumps(input1) actions = Actions(conn) actions.add_action(input1_json) cur.execute("select count(*) from actions") result = cur.fetchone() count = result[0] assert count == 1
def test_get_stats(): input1 = {"action": "jump", "time": 100} input1_json = json.dumps(input1) input2 = {"action": "run", "time": 75} input2_json = json.dumps(input2) input3 = {"action": "jump", "time": 200} input3_json = json.dumps(input3) actions = Actions(conn) actions.add_action(input1_json) actions.add_action(input2_json) actions.add_action(input3_json) results_json = actions.get_stats() results = json.loads(results_json) jump_dict = list(filter(lambda dict: dict["action"] == "jump", results))[0] run_dict = list(filter(lambda dict: dict["action"] == "run", results))[0] assert jump_dict["avg"] == 150 assert run_dict["avg"] == 75