test/
– Testing¶
Note
To run tests you need to install python dependencies with pip install -r requirements.txt
and pug client with npm install pug
.
- run tests:
pytest tests
Writing tests¶
Every new feature need to be tested. All tests are located in test/
, and this have the same project structure than src/
, but all names are preceded by test_
.
At the beggining of every test, set in global variables: filepath of .pug
source file to test and directory located in.
The basic process of each test involves next steps:
- Create a
.pug
page inside project source directory that will be tested. This page must contains a mixin execution string and an include pointing to the mixins source code that will be tested (in the same folder). Seepug_utils.create_pug_page()
. - Renderize created pug page and test HTML output.
- If possible, test web endpoints (see
http_utils
below).
Fixtures¶
Pytest fixtures are inyected from test/conftest.py
and located at test/_fixtures/
.
pug_utils.py
¶
-
pug_utils.
create_pug_page
(src, content, includes=[])¶ Creates a pug page with the content provided inserting includes to files in the same folder.
Parameters: Returns: src
parameter value.Return type:
http_utils.py
¶
-
class
http_utils.
Response
(text, status_code, url)¶ Represents HTTP response objects.
Parameters:
-
http_utils.
get
(url, timeout=10)¶ Performs a GET request giving an url as first parameter.
Parameters:
-
http_utils.
assert_200
(url)¶ Assert if requesting with GET an url this returns 200 status code.
Parameters: url (str) – Request url. Returns: Response object if is asserted True
.Return type: http_utils.Response
-
http_utils.
assert_403
(url)¶ Assert if requesting with GET an url this returns 403 HTTP error (Forbidden request).
Parameters: url (str) – Request url. Returns: Response object if is asserted True
.Return type: http_utils.Response
Global variables¶
Global tests variables are located at _fixtures/constests.py
module.
constests.py
¶
-
PUG_CLI_PATH
¶ Filepath of pug client.
-
*_DIR
You can get every directory path inside
src/
folder importing fromconftest.py
the uppercase name of a src folder following by_DIR
. For example, filepath ofsrc/code
is the value ofCODE_DIR
.