Page MenuHomeSoftware Heritage

Add frontend test for metadata search
ClosedPublic

Authored by KShivendu on Feb 27 2021, 7:03 PM.

Active Operations

Diff Detail

Repository
rDWAPPS Web applications
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Build has FAILED

Patch application report for D5163 (id=18469)

Rebasing onto d91cbf3780...

Current branch diff-target is up to date.
Changes applied before test
commit ed72b4ae57a09678b7902a179b9416d5c25d3f99
Author: KShivendu <shivendu@iitbhilai.ac.in>
Date:   Sun Feb 28 05:02:13 2021 +0530

    Add frontend test for metadata search

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

Harbormaster returned this revision to the author for changes because remote builds failed.Feb 27 2021, 7:10 PM
Harbormaster failed remote builds in B19546: Diff 18469!

Since new metadata are added for some origins in tests data, the test_api_origin_metadata_search is now failing.

16:46 $ pytest -svv swh/web/tests/api/views/test_origin.py::test_api_origin_metadata_search[swh-indexer-storage]
============================================================================================== test session starts ===============================================================================================
platform linux -- Python 3.7.3, pytest-6.2.2, py-1.10.0, pluggy-0.13.1 -- /home/anlambert/.virtualenvs/swh/bin/python3
cachedir: .pytest_cache
django: settings: swh.web.settings.tests (from ini)
hypothesis profile 'swh-web-fast' -> deadline=None, max_examples=1, database=DirectoryBasedExampleDatabase('/home/anlambert/swh/swh-environment/swh-web/.hypothesis/examples'), suppress_health_check=[HealthCheck.too_slow, HealthCheck.filter_too_much, HealthCheck.function_scoped_fixture]
rootdir: /home/anlambert/swh/swh-environment/swh-web, configfile: pytest.ini
plugins: asyncio-0.14.0, cov-2.11.1, xdist-2.2.1, django-4.1.0, requests-mock-1.8.0, hypothesis-6.4.0, forked-1.3.0, mock-3.5.1, postgresql-2.6.1, dash-1.19.0, swh.journal-0.7.2.dev1+ged9d682, swh.core-0.12.1.dev0+g576b104.d20210302
collecting ... [03/Mar/2021 15:47:57] [INFO] swh.loader.git.from_disk.GitLoaderFromArchive.load:326 - Load origin 'https://github.com/memononen/libtess2' with type 'git'
[03/Mar/2021 15:47:57] [INFO] swh.loader.git.from_disk.GitLoaderFromArchive.prepare:374 - Project https://github.com/memononen/libtess2 - Uncompressing archive libtess2.zip at /tmp/tmp.quw59wmd.swh.loader.git/libtess2
[03/Mar/2021 15:47:57] [INFO] swh.loader.git.from_disk.GitLoaderFromArchive.cleanup:386 - Project https://github.com/memononen/libtess2 - Done injecting /tmp/tmp.quw59wmd.swh.loader.git/libtess2
[03/Mar/2021 15:47:57] [INFO] swh.loader.git.from_disk.GitLoaderFromArchive.load:326 - Load origin 'https://github.com/wcoder/highlightjs-line-numbers.js' with type 'git'
[03/Mar/2021 15:47:57] [INFO] swh.loader.git.from_disk.GitLoaderFromArchive.prepare:374 - Project https://github.com/wcoder/highlightjs-line-numbers.js - Uncompressing archive highlightjs-line-numbers.js.zip at /tmp/tmp.36efgali.swh.loader.git/highlightjs-line-numbers.js
[03/Mar/2021 15:47:57] [INFO] swh.loader.git.from_disk.GitLoaderFromArchive.cleanup:386 - Project https://github.com/wcoder/highlightjs-line-numbers.js - Done injecting /tmp/tmp.36efgali.swh.loader.git/highlightjs-line-numbers.js
[03/Mar/2021 15:47:58] [INFO] swh.loader.git.from_disk.GitLoaderFromArchive.load:326 - Load origin 'https://github.com/wcoder/highlightjs-line-numbers.js' with type 'git'
[03/Mar/2021 15:47:58] [INFO] swh.loader.git.from_disk.GitLoaderFromArchive.prepare:374 - Project https://github.com/wcoder/highlightjs-line-numbers.js - Uncompressing archive highlightjs-line-numbers.js_visit2.zip at /tmp/tmp.h_m538_k.swh.loader.git/highlightjs-line-numbers.js_visit2
[03/Mar/2021 15:47:58] [INFO] swh.loader.git.from_disk.GitLoaderFromArchive.cleanup:386 - Project https://github.com/wcoder/highlightjs-line-numbers.js - Done injecting /tmp/tmp.h_m538_k.swh.loader.git/highlightjs-line-numbers.js_visit2
[03/Mar/2021 15:47:58] [INFO] swh.loader.git.from_disk.GitLoaderFromArchive.load:326 - Load origin 'repo_with_submodules' with type 'git'
[03/Mar/2021 15:47:58] [INFO] swh.loader.git.from_disk.GitLoaderFromArchive.prepare:374 - Project repo_with_submodules - Uncompressing archive repo_with_submodules.tgz at /tmp/tmp.kzu1r2m_.swh.loader.git/repo_with_submodules
[03/Mar/2021 15:47:58] [INFO] swh.loader.git.from_disk.GitLoaderFromArchive.cleanup:386 - Project repo_with_submodules - Done injecting /tmp/tmp.kzu1r2m_.swh.loader.git/repo_with_submodules
[03/Mar/2021 15:48:00] [DEBUG] swh.indexer.__init__:161 - <swh.indexer.mimetype.MimetypeIndexer object at 0x7f5d1c3e00f0>: config={'tools': {'configuration': {'debian-package': 'python3-magic', 'type': 'library'}, 'version': '1:5.30-1+deb9u1', 'name': 'file'}, 'indexer_storage': {'args': {}, 'cls': 'memory'}, 'storage': {'cls': 'memory'}, 'objstorage': {'args': {}, 'cls': 'memory'}}
[03/Mar/2021 15:48:00] [DEBUG] swh.indexer.__init__:161 - <swh.indexer.fossology_license.FossologyLicenseIndexer object at 0x7f5d1c788080>: config={'objstorage': {'args': {}, 'cls': 'memory'}, 'workdir': '/tmp/swh/indexer.fossology.license', 'tools': {'configuration': {'command_line': 'nomossa <filepath>'}, 'version': '3.1.0rc2-31-ga2cbb8c', 'name': 'nomos'}, 'storage': {'cls': 'memory'}, 'indexer_storage': {'args': {}, 'cls': 'memory'}}
[03/Mar/2021 15:48:00] [DEBUG] swh.indexer.__init__:161 - <swh.indexer.ctags.CtagsIndexer object at 0x7f5d1c64a7f0>: config={'objstorage': {'args': {}, 'cls': 'memory'}, 'workdir': '/tmp/swh/indexer.ctags', 'tools': {'configuration': {'command_line': 'ctags --fields=+lnz --sort=no --links=no --output-format=json <filepath>'}, 'version': '~git7859817b', 'name': 'universal-ctags'}, 'storage': {'cls': 'memory'}, 'languages': {'c': 'c'}, 'indexer_storage': {'args': {}, 'cls': 'memory'}}
collected 1 item                                                                                                                                                                                                 

