Skip to content

Conversation

@Mungaijoe
Copy link

📌 Utility Service Request tests

This PR introduces comprehensive unit tests for the core functionality of the Utility Service Request DocType in the utility_billing app. The goal is to ensure all critical business logic functions as expected, including validation, contract generation, customer creation, and sales document generation.


✅ What’s Covered

The following tests were added:

Test Method Description
test_validate_contract_dates_auto_sets_end_date Ensures end_date is auto-calculated correctly from start_date and contract_length_months.
test_on_submit_creates_customer_when_enabled Verifies that a customer is automatically created upon submit when enabled in settings.
test_create_contract_success Confirms a valid Contract document is created and correctly linked to the service request.
test_get_utility_bill_structure_details_returns_items Asserts that item details are fetched from the selected utility bill structure.
test_create_sales_order_doc_creates_order_successfully Validates successful creation of a Sales Order from a service request, with correct customer linkage.
test_create_sales_invoice_doc_creates_invoice_successfully Validates successful creation of a Sales Invoice from a service request, with correct customer linkage.

🧪 Test Design Considerations

  • Fixtures Setup (setUp)

    • Creates test Customer, Item, and Utility Bill Structure records.
    • Tracks inserted documents in self.created_docs for cleanup.
  • Clean Teardown (tearDown)

    • Deletes all documents created during tests using frappe.delete_doc.
    • Performs frappe.db.rollback() to ensure test isolation.
  • Reusable Helper

    • create_utility_service_request() simplifies creation of a consistent base document with optional overrides.
  • Test Isolation

    • Each test runs independently and does not rely on state from others.
  • DocStrings

    • Each test contains docstrings for better understanding.

🛠 How to Run Tests

From your Frappe bench directory:

bench --site [your-site-name] run-tests --doctype "Utility Service Request"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant