comparison doc/contribuing/testing.rst @ 3498:d78b5eae912a

tests: update following names change
author Goffi <goffi@goffi.org>
date Fri, 16 Apr 2021 18:32:34 +0200
parents b166a59b1724
children 4705f80b6e23
comparison
equal deleted inserted replaced
3497:73e04040d577 3498:d78b5eae912a
59 ``--keep-container`` and ``--keep-vnc``. 59 ``--keep-container`` and ``--keep-vnc``.
60 60
61 ``--dev-mode`` 61 ``--dev-mode``
62 Shortcut for ``--keep-containers``, ``--keep-profiles`` and ``--keep-vnc``. This is 62 Shortcut for ``--keep-containers``, ``--keep-profiles`` and ``--keep-vnc``. This is
63 useful, as you guess with its names, for development of tests. User can then log-in into 63 useful, as you guess with its names, for development of tests. User can then log-in into
64 the ``sat`` container, launch a Python console, and work with the automated browser in 64 the ``backend`` container, launch a Python console, and work with the automated browser in
65 real-time. Basic commands to launch a browser and log-in with test account are printed 65 real-time. Basic commands to launch a browser and log-in with test account are printed
66 at the end of the tests. Note that if you want to have profiles created, or extra tools 66 at the end of the tests. Note that if you want to have profiles created, or extra tools
67 like the fake SMTP server, you'll have to launch at least one test which require them. 67 like the fake SMTP server, you'll have to launch at least one test which require them.
68 To log-in into the ``sat`` container, you can use the following command, from 68 To log-in into the ``backend`` container, you can use the following command, from
69 ``/docker`` directory:: 69 ``/docker`` directory::
70 70
71 $ docker-compose -f docker-compose_e2e.yml exec sat /bin/bash 71 $ docker-compose -f docker-compose_e2e.yml exec backend /bin/bash
72 72
73 Then run a python console with given instructions 73 Then run a python console with given instructions
74 74
75 It's also good to know that in the e2e test environment, the following pytest plugins are 75 It's also good to know that in the e2e test environment, the following pytest plugins are
76 installed and used: 76 installed and used:
98 Here are the fixture common to all e2e tests which are good to know: 98 Here are the fixture common to all e2e tests which are good to know:
99 99
100 ``test_profiles`` 100 ``test_profiles``
101 Creates a bunch of test accounts which are available during the whole test session. 101 Creates a bunch of test accounts which are available during the whole test session.
102 Those account are destroyed once all the tests are finished (successful or not), except 102 Those account are destroyed once all the tests are finished (successful or not), except
103 if you set the ``SAT_TEST_E2E_KEEP_PROFILES`` environment variable (or use the 103 if you set the ``LIBERVIA_TEST_E2E_KEEP_PROFILES`` environment variable (or use the
104 ``--keep-profiles`` flag in ``run_e2e.py``. 104 ``--keep-profiles`` flag in ``run_e2e.py``.
105 105
106 The profiles created are in the form ``accountX`` for account on the ``server1.test``, 106 The profiles created are in the form ``accountX`` for account on the ``server1.test``,
107 or ``accountX_sY`` for account on other servers (see the docstring for details). 107 or ``accountX_sY`` for account on other servers (see the docstring for details).
108 108
125 125
126 ``fake_file.new_dest_file()`` will return a Path to a randomly named destination file, 126 ``fake_file.new_dest_file()`` will return a Path to a randomly named destination file,
127 and ``fake_file.get_dest_hash(dest_file_path)`` will generate its hash once written. 127 and ``fake_file.get_dest_hash(dest_file_path)`` will generate its hash once written.
128 128
129 ``sent_emails`` 129 ``sent_emails``
130 When used, a fake SMTP server (already configured in container's ``sat.conf``) will be 130 When used, a fake SMTP server (already configured in container's ``libervia.conf``) will be
131 launched if it's not already, and all messages sent to it since the beginning of the test 131 launched if it's not already, and all messages sent to it since the beginning of the test
132 will be available in the given list. Message are subclasses of 132 will be available in the given list. Message are subclasses of
133 ``email.message.EmailMessage`` with the extra properties ``from_``, ``to``, ``subject`` 133 ``email.message.EmailMessage`` with the extra properties ``from_``, ``to``, ``subject``
134 and ``body`` available for easy access to their content. 134 and ``body`` available for easy access to their content.
135 135
136 The SMTP server is terminated at the end of the test session. 136 The SMTP server is terminated at the end of the test session.
137 137
138 jp e2e tests 138 libervia-cli e2e tests
139 ------------ 139 ----------------------
140 140
141 End-to-end tests for ``jp`` are a good way to tests backend features without having to 141 End-to-end tests for ``libervia-cli`` are a good way to tests backend features without having to
142 deal with frontends UI. Those tests use extensively the ``sh`` module, which helps 142 deal with frontends UI. Those tests use extensively the ``sh`` module, which helps
143 writing ``jp`` commands like if they where methods. 143 writing ``libervia-cli`` commands like if they where methods.
144 144
145 Among the helping fixture (check the various ``conftest.py`` files for details), the 145 Among the helping fixture (check the various ``conftest.py`` files for details), the
146 following are specially good to know: 146 following are specially good to know:
147 147
148 ``jp_json`` 148 ``li_json``
149 Set the ``json_raw`` output are parse it. When you use this instead of the normal ``jp``, 149 Set the ``json_raw`` output are parse it. When you use this instead of the normal ``libervia-cli``,
150 you'll get a Python object that you can manipulate easily. 150 you'll get a Python object that you can manipulate easily.
151 151
152 ``jp_elt`` 152 ``li_elt``
153 Set the ``xml_raw`` output and parse it as a Twisted ``domish.Element``. When you use a 153 Set the ``xml_raw`` output and parse it as a Twisted ``domish.Element``. When you use a
154 command which can return XML, it is useful to get this object which is easy to 154 command which can return XML, it is useful to get this object which is easy to
155 manipulate in Python. 155 manipulate in Python.
156 156
157 ``editor`` 157 ``editor``
159 variable), to automatically modify and/or check the text sent by a command. You can 159 variable), to automatically modify and/or check the text sent by a command. You can
160 specify Python code to execute to modify the received text with the ``set_filter`` 160 specify Python code to execute to modify the received text with the ``set_filter``
161 method (this code is in a string which will be executed by Python interpreter, where the 161 method (this code is in a string which will be executed by Python interpreter, where the
162 ``content`` variable is the received text). By default, the text is kept unmodified. 162 ``content`` variable is the received text). By default, the text is kept unmodified.
163 163
164 After ``editor`` has been used by the ``jp`` command, you can check its 164 After ``editor`` has been used by the ``libervia-cli`` command, you can check its
165 ``original_content`` property to see the text that it received, and ``new_content`` 165 ``original_content`` property to see the text that it received, and ``new_content``
166 property to see the text that has been written after updating the original content with 166 property to see the text that has been written after updating the original content with
167 the code set in ``set_filter``. 167 the code set in ``set_filter``.
168 168
169 Libervia e2e tests 169 Libervia e2e tests
196 examples 196 examples
197 -------- 197 --------
198 198
199 Following examples have to be run from ``tests/e2e`` directory. 199 Following examples have to be run from ``tests/e2e`` directory.
200 200
201 Run all tests for ``jp``:: 201 Run all tests for ``Libervia CLI``::
202 202
203 $ ./run_e2e.py -k jp 203 $ ./run_e2e.py -k libervia-cli
204 204
205 Run all tests for ``Libervia`` with real-time visual feedback (note that you need to have 205 Run all tests for ``Libervia Web`` with real-time visual feedback (note that you need to have
206 ``vncviewer`` installed and available in path, see above):: 206 ``vncviewer`` installed and available in path, see above)::
207 207
208 $ ./run_e2e.py -k libervia --visual 208 $ ./run_e2e.py -k libervia-web --visual
209 209
210 210
211 Run all tests with verbose mode (useful to know which test is currently running):: 211 Run all tests with verbose mode (useful to know which test is currently running)::
212 212
213 $ ./run_e2e.py -v 213 $ ./run_e2e.py -v
219 Run in dev mode, to work on new tests, note that we run the ``user_can_create_account`` 219 Run in dev mode, to work on new tests, note that we run the ``user_can_create_account``
220 test to be sure to have test profiles created and fake SMTP server run…:: 220 test to be sure to have test profiles created and fake SMTP server run…::
221 221
222 $ ./run_e2e.py -k user_can_create_account --dev-mode 222 $ ./run_e2e.py -k user_can_create_account --dev-mode
223 223
224 …then to go into the ``sat`` container and work with the browser (to be run in ``docker`` 224 …then to go into the ``backend`` container and work with the browser (to be run in ``docker``
225 directory)…:: 225 directory)…::
226 226
227 $ docker-compose -f docker-compose_e2e.yml exec sat /bin/bash 227 $ docker-compose -f docker-compose_e2e.yml exec backend /bin/bash
228 228
229 …and, inside the container, you can now run ``python3`` and enter instruction prints at 229 …and, inside the container, you can now run ``python3`` and enter instruction prints at
230 the end of the test session. 230 the end of the test session.