swh/web/tests/api/views/test_origin.py::test_api_origin_metadata_search[swh-indexer-storage] FAILED

==================================================================================================== FAILURES ====================================================================================================
______________________________________________________________________________ test_api_origin_metadata_search[swh-indexer-storage] ______________________________________________________________________________

api_client = <rest_framework.test.APIClient object at 0x7f5d39b86fd0>, mocker = <pytest_mock.plugin.MockerFixture object at 0x7f5d39b33e80>, backend = 'swh-indexer-storage'

    @pytest.mark.parametrize("backend", ["swh-search", "swh-indexer-storage"])
    def test_api_origin_metadata_search(api_client, mocker, backend):
    
        mock_config = mocker.patch("swh.web.common.archive.config")
        mock_config.get_config.return_value = {"metadata_search_backend": backend}
    
        url = reverse(
            "api-1-origin-metadata-search", query_params={"fulltext": ORIGIN_METADATA_VALUE}
        )
        rv = check_api_get_responses(api_client, url, status_code=200)
    
        expected_data = [
            {
                "url": origin_url,
                "metadata": {
                    "from_revision": master_rev,
                    "tool": {
                        "name": INDEXER_TOOL["tool_name"],
                        "version": INDEXER_TOOL["tool_version"],
                        "configuration": INDEXER_TOOL["tool_configuration"],
                        "id": INDEXER_TOOL["id"],
                    },
                    "metadata": {ORIGIN_METADATA_KEY: ORIGIN_METADATA_VALUE},
                    "mappings": [],
                },
            }
            for origin_url, master_rev in ORIGIN_MASTER_REVISION.items()
        ]
    
