From 922bf0307d25781af81e21eef87b7f2dee9ba8d4 Mon Sep 17 00:00:00 2001 From: Shivam Sandbhor Date: Wed, 18 Mar 2020 11:20:19 +0530 Subject: [PATCH 1/2] Add pytest markers to give option to skip tests dependent on internet connection Signed-off-by: Shivam Sandbhor --- README.md | 5 ++++- pytest.ini | 4 +++- vulnerabilities/tests/test_npm.py | 4 +++- vulnerabilities/tests/test_rust.py | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6e4fbd72a..cd7184bf9 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,10 @@ the code Django includes for this purpose: `SECRET_KEY=$(python -c "from django. pycodestyle --exclude=migrations,settings.py,venv --max-line-length=100 . DJANGO_DEV=1 pytest ``` - +To skip tests which require internet connection: +``` +DJANGO_DEV=1 pytest -m "not webtest" +``` ## Data import ``` diff --git a/pytest.ini b/pytest.ini index 8a0f512df..0145255ad 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,4 @@ [pytest] -DJANGO_SETTINGS_MODULE = vulnerablecode.settings \ No newline at end of file +DJANGO_SETTINGS_MODULE = vulnerablecode.settings +markers = + webtest: marker for tests which require internet connection. diff --git a/vulnerabilities/tests/test_npm.py b/vulnerabilities/tests/test_npm.py index 8fdc1a057..ddf69aff6 100644 --- a/vulnerabilities/tests/test_npm.py +++ b/vulnerabilities/tests/test_npm.py @@ -23,7 +23,7 @@ import os import json - +import pytest from vulnerabilities.scraper.npm import extract_data from vulnerabilities.scraper.npm import get_all_versions @@ -32,6 +32,7 @@ TEST_DATA = os.path.join(BASE_DIR, 'test_data/') +@pytest.mark.webtest def test_get_all_versions(): x = get_all_versions('electron') expected = ['0.1.2', '2.0.0', '3.0.0', @@ -39,6 +40,7 @@ def test_get_all_versions(): assert set(expected) <= set(x) +@pytest.mark.webtest def test_extract_data(): with open(os.path.join(TEST_DATA, 'npm_test.json')) as f: test_data = json.load(f) diff --git a/vulnerabilities/tests/test_rust.py b/vulnerabilities/tests/test_rust.py index 895d073b0..a08c989e6 100644 --- a/vulnerabilities/tests/test_rust.py +++ b/vulnerabilities/tests/test_rust.py @@ -21,12 +21,14 @@ # VulnerableCode is a free software code scanning tool from nexB Inc. and others. # Visit https://github.com/nexB/vulnerablecode/ for support and download. +import pytest from vulnerabilities.scraper.rust import rust_crate_advisories from vulnerabilities.scraper.rust import load_advisory RUSTSEC_DB_URL = 'https://github.com/RustSec/advisory-db/archive/master.zip' +@pytest.mark.webtest def test_extract_data(): for advisory in rust_crate_advisories(RUSTSEC_DB_URL): loaded_advisory = load_advisory(advisory) From c97975a00d274efb045c14cd7b0b945c7cb72b53 Mon Sep 17 00:00:00 2001 From: Shivam Sandbhor Date: Fri, 20 Mar 2020 15:36:48 +0530 Subject: [PATCH 2/2] Add type ='npm' for unaffected packages in npm dump Signed-off-by: Shivam Sandbhor --- vulnerabilities/data_dump.py | 1 + 1 file changed, 1 insertion(+) diff --git a/vulnerabilities/data_dump.py b/vulnerabilities/data_dump.py index ae55ff919..049af9906 100644 --- a/vulnerabilities/data_dump.py +++ b/vulnerabilities/data_dump.py @@ -185,6 +185,7 @@ def npm_dump(extract_data): for version in data['fixed_versions']: package_fixed = Package.objects.create( name=package_name, + type='npm', version=version ) ResolvedPackage.objects.create(