Page MenuHomeSoftware Heritage

Add first set of functional tests
ClosedPublic

Authored by jayeshv on May 12 2022, 11:51 AM.

Details

Summary
  • Mock storage and dev server
  • Dummy storage data
  • Functional tests for OriginNode and OriginConnection

Diff Detail

Repository
rDGQL GraphQL API
Branch
origin-tests
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 29448
Build 46024: Phabricator diff pipeline on jenkinsJenkins console · Jenkins
Build 46023: arc lint + arc unit

Event Timeline

Build has FAILED

Patch application report for D7817 (id=28228)

Rebasing onto e43cde0cb4...

Current branch diff-target is up to date.
Changes applied before test
commit 7de3ce4168829db5a27030cf6955813c5874daad
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed May 11 10:51:12 2022 +0200

    Add first set of functional tests
    
    - Mock storage and dev server
    - Dummy storage data
    - Functional tests for OriginNode and OriginConnection

Link to build: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/9/
See console output for more information: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/9/console

Harbormaster returned this revision to the author for changes because remote builds failed.May 12 2022, 11:52 AM
Harbormaster failed remote builds in B29335: Diff 28228!

Build has FAILED

Patch application report for D7817 (id=28230)

Rebasing onto e43cde0cb4...

Current branch diff-target is up to date.
Changes applied before test
commit 7dda8e52dcc58b3a1f1e5b0b9a5856cf5edc200b
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed May 11 10:51:12 2022 +0200

    Add first set of functional tests
    
    - Mock storage and dev server
    - Dummy storage data
    - Functional tests for OriginNode and OriginConnection

Link to build: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/10/
See console output for more information: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/10/console

Harbormaster returned this revision to the author for changes because remote builds failed.May 12 2022, 12:23 PM
Harbormaster failed remote builds in B29337: Diff 28230!

Add requests to mypy.ini ignore imports

Build has FAILED

Patch application report for D7817 (id=28231)

Rebasing onto e43cde0cb4...

Current branch diff-target is up to date.
Changes applied before test
commit e5409ed13e12642dc9d2cc805c19933fd326ca75
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed May 11 10:51:12 2022 +0200

    Add first set of functional tests
    
    - Mock storage and dev server
    - Dummy storage data
    - Functional tests for OriginNode and OriginConnection

Link to build: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/11/
See console output for more information: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/11/console

Harbormaster returned this revision to the author for changes because remote builds failed.May 12 2022, 12:28 PM
Harbormaster failed remote builds in B29338: Diff 28231!

Increase the time delay to start the test server

Build has FAILED

Patch application report for D7817 (id=28232)

Rebasing onto e43cde0cb4...

Current branch diff-target is up to date.
Changes applied before test
commit 780e0d7e834f07f4670b0248d188a9e4d619732b
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed May 11 10:51:12 2022 +0200

    Add first set of functional tests
    
    - Mock storage and dev server
    - Dummy storage data
    - Functional tests for OriginNode and OriginConnection

Link to build: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/12/
See console output for more information: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/12/console

Harbormaster returned this revision to the author for changes because remote builds failed.May 12 2022, 12:33 PM
Harbormaster failed remote builds in B29339: Diff 28232!

Change the URL to localhost

Build has FAILED

Patch application report for D7817 (id=28233)

Rebasing onto e43cde0cb4...

Current branch diff-target is up to date.
Changes applied before test
commit 6ed56b9b24c5279a7e7512ede416d8222268fbcc
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed May 11 10:51:12 2022 +0200

    Add first set of functional tests
    
    - Mock storage and dev server
    - Dummy storage data
    - Functional tests for OriginNode and OriginConnection

Link to build: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/13/
See console output for more information: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/13/console

Harbormaster returned this revision to the author for changes because remote builds failed.May 12 2022, 12:43 PM
Harbormaster failed remote builds in B29340: Diff 28233!

Tests for filtering origin with URL

Build has FAILED

Patch application report for D7817 (id=28262)

Rebasing onto e43cde0cb4...

Current branch diff-target is up to date.
Changes applied before test
commit d664beb1949c5e052cff4399d5142458d5c55b11
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed May 11 10:51:12 2022 +0200

    Add first set of functional tests
    
    - Mock storage and dev server
    - Dummy storage data
    - Functional tests for OriginNode and OriginConnection