>       assert rv.data == expected_data
E       AssertionError: assert [{'metadata': {'from_revision': '56d5c87b596bfe792f79b2e41fde83b769f6406d',\n               'mappings': [],\n               'metadata': {'vcs': 'git'},\n               'tool': {'configuration': {},\n                        'id': 1233115655296547119,\n                        'name': 'swh-web tests',\n                        'version': '1.0'}},\n  'url': 'https://github.com/memononen/libtess2'},\n {'metadata': {'from_revision': 'ffcb69001f3f6745dfd5b48f72ab6addb560e234',\n               'mappings': [],\n               'metadata': {'description': 'A sample repo with submodules',\n                            'vcs': 'git'},\n               'tool': {'configuration': {},\n                        'id': 1233115655296547119,\n                        'name': 'swh-web tests',\n                        'version': '1.0'}},\n  'url': 'repo_with_submodules'},\n {'metadata': {'from_revision': '3bd01955e961aa2e6e1b6f9cd9e003f94273584e',\n               'mappings': [],\n               'metadata': {'description': 'Line numbering plugin for '\n                                           'Highlight.js',\n                            'vcs': 'git'},\n               'tool': {'configuration': {},\n                        'id': 1233115655296547119,\n                        'name': 'swh-web tests',\n                        'version': '1.0'}},\n  'url': 'https://github.com/wcoder/highlightjs-line-numbers.js'}] == [{'metadata': {'from_revision': '56d5c87b596bfe792f79b2e41fde83b769f6406d',\n               'mappings': [],\n               'metadata': {'vcs': 'git'},\n               'tool': {'configuration': {},\n                        'id': 1233115655296547119,\n                        'name': 'swh-web tests',\n                        'version': '1.0'}},\n  'url': 'https://github.com/memononen/libtess2'},\n {'metadata': {'from_revision': '3bd01955e961aa2e6e1b6f9cd9e003f94273584e',\n               'mappings': [],\n               'metadata': {'vcs': 'git'},\n               'tool': {'configuration': {},\n                        'id': 1233115655296547119,\n                        'name': 'swh-web tests',\n                        'version': '1.0'}},\n  'url': 'https://github.com/wcoder/highlightjs-line-numbers.js'},\n {'metadata': {'from_revision': 'ffcb69001f3f6745dfd5b48f72ab6addb560e234',\n               'mappings': [],\n               'metadata': {'vcs': 'git'},\n               'tool': {'configuration': {},\n                        'id': 1233115655296547119,\n                        'name': 'swh-web tests',\n                        'version': '1.0'}},\n  'url': 'repo_with_submodules'}]
E         At index 1 diff: {'url': 'repo_with_submodules', 'metadata': {'tool': {'id': 1233115655296547119, 'name': 'swh-web tests', 'version': '1.0', 'configuration': {}}, 'metadata': {'vcs': 'git', 'description': 'A sample repo with submodules'}, 'from_revision': 'ffcb69001f3f6745dfd5b48f72ab6addb560e234', 'mappings': []}} != {'url': 'https://github.com/wcoder/highlightjs-line-numbers.js', 'metadata': {'from_revision': '3bd01955e961aa2e6e1b6f9cd9e003f94273584e', 'tool': {'name': 'swh-web tests', 'version': '1.0', 'configuration': {}, 'id': 1233115655296547119}, 'metadata': {'vcs': 'git'}, 'mappings': []}}
E         Full diff:
E           [
E            {'metadata': {'from_revision': '56d5c87b596bfe792f79b2e41fde83b769f6406d',
E                          'mappings': [],
E                          'metadata': {'vcs': 'git'},
E                          'tool': {'configuration': {},
E                                   'id': 1233115655296547119,
E                                   'name': 'swh-web tests',
E                                   'version': '1.0'}},
E             'url': 'https://github.com/memononen/libtess2'},
E         +  {'metadata': {'from_revision': 'ffcb69001f3f6745dfd5b48f72ab6addb560e234',
E         +                'mappings': [],
E         +                'metadata': {'description': 'A sample repo with submodules',
E         +                             'vcs': 'git'},
E         +                'tool': {'configuration': {},
E         +                         'id': 1233115655296547119,
E         +                         'name': 'swh-web tests',
E         +                         'version': '1.0'}},
E         +   'url': 'repo_with_submodules'},
E            {'metadata': {'from_revision': '3bd01955e961aa2e6e1b6f9cd9e003f94273584e',
E                          'mappings': [],
E         -                'metadata': {'vcs': 'git'},
E         +                'metadata': {'description': 'Line numbering plugin for '
E         +                                            'Highlight.js',
E         +                             'vcs': 'git'},
E                          'tool': {'configuration': {},
E                                   'id': 1233115655296547119,
E                                   'name': 'swh-web tests',
E                                   'version': '1.0'}},
E             'url': 'https://github.com/wcoder/highlightjs-line-numbers.js'},
E         -  {'metadata': {'from_revision': 'ffcb69001f3f6745dfd5b48f72ab6addb560e234',
E         -                'mappings': [],
E         -                'metadata': {'vcs': 'git'},
E         -                'tool': {'configuration': {},
E         -                         'id': 1233115655296547119,
E         -                         'name': 'swh-web tests',
E         -                         'version': '1.0'}},
E         -   'url': 'repo_with_submodules'},
E           ]

