seitime-frappe/frappe/tests
David Arnold 4000cba810
fix: compat FrappeTestCase (#28367)
due to circular imports issues and me going out of my way to make it work 'cleanly', the previous backwards compatibility for FrappeTestCase unfortunately did not work on the manual cli test runner 'run-tests'

While not generally not affecting CI (which is precedented by the framwork's best practices to use 'run-parallel-test'), this broke some manual developer workflows

The restauration of FrappeTestCase in these scenario now unfortunately involves a plain copy of almost an entire implementation into the dumpster.

On the one hand, this doesn not accurately reflect the rather minuscule differences between IntegrationTestCase and FrappeTestCase, but on the other hand, it shields and freezes the old api should IntegrationTestCase evolve futher
2024-11-05 18:16:22 +01:00
..
classes chore(typing): fix some (exotic) type errors treewide (#28210) 2024-10-21 10:02:04 +00:00
data test: Add test for lazy_import 2022-08-11 23:53:21 +05:30
utils fix: compat FrappeTestCase (#28367) 2024-11-05 18:16:22 +01:00
__init__.py refactor: organize test contextmanagers (#28041) 2024-10-09 02:09:19 +02:00
README.md refactor: Structure frappe.test.utils (green to green) (#28038) 2024-10-08 15:10:24 +00:00
test_api.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_api_v2.py feat(APIv2): Add comment via REST API (#25889) 2024-04-10 10:53:22 +00:00
test_assign.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_auth.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_background_jobs.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_base_document.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_boilerplate.py test: adjust param for get_user_input_stream 2024-01-29 15:18:08 +01:00
test_boot.py refactor: organize test contextmanagers (#28041) 2024-10-09 02:09:19 +02:00
test_caching.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_child_table.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_client.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_commands.py refactor: Structure frappe.test.utils (green to green) (#28038) 2024-10-08 15:10:24 +00:00
test_config.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_cors.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_dashboard_connections.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_db.py test: add missing test case for get values on single (#28254) 2024-10-23 10:47:46 +02:00
test_db_query.py Merge pull request #28015 from marination/not-set-filter 2024-10-14 16:00:55 +05:30
test_db_update.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_defaults.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_deferred_insert.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_doc_ref.py chore(docref): fix circular imports (#28282) 2024-10-24 22:31:12 +02:00
test_docstatus.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_document.py refactor: organize test contextmanagers (#28041) 2024-10-09 02:09:19 +02:00
test_document_locks.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_document_ro_mode.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_domainification.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_dynamic_links.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_email.py refactor: clarify test record dep management in test modules (#28060) 2024-10-09 13:44:27 +00:00
test_exporter_fixtures.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_fixture_import.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_fmt_datetime.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_fmt_money.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_form_load.py refactor: clarify test record dep management in test modules (#28060) 2024-10-09 13:44:27 +00:00
test_formatter.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_frappe_client.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_geo_ip.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_global_search.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_goal.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_hooks.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_linked_with.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_listview.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_model_utils.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_modules.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_monitor.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_naming.py fix: Excessive gap locking from hash naming (#28349) 2024-11-01 06:18:22 +00:00
test_nestedset.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_non_nullable_docfield.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_oauth20.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_password.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_password_strength.py test: retry flaky password_strength test thrice 2023-12-20 13:57:48 +05:30
test_patches.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_pdf.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_perf.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_permissions.py refactor: clarify test record dep management in test modules (#28060) 2024-10-09 13:44:27 +00:00
test_printview.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_query.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_query_builder.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_query_report.py refactor: organize test contextmanagers (#28041) 2024-10-09 02:09:19 +02:00
test_rate_limiter.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_rating.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_recorder.py refactor: Structure frappe.test.utils (green to green) (#28038) 2024-10-08 15:10:24 +00:00
test_redis.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_rename_doc.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_reportview.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_safe_exec.py refactor: organize test contextmanagers (#28041) 2024-10-09 02:09:19 +02:00
test_scheduler.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_search.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_seen.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_sequence.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_sitemap.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_test_utils.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_trace.py refactor: organize test contextmanagers (#28041) 2024-10-09 02:09:19 +02:00
test_translate.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_twofactor.py refactor: organize test contextmanagers (#28041) 2024-10-09 02:09:19 +02:00
test_utils.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_virtual_doctype.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_webform.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
test_website.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
tests_geo_utils.py refactor: unit vs integration treewide (#27992) 2024-10-06 09:43:36 +00:00
translation_test_file.txt feat: allow splitting _() function call on multiple lines 2022-03-26 16:18:35 +05:30
ui_test_helpers.py fix(test): fix tests 2024-08-14 17:08:01 +05:30

Frappe Test Framework

This README provides an overview of the test case framework available in Frappe. These utilities are designed to facilitate efficient and effective testing of Frappe applications.

This is different from the frappe.testing module which houses the discovery and runner infrastructure for CLI and CI.

Directory Structure

The test framework is organized into the following structure:

frappe/tests/
├── classes/
│   ├── context_managers.py
│   ├── unit_test_case.py
│   └── ...
├── utils/
│   ├── generators.py
│   └── ...
├── test_api.py
├── test_child_table.py
└── ...

Key Components

  1. Test case classes (UnitTestCase and IntegrationTestCase)
  2. Framework and class specific context managers
  3. Utility functions and generators
  4. Specific test modules for various Frappe components

Test Case Classes

UnitTestCase (classes/unit_test_case.py)

Import convention: from frappe.tests import UnitTestCase

This class extends unittest.TestCase and provides additional utilities specific to the Frappe framework. It's designed for testing individual components or functions in isolation.

Key features include:

  • Custom assertions for Frappe-specific comparisons
  • Utilities for HTML and SQL normalization
  • Context managers for user switching and time freezing

IntegrationTestCase (classes/integration_test_case.py)

Import convention: from frappe.tests import IntegrationTestCase

This class extends UnitTestCase and is designed for integration testing. It provides features for:

  • Automatic site and connection setup
  • Automatic test records loading
  • Automatic reset of thread locals
  • Context managers that depend on a site connection
  • Asserts that depend on a site connection

For a detailed list of context managers, please refer to the code.

Utility Functions and Generators (utils/generators.py)

This module contains utility functions for generating test records and managing test data.

Specific Test Modules

Various test modules (e.g., test_api.py, test_document.py) contain tests for specific Frappe core components and functionalities.

Note that Document tests are collocated alongside each Document module.

Usage

To use these test utilities in your Frappe application tests, you can inherit from the appropriate test case class:

from frappe.tests import UnitTestCase

class MyTestCase(UnitTestCase):
    def test_something(self):
        # Your test code here
        pass

Contributing

When adding new test utilities or modifying existing ones:

  1. Place them in the appropriate directory based on their function.
  2. Update this README to reflect any significant changes in the framework structure or usage.
  3. Ensure that your changes follow the existing coding style and conventions.

Remember to always refer to the actual code for the most up-to-date and detailed information on available methods and their usage.