Link to build: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/14/
See console output for more information: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/14/console

Harbormaster returned this revision to the author for changes because remote builds failed.May 13 2022, 10:26 AM
Harbormaster failed remote builds in B29367: Diff 28262!

Replace the dummy uvicorn server with the flask

Build is green

Patch application report for D7817 (id=28303)

Rebasing onto 2736e5f3dd...

Current branch diff-target is up to date.
Changes applied before test
commit 93d8b83a48c65f6abec8942ecae53bb6df70fff3
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed May 11 10:51:12 2022 +0200

    Add first set of functional tests
    
    - Mock storage and dummy flask app for tests
    - Separate config file for tests
    - Dummy storage data for origin type
    - Functional tests for OriginNode and OriginConnection

See https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/16/ for more details.

Removed unused libs from mypy config

Build is green

Patch application report for D7817 (id=28304)

Rebasing onto 2736e5f3dd...

Current branch diff-target is up to date.
Changes applied before test
commit 39ea7626af89812dd317b50368c05709867e4650
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed May 11 10:51:12 2022 +0200

    Add first set of functional tests
    
    - Mock storage and dummy flask app for tests
    - Separate config file for tests
    - Dummy storage data for origin type
    - Functional tests for OriginNode and OriginConnection

See https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/17/ for more details.

anlambert added a subscriber: anlambert.
anlambert added inline comments.
swh/graphql/server.py
77

s/falsk/flask/

77–95

If this only used by test, you should move this code in conftest.py and wraps it in a session scope fixture.

swh/graphql/tests/conftest.py
7

You should not import stuffs from private modules, we already have some issues because of that in the past.

30

Use pytest-mock instead, this should translate to:

@pytest.fixture(scope="session")
def storage(mocker):
    def mock_storage(*args, **kw):
        storage = get_swhstorage(cls="memory")
        populate_dummy_data(storage)
        return storage

    mocker.patch.object(app_server, "get_storage", mock_storage)
swh/graphql/tests/functional/test_origin.py
9 ↗(On Diff #28304)

You can gain one indentation level by removing the class and writing only functions for the tests.

Something like:

def test_origin_connection_get(client):
   ...

def test_origin_connection_get_filter_by_pattern(client):
  ...

...
swh/graphql/tests/functional/utils.py
11

If the status code is not 200 and there is some error message in the response, you should extract it and display it if the assertions fails.
It should help to debug tests.

error_message = (extract it from response if available)
assert response.status_code == 200, error_message
This revision now requires changes to proceed.May 16 2022, 3:37 PM
swh/graphql/tests/conftest.py
30

Ok got it, you were forced to proceed like this because of the session scope.

I think you can use function scope fixture (the default) directly then, based on my
tests this does not affect tests performance and this will guarantee that each test
is executed with the same input data in you test archive.

This way you can directly use the monkeypatch fixture.

jayeshv added inline comments.
swh/graphql/tests/conftest.py
30

Removed this mock, setting the global variable directly from conftest.

Build has FAILED

Patch application report for D7817 (id=28344)

Rebasing onto 2736e5f3dd...

Current branch diff-target is up to date.
Changes applied before test
commit 1e07b31877cea885c804548a49b6c4cd7a0848e6
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed May 11 10:51:12 2022 +0200

    Add first set of functional tests
    
    - in-memory storage and dummy flask app for tests
    - Dummy storage data to test origin type
    - Functional tests for OriginNode and OriginConnection

Link to build: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/18/
See console output for more information: https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/18/console

jayeshv marked an inline comment as done.

Changed import order

Build is green

Patch application report for D7817 (id=28345)

Rebasing onto 2736e5f3dd...

Current branch diff-target is up to date.
Changes applied before test
commit 34095c065153cd24d35be41c54fcc30d8f3d12a9
Author: Jayesh Velayudhan <jayesh@softwareheritage.org>
Date:   Wed May 11 10:51:12 2022 +0200

    Add first set of functional tests
    
    - in-memory storage and dummy flask app for tests
    - Dummy storage data to test origin type
    - Functional tests for OriginNode and OriginConnection

See https://jenkins.softwareheritage.org/job/DGQL/job/tests-on-diff/19/ for more details.

This revision is now accepted and ready to land.May 18 2022, 4:56 PM
This revision was automatically updated to reflect the committed changes.