Esempio n. 1
0
def test_api_response_error_from_external(monkeypatch):
    monkeypatch.setattr(
        'tic_tac_toe.api.requests',
        Mock(
            get=Mock(
                return_value=Mock(
                    status_code=502,
                    text='X'
                )
            )
        )
    )
    response = app.test_client().get('/winner_external?board=_________')
    assert response.status_code == 502
Esempio n. 2
0
def test_api_response_is_json(monkeypatch):
    monkeypatch.setattr(
        'tic_tac_toe.api.requests',
        Mock(
            get=Mock(
                return_value=Mock(
                    status_code=200,
                    text='X'
                )
            )
        )
    )
    response = app.test_client().get('/winner_external?board=_________')
    assert response.status_code == 200
    assert response.content_type == 'application/json'
    assert isinstance(response.json, dict)
    assert 'winner' in response.json
Esempio n. 3
0
def test_api_missing_parameter():
    assert app.test_client().get('/winner_external').status_code == 400
Esempio n. 4
0
def test_api_response_is_json():
    response = app.test_client().get('/winner?board=_________')
    assert response.status_code == 200
    assert response.content_type == 'application/json'
    assert isinstance(response.json, dict)
    assert 'winner' in response.json
Esempio n. 5
0
def test_api_missing_parameter():
    assert app.test_client().get("/winner").status_code == 400
Esempio n. 6
0
def test_api_unfinished_game():
    response = app.test_client().get("/winner?board=X_____O__")
    assert response.status_code == 200 and response.json["winner"] is None
Esempio n. 7
0
def test_api_3x_in_a_row():
    response = app.test_client().get("/winner?board=XXX_O_O__")
    assert response.status_code == 200 and response.json["winner"] == "X"
Esempio n. 8
0
def test_api_response_is_json():
    response = app.test_client().get("/winner?board=_________")
    assert response.status_code == 200
    assert response.content_type == "application/json"
    assert isinstance(response.json, dict)
    assert "winner" in response.json