mirror of
https://github.com/danieldemus/pyp2spec.git
synced 2026-07-29 13:44:21 +02:00
Use betamax cassettes to record & replay requests to PyPI
This commit is contained in:
@@ -14,7 +14,7 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install -r requirements.txt
|
||||
python -m pip install pytest pytest-regressions
|
||||
python -m pip install pytest pytest-regressions betamax
|
||||
- name: Run pytest
|
||||
run: |
|
||||
python -m pytest -vv
|
||||
|
||||
@@ -37,11 +37,12 @@ python conf2spec.py -f tests/test_config/pyp2spec_click.conf
|
||||
|
||||
Test framework used in the project is pytest.
|
||||
The tests use pytest-regresssions extension used to generate spec files to compare.
|
||||
The tests use betamax to record API calls and replay them from the prerecorded cassettes.
|
||||
To run the tests, run following commands:
|
||||
|
||||
```
|
||||
python -m pip install pytest pytest-regresssions
|
||||
python -m pytest
|
||||
python -m pip install pytest pytest-regresssions betamax
|
||||
python -m pytest -vv
|
||||
```
|
||||
|
||||
|
||||
|
||||
+7
-4
@@ -7,9 +7,11 @@ import requests
|
||||
import tomli_w
|
||||
|
||||
|
||||
def get_pypi_metadata(package_name):
|
||||
def get_pypi_metadata(package_name, session=None):
|
||||
pypi_index = f'https://pypi.org/pypi/{package_name}/json'
|
||||
response = requests.get(pypi_index)
|
||||
|
||||
s = session or requests.Session()
|
||||
response = s.get(pypi_index)
|
||||
return response.json()
|
||||
|
||||
|
||||
@@ -95,7 +97,8 @@ def is_url(package):
|
||||
|
||||
|
||||
def create_config_contents(package, description=None, release=None,
|
||||
message=None, email=None, name=None, version=None, summary=None, date=None):
|
||||
message=None, email=None, name=None, version=None, summary=None, date=None,
|
||||
session=None):
|
||||
"""Use `package_data` to create the whole config contents.
|
||||
Return contents.
|
||||
"""
|
||||
@@ -109,7 +112,7 @@ def create_config_contents(package, description=None, release=None,
|
||||
|
||||
# `package` is not a URL -> it's a package name, look for it on PyPI
|
||||
if not is_url(package):
|
||||
package_data = get_pypi_metadata(package)
|
||||
package_data = get_pypi_metadata(package, session)
|
||||
|
||||
pypi_name = package_data["info"]["name"]
|
||||
contents["pypi_name"] = pypi_name
|
||||
|
||||
File diff suppressed because one or more lines are too long
+10
-6
@@ -1,10 +1,14 @@
|
||||
# import config
|
||||
import pyp2conf
|
||||
|
||||
import betamax
|
||||
import tomli
|
||||
|
||||
import pyp2conf
|
||||
|
||||
def test_config_is_valid():
|
||||
|
||||
with betamax.Betamax.configure() as config:
|
||||
config.cassette_library_dir = 'tests/fixtures/cassettes'
|
||||
|
||||
|
||||
def test_config_is_valid(betamax_session):
|
||||
package = "aionotion"
|
||||
config = pyp2conf.create_config_contents(
|
||||
package=package,
|
||||
@@ -15,11 +19,11 @@ def test_config_is_valid():
|
||||
name="Package Manager",
|
||||
version="2.0.3",
|
||||
summary="Python library for Notion Home Monitoring",
|
||||
date="Fri Jun 04 2021"
|
||||
date="Fri Jun 04 2021",
|
||||
session=betamax_session,
|
||||
)
|
||||
|
||||
with open(f"tests/test_configs/pyp2spec_{package}.conf", "rb") as config_file:
|
||||
loaded_contents = tomli.load(config_file)
|
||||
|
||||
assert config == loaded_contents
|
||||
# assert config.ConfigFile.validate_contents(contents)
|
||||
|
||||
Reference in New Issue
Block a user