import pytest
import sys
import os

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app import app

@pytest.fixture
def client():
    app.config['TESTING'] = True
    with app.test_client() as client:
        yield client

def test_hello(client):
    """Test GET /hello endpoint"""
    response = client.get('/hello')
    assert response.status_code == 200
    data = response.get_json()
    assert data['message'] == 'Hello, World!'

def test_time(client):
    """Test GET /time endpoint"""
    response = client.get('/time')
    assert response.status_code == 200
    data = response.get_json()
    assert 'time' in data

def test_echo_post(client):
    """Test POST /echo endpoint"""
    test_data = {'name': 'test', 'value': 123}
    response = client.post('/echo', json=test_data)
    assert response.status_code == 200
    data = response.get_json()
    assert data['echo'] == test_data

def test_echo_no_body(client):
    """Test POST /echo with no body"""
    response = client.post('/echo', content_type='application/json')
    assert response.status_code == 400