swh/web/tests/api/views/test_origin.py:625: AssertionError

As the set of metadata returned by the call to "api-1-origin-metadata-search" api endpoint has changed, the test
should now check that the search term is well present in the returned metadata.

This the current test implementation:

@pytest.mark.parametrize("backend", ["swh-search", "swh-indexer-storage"])
def test_api_origin_metadata_search(api_client, mocker, backend):

    mock_config = mocker.patch("swh.web.common.archive.config")
    mock_config.get_config.return_value = {"metadata_search_backend": backend}

    url = reverse(
        "api-1-origin-metadata-search", query_params={"fulltext": ORIGIN_METADATA_VALUE}
    )
    rv = check_api_get_responses(api_client, url, status_code=200)

    expected_data = [
        {
            "url": origin_url,
            "metadata": {
                "from_revision": master_rev,
                "tool": {
                    "name": INDEXER_TOOL["tool_name"],
                    "version": INDEXER_TOOL["tool_version"],
                    "configuration": INDEXER_TOOL["tool_configuration"],
                    "id": INDEXER_TOOL["id"],
                },
                "metadata": {ORIGIN_METADATA_KEY: ORIGIN_METADATA_VALUE},
                "mappings": [],
            },
        }
        for origin_url, master_rev in ORIGIN_MASTER_REVISION.items()
    ]

    assert rv.data == expected_data

The test could be modified the following ways:

  • remove the "metadata" field from the expected_data dict
  • check that expected_data is a sub dict of rv.data
  • check that rv.data without rv.data["metadata"]["metadata"] is equal to expected_data
  • check that ORIGIN_METADATA_VALUE is present in the values of the rv.data["metadata"] dict
  • Add frontend test for metadata search
  • Fix backend tests

Build is green

Patch application report for D5163 (id=18580)

Rebasing onto a7e8c16a34...

First, rewinding head to replay your work on top of it...
Applying: Add frontend test for metadata search
Applying: Fix backend tests
Changes applied before test
commit 4b404d1cd7c5df5769db7756aaaa3d3f0d506d2c
Author: KShivendu <shivendu@iitbhilai.ac.in>
Date:   Thu Mar 4 11:34:52 2021 +0530

    Fix backend tests

commit 6581ecf750746ade0a0e2f0742d329be870ff5cf
Author: KShivendu <shivendu@iitbhilai.ac.in>
Date:   Sun Feb 28 03:24:09 2021 +0530

    Add frontend test for metadata search

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

