Skip to content

Latest commit

 

History

History
234 lines (180 loc) · 6.81 KB

File metadata and controls

234 lines (180 loc) · 6.81 KB

Test Suite Summary

Overview

A comprehensive test suite has been created for the DineWise restaurant ontology project. The tests cover all major functionality across all modules.

Test Files Created

1. tests/conftest.py - Shared Fixtures

  • Base ontology fixtures: Loads restaurant-ontology.owl
  • Updated ontology fixtures: Loads restaurant-ontology-updated.owl (if exists)
  • Test ontology fixture: Creates temporary in-memory ontologies for isolated testing
  • Sample data fixtures: Provides sample restaurant and dish data

2. tests/test_load_ontology.py - Ontology Loading Tests

Test Coverage:

  • ✅ Ontology file existence validation
  • ✅ Successful ontology loading
  • ✅ Required classes exist (Restaurant, Dish, Ingredient, Chef, etc.)
  • ✅ Cuisine subclasses (ItalianCuisine, IndianCuisine, etc.)
  • ✅ VegetarianDish defined class
  • ✅ Sample restaurant (MamasTrattoria) exists
  • ✅ Sample dish (MargheritaPizza) exists
  • ✅ Restaurant-dish relationships
  • ✅ Property access and validation
  • ✅ Error handling (file not found)

Total Tests: ~12 tests

3. tests/test_add_data.py - Data Addition Tests

Test Coverage:

  • ✅ Creating restaurant individuals
  • ✅ Setting restaurant properties (name, rating, price, address)
  • ✅ Creating dish individuals
  • ✅ Setting dish properties (name, price, vegetarian status, spiciness)
  • ✅ Creating chef individuals
  • ✅ Restaurant-dish relationships (serves)
  • ✅ Chef-restaurant relationships (worksAt)
  • ✅ Dish-chef relationships (preparedBy)
  • ✅ Restaurant-cuisine relationships (specializesIn)
  • ✅ Saving ontology to file
  • ✅ Loading saved ontology
  • ✅ Counting individuals after addition
  • ✅ Complete restaurant setup (restaurant + chef + multiple dishes)

Total Tests: ~15 tests

4. tests/test_reasoning_demo.py - Reasoning Tests

Test Coverage:

  • ✅ VegetarianDish class existence
  • ✅ Instance count before reasoning (should be 0)
  • ✅ Finding dishes with isVegetarian=True property
  • ✅ Reasoner execution without errors
  • ✅ Instance count after reasoning (should match vegetarian dishes)
  • ✅ Automatic classification of vegetarian dishes
  • ✅ Finding restaurants serving vegetarian dishes
  • ✅ Inferred classification persistence
  • ✅ Non-vegetarian dishes NOT classified
  • ✅ Complete reasoning flow integration
  • ✅ Reasoning with multiple restaurants

Total Tests: ~12 tests

5. tests/test_api.py - Flask API Tests

Test Coverage:

API Setup Tests

  • ✅ API file import without errors
  • ✅ API file exists

GET /api/restaurants Tests

  • ✅ Successful retrieval of all restaurants
  • ✅ Correct response structure (success, count, data)
  • ✅ Restaurant data structure (id, name, rating, avgPrice, address, cuisine)
  • ✅ Empty list handling

GET /api/restaurants/ Tests

  • ✅ Successful retrieval of specific restaurant
  • ✅ Restaurant includes dishes
  • ✅ 404 error for non-existent restaurant
  • ✅ Correct error response format

GET /api/recommend Tests

  • ✅ Successful recommendation response
  • ✅ Vegetarian filter
  • ✅ Max price filter
  • ✅ Min rating filter
  • ✅ Cuisine filter
  • ✅ Combined filters
  • ✅ Invalid parameter handling

GET /api/dishes/vegetarian Tests

  • ✅ Successful retrieval of vegetarian dishes
  • ✅ Correct data structure (name, price, restaurant, spiciness)

GET /api/health Tests

  • ✅ Health check success
  • ✅ Correct response structure
  • ✅ Correct counts

Error Handling Tests

  • ✅ Exception handling (500 errors)
  • ✅ CORS enabled

Total Tests: ~20 tests

Configuration Files

pytest.ini

  • Test discovery patterns
  • Output options (verbose, colors)
  • Test markers (unit, integration, slow, ontology, api)
  • Coverage configuration

.gitignore (Updated)

Added test-related artifacts:

  • .pytest_cache/
  • .coverage
  • htmlcov/
  • .tox/

requirements.txt (Updated)

Added testing dependencies:

  • pytest==7.4.3
  • pytest-cov==4.1.0
  • pytest-mock==3.12.0

Running Tests

Basic Commands

# Run all tests
pytest

# Run with verbose output
pytest -v

# Run specific test file
pytest tests/test_load_ontology.py

# Run specific test class
pytest tests/test_api.py::TestAPIRestaurantsEndpoint

# Run specific test function
pytest tests/test_api.py::TestAPIRestaurantsEndpoint::test_get_restaurants_success

# Run with coverage
pytest --cov=. --cov-report=html

# Run only unit tests
pytest -m unit

# Run only integration tests
pytest -m integration

Prerequisites

  1. Base Ontology: restaurant-ontology.owl must exist
  2. Updated Ontology (for some tests): Run python add_data.py first to create restaurant-ontology-updated.owl
  3. Dependencies: Install with pip install -r requirements.txt

Test Statistics

  • Total Test Files: 4
  • Total Test Classes: ~10
  • Total Test Functions: ~60+
  • Test Coverage: All major functionality covered

Test Categories

Unit Tests

  • Individual function testing
  • Mocked dependencies
  • Fast execution

Integration Tests

  • Complete workflow testing
  • Real ontology files
  • End-to-end scenarios

API Tests

  • Flask endpoint testing
  • Request/response validation
  • Error handling

Key Features

  1. Comprehensive Coverage: All modules and endpoints tested
  2. Isolated Testing: Each test is independent
  3. Fixtures: Shared setup/teardown logic
  4. Mocking: API tests use mocks for isolation
  5. Error Handling: Tests verify proper error responses
  6. Documentation: Well-documented test functions

Known Limitations

  1. Some integration tests require ontology files to exist
  2. API tests use mocking - may not catch all real-world edge cases
  3. Reasoner tests depend on Owlready2's internal implementation
  4. Some tests may skip if prerequisites are not met (using pytest.skip())

Next Steps

To improve test coverage further, consider:

  1. Performance Tests: Add tests for large ontologies
  2. Load Tests: Test API under load
  3. Edge Case Tests: More boundary condition testing
  4. Property Tests: Test with randomly generated data
  5. CI/CD Integration: Add tests to continuous integration pipeline

Example Test Output

$ pytest -v

tests/test_load_ontology.py::TestLoadOntology::test_ontology_file_exists PASSED
tests/test_load_ontology.py::TestLoadOntology::test_load_ontology_success PASSED
tests/test_add_data.py::TestAddData::test_add_restaurant_creates_individual PASSED
tests/test_reasoning_demo.py::TestReasoning::test_reasoner_runs_without_error PASSED
tests/test_api.py::TestAPIRestaurantsEndpoint::test_get_restaurants_success PASSED
...

========================= 60+ passed in 5.23s =========================

Support

For issues or questions about tests, refer to:

  • tests/README.md - Detailed test documentation
  • pytest.ini - Configuration options
  • tests/conftest.py - Available fixtures