Blog Post #2

Utkarsh
Published: 06/28/2021

The second week of my GSOC experience mainly comprised of me fixing the tests that were merged into the main branch. The problems mainly arose due to the difference in main branch and the environment in which the tests were developed.

What did my work comprise of?

My work was mainly to get most of the tests working and to develop cassettes to record the traffic for faster retesting. I had to learn how to use pytest-vcr and to implement in such a way that was efficient and removed redundancies. There were 236 tests in total that covered 11 different scripts. The main reason for recording the traffic was that almost all the services offered require WSAA authentication and they require the wsaa.Autenticar() function to be called. The problem with this is that once this function is called, calling it immediately after causes an exception:- Falla SOAP: ns1:coe.alreadyAuthenticated: El CEE ya posee un TA valido para el acceso al WSN solicitado.
Another problem that I faced was the overwriting of the cassettes once after the recoding was done. This was seen in the exception :- CannotOverwriteExistingCassetteException: Can't overwrite existing cassette ('cassette.yaml') in your current record mode ('once').

How did I get about solving these problems?

I figured out that the reason for the CannotOverwriteExistingCassetteException was that there were many redundant requests and while replaying were causing the cassettes to be re-recorded. One way to handle this as to define a fixture that would handle the incoming requests.
I used the following fixture to fix this issue:-
@pytest.fixture(autouse=True)
def auth(request):
    if 'dontusefix' in request.keywords:
        return
    z=request.module.__obj__
    z.Cuit = CUIT
    wsaa=WSAA()
    ta = wsaa.Autenticar(request.module.__service__, CERT, PKEY)
    z.SetTicketAcceso(ta)
    z.Conectar(CACHE, request.module.__WSDL__)
    return z 

Also I had to record the traffic script by script and make cassettes. It was a tedious process but the result was worth it. Initially was running the pytest, it would take about 5 mins for all the tests to run and show the results of the test. Now with the cassettes in play, it was only a matter of seconds before all the tests ran. The cassettes also helped in solving the Already authenticated exception. This was because now when the scripts made request to the servers, the recorded response was played for them. This resulted in faster and efficient testing.

Final Result

Finally with the help of cassettes, I managed to get 202 tests passing on python 3 and 191 tests passing on python 2. The difference in the number of tests passing was due to some unicode errors on python 2. I plan to resolve these issues in the upcoming week so I can get maximum tests passing on both the versions. Here is a summary of tests on python 3:-

$ pytest
============================= test session starts ==============================
platform linux -- Python 3.9.5, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /home/runner/work/pyafipws/pyafipws
plugins: vcr-1.0.2, html-3.1.1, metadata-1.11.0
collected 236 items

tests/test_ws_sr_padron.py s.sx                                          [  1%]
tests/test_wsaa.py ...x.                                                 [  3%]
tests/test_wsaa_crypto.py ....                                           [  5%]
tests/test_wsbfev1.py ..........                                         [  9%]
tests/test_wscdc.py s.......                                             [ 13%]
tests/test_wsct.py ..........xx..xxxxxxxxxxssxxxxxx                      [ 26%]
tests/test_wsfev1.py ...xxx                                              [ 29%]
tests/test_wsfev1_dummy.py .                                             [ 29%]
tests/test_wsfexv1.py ..........                                         [ 33%]
tests/test_wslsp.py ......................................x.             [ 50%]
tests/test_wsltv.py ............................x.                       [ 63%]
tests/test_wslum.py ........................x.                           [ 74%]
tests/test_wsmtx.py ..............x......x..........x                    [ 88%]
tests/test_wsremcarne.py ...........................                     [100%]

-- Docs: https://docs.pytest.org/en/stable/warnings.html
- generated html file: file:///home/runner/work/pyafipws/pyafipws/report.html --
============ 202 passed, 5 skipped, 29 xfailed, 6 warnings in 6.68s ============

and with python 2:-
$ pytest
============================= test session starts ==============================
platform linux2 -- Python 2.7.18, pytest-4.6.11, py-1.10.0, pluggy-0.13.1
rootdir: /home/runner/work/pyafipws/pyafipws
plugins: vcr-1.0.2, html-1.22.1, metadata-1.11.0
collected 236 items

tests/test_ws_sr_padron.py s.sx                                          [  1%]
tests/test_wsaa.py ..sxs                                                 [  3%]
tests/test_wsaa_crypto.py ....                                           [  5%]
tests/test_wsbfev1.py .....s....                                         [  9%]
tests/test_wscdc.py s.......                                             [ 13%]
tests/test_wsct.py ..........xx..xxxxxxxxxxssxxxxxx                      [ 26%]
tests/test_wsfev1.py .ssxxx                                              [ 29%]
tests/test_wsfev1_dummy.py .                                             [ 29%]
tests/test_wsfexv1.py .....s...s                                         [ 33%]
tests/test_wslsp.py ......................................xs             [ 50%]
tests/test_wsltv.py ............................xs                       [ 63%]
tests/test_wslum.py ........................xs                           [ 74%]
tests/test_wsmtx.py ...........s..x......x..........x                    [ 88%]
tests/test_wsremcarne.py ...........................                     [100%]

-- Docs: https://docs.pytest.org/en/latest/warnings.html
- generated html file: file:///home/runner/work/pyafipws/pyafipws/report.html --
======== 191 passed, 16 skipped, 29 xfailed, 2 warnings in 6.24 seconds ========
DJDT

Versions

Time

Settings from gsoc.settings

Headers

Request

SQL queries from 1 connection

Static files (2312 found, 3 used)

Templates (11 rendered)

Cache calls from 1 backend

Signals

Log messages