Could you undo the unrelated changes in origin-search.spec.js?

anlambert added inline comments.
cypress/integration/origin-search.spec.js
23

It looks like your IDE reformatted the code style in a different format that the one we are using.

You need to revert those format changes and use the following configuration for eslint.

swh/web/tests/api/views/test_origin.py
625–634

Do this instead:

for i in range(len(expected_data)):
        expected = expected_data[i]
        response = rv.data[i]
        metadata = response["metadata"].pop("metadata")
        assert any([ORIGIN_METADATA_VALUE in json.dumps(val) for val in metadata.values()])
        assert response == expected
This revision now requires changes to proceed.Mar 4 2021, 12:39 PM

Updating D5163: Add frontend test for metadata search

Build has FAILED

Patch application report for D5163 (id=18615)

Rebasing onto a7e8c16a34...

First, rewinding head to replay your work on top of it...
Applying: Add frontend test for metadata search
Changes applied before test
commit 9d58ff06bca2959ee00a4d30f71c31d301dad981
Author: KShivendu <shivendu@iitbhilai.ac.in>
Date:   Sun Feb 28 03:24:09 2021 +0530

    Add frontend test for metadata search
    
    Fix failing backend tests
    
    Improve code writing style

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

This build is failing because of ImportError: cannot import name 'SWHID' from 'swh.model.identifiers'. Tests are running without errors locally with pip install swh.model=1.0.0.

Build is green

Patch application report for D5163 (id=18615)

Rebasing onto a7e8c16a34...

First, rewinding head to replay your work on top of it...
Applying: Add frontend test for metadata search
Changes applied before test
commit 2610fbf0686bf80c7a7a5b18fa0d34bb1cc5ed23
Author: KShivendu <shivendu@iitbhilai.ac.in>
Date:   Sun Feb 28 03:24:09 2021 +0530

    Add frontend test for metadata search
    
    Fix failing backend tests
    
    Improve code writing style

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

Looks good to me. Thanks !

cypress/integration/origin-search.spec.js
176

Can you add a comment saying metadata are defined in the swh/web/tests/data.py file ?

This revision is now accepted and ready to land.Mar 5 2021, 12:27 PM

Updating D5163: Add frontend test for metadata search

Updating D5163: Add frontend test for metadata search

@KShivendu you need to rebase the diff to origin/master in order to be able to land it.

Build is green

Patch application report for D5163 (id=18632)

Rebasing onto a7e8c16a34...

First, rewinding head to replay your work on top of it...
Applying: Add frontend test for metadata search
Changes applied before test
commit 556c471e67565adcef2f13b49da03a5d7fbb7ac6
Author: KShivendu <shivendu@iitbhilai.ac.in>
Date:   Sun Feb 28 03:24:09 2021 +0530

    Add frontend test for metadata search
    
    Fix failing backend tests
    
    Improve code writing style

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

@KShivendu also you can improve the commit message to

cypress: Add frontend test for origin intrinsic metadata search

Closes T2285

Build is green

Patch application report for D5163 (id=18633)

Rebasing onto a7e8c16a34...

First, rewinding head to replay your work on top of it...
Applying: Add frontend test for metadata search
Changes applied before test
commit 394f2b09a2a5f1ef70554d9d017a993119f378cb
Author: KShivendu <shivendu@iitbhilai.ac.in>
Date:   Sun Feb 28 03:24:09 2021 +0530

    Add frontend test for metadata search
    
    Fix failing backend tests
    
    Improve code writing style

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

Updating D5163: Add frontend test for metadata search

This revision was landed with ongoing or failed builds.Mar 5 2021, 1:11 PM
This revision was automatically updated to reflect the committed changes.

Build is green

Patch application report for D5163 (id=18634)

Rebasing onto a7e8c16a34...

Current branch diff-target is up to date.
Changes applied before test
commit 93b1c0ba9af5971d642202e6563ac08495dda7fa
Author: KShivendu <shivendu@iitbhilai.ac.in>
Date:   Sun Feb 28 03:24:09 2021 +0530

    cypress: Add frontend test for origin intrinsic metadata search
    
    Closes T2285

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