<commit_before>Test Suite
##############################################################################

.. contents:: Contents
  :local:


Running the Test Suite
==============================================================================

``./csu dev test`` will run the entire test suite. For a full list of test commands available, see :doc:`../getting_started/helper_commands`.


Structure
==============================================================================

The ``tests/`` directory is in the ``csunplugged/`` directory (at the same
level as the apps) and is structured as follows:

.. code-block:: none
      
  └── tests/
      ├── general/
      │   ├── management/
      │   ├── templatetags/
      │   ├── urls/
      │   └── views/
      ├── resources/
      │   ├── loaders/
      │   ├── models/
      │   ├── resource/
      │   ├── urls/
      │   ├── views/
      │   └── ResourcesTestDataGenerator.py
      ├── topics/
      │   ├── loaders/
      │   │   └── assets/
      │   ├── models/
      │   ├── urls/
      │   ├── views/
      │   └── TopicsTestDataGenerator.py
      ├── utils
      │   └── errors/
      └── BaseTestWithDB.py

Note that each app being tested has it's own folder, and this is then broken down further into the component being tested (i.e. views, urls, models, etc).

Items of interest from this diagram:

- ``models/`` - contains a test file for each model in the app.

- ``urls/`` - contains a test file for each url in the app.

- ``views/`` - contains a test file for each view in the app.

- ``loaders/`` - contains a test file for each loader in the app as well as an
  ``assets/`` directory. Test yaml files should be saved in the corresponding loader directory within ``assets/`` and should mimick the folder structure of the app where necessary.

- Test Data Generators - these are classes used to generate place holder data in
  the database. You should use the methods in these files when testing a model that contains a foreign key and/or many-to-many field that needs to be
  populated.

- ``BaseTestWithDB.py`` - this class inherits the Django ``TestCase`` class, and
  creates and logs in a user. This is the base test class that all other tests
  should inherit from in order to interact with the database.

- ``utils/errors/`` - contains test error classes for testing exceptions are
  raised correctly by the loaders.

Adding Tests
==============================================================================

When writing a new test function, it is important that the method name is as 
descriptive as possible. The method name should also be prefixed with ``test_``
as the test suite will only execute methods with this prefix.

.. note::

  We use `Codecov`_ to check the coverage of our tests. Every Pull Request should
  increase the overall coverage, Travis will fail if this is not the case.


.. _Codecov: https://codecov.io/gh<commit_msg>Minor rewording re PR comments.<commit_after>Test Suite
##############################################################################

.. contents:: Contents
  :local:


Running the Test Suite
==============================================================================

``./csu dev test`` will run the entire test suite. For running a specific tests, viewing code coverage, and more testing commands, see :doc:`../getting_started/helper_commands`.


Structure
==============================================================================

All tests are in the ``tests/`` directory, which in the ``csunplugged/`` directory (at the same level as the apps). It is structured as follows:

.. code-block:: none
      
  └── tests/
      ├── general/
      │   ├── management/
      │   ├── templatetags/
      │   ├── urls/
      │   └── views/
      ├── resources/
      │   ├── loaders/
      │   ├── models/
      │   ├── resource/
      │   ├── urls/
      │   ├── views/
      │   └── ResourcesTestDataGenerator.py
      ├── topics/
      │   ├── loaders/
      │   │   └── assets/
      │   ├── models/
      │   ├── urls/
      │   ├── views/
      │   └── TopicsTestDataGenerator.py
      ├── utils
      │   └── errors/
      └── BaseTestWithDB.py

Note that each app being tested has it's own folder, and this is then broken down further into the component being tested (i.e. views, urls, models, etc).

Items of interest from this diagram:

- ``models/`` - contains a test file for each model in the app.

- ``urls/`` - contains a test file for each url in the app.

- ``views/`` - contains a test file for each view in the app.

- ``loaders/`` - contains a test file for each loader in the app as well as an
  ``assets/`` directory. Test yaml files should be saved in the corresponding loader directory within ``assets/`` and should mimick the folder structure of the app where necessary.

- Test Data Generators - these are classes used to generate place holder data in
  the database. You should use the methods in these files when testing a model that contains a foreign key and/or many-to-many field that needs to be
  populated.

- ``BaseTestWithDB.py`` - this class inherits the Django ``TestCase`` class, and
  creates and logs in a user. This is the base test class that all other tests
  should inherit from in order to interact with the database.

- ``utils/errors/`` - contains test error classes for testing exceptions are
  raised correctly by the loaders.

Adding Tests
==============================================================================

When writing a new test function, it is important that the method name is as 
descriptive as possible. The method name should also be prefixed with ``test_``
as the test suite will only execute methods with this prefix.

.. note::

  We use `Codecov`_ to check the coverage of our tests. Every Pull Request should
  cover 100% of the difference (therefore increasing coverage), Travis will fail if this is not the case.


.. _Codecov: https://codecov.io/
{'fraction_non_alphanumeric': 0.19375419744795164, 'fraction_numerical': 0.0005036937541974479, 'mean_word_length': 3.1454418928322894, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2347527', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1593, 'n_words': 777}