Drop "message" parameter of pytest.raises

Deprecated since version 4.1
https://docs.pytest.org/en/4.6.x/deprecations.html#raises-message-deprecated
This commit is contained in:
Santiago L 2022-09-26 17:08:40 +02:00
parent d9ba3889c0
commit 814f36d4ee
3 changed files with 65 additions and 35 deletions

View File

@ -1,5 +1,4 @@
import copy
import ipaddress
import json
import os
import shutil
@ -7,7 +6,7 @@ from datetime import datetime, timedelta
from decimal import Decimal
from io import BytesIO
from json.decoder import JSONDecodeError
from typing import Tuple, Type
from typing import Tuple
import pytest
from dateutil.tz import tzutc
@ -15,7 +14,7 @@ from flask import current_app as app
from flask import g
from pytest import raises
from sqlalchemy.util import OrderedSet
from teal.enums import Currency, Subdivision
from teal.enums import Currency
from ereuse_devicehub.client import Client, UserClient
from ereuse_devicehub.db import db
@ -82,11 +81,7 @@ def test_erase_basic():
def test_validate_device_data_storage():
"""Checks the validation for data-storage-only actions works."""
# We can't set a GraphicCard
with pytest.raises(
TypeError,
message='EraseBasic.device must be a DataStorage '
'but you passed <GraphicCard None model=\'foo-bar\' S/N=\'foo\'>',
):
with pytest.raises(TypeError):
models.EraseBasic(
device=GraphicCard(
serial_number='foo', manufacturer='bar', model='foo-bar'
@ -94,6 +89,10 @@ def test_validate_device_data_storage():
clean_with_zeros=True,
**conftest.T,
)
pytest.fail(
'EraseBasic.device must be a DataStorage '
'but you passed <GraphicCard None model=\'foo-bar\' S/N=\'foo\'>'
)
@pytest.mark.mvp
@ -292,9 +291,7 @@ def test_generic_action(
for ams in [models.Recycling, models.Use, models.Refurbish, models.Management]
),
)
def test_simple_status_actions(
action_model: models.Action, user2: UserClient
):
def test_simple_status_actions(action_model: models.Action, user2: UserClient):
"""Simple test of status action."""
user = user2
snap, _ = user.post(file('basic.snapshot'), res=models.Snapshot)
@ -554,7 +551,9 @@ def test_status_without_lot(action_model: models.Action, user: UserClient):
for ams in [models.Recycling, models.Use, models.Refurbish, models.Management]
),
)
def test_status_in_temporary_lot(action_model: models.Action, user: UserClient, app: Devicehub):
def test_status_in_temporary_lot(
action_model: models.Action, user: UserClient, app: Devicehub
):
"""Test of status actions for devices in a temporary lot."""
snap, _ = user.post(file('basic.snapshot'), res=models.Snapshot)
abstract = Device.query.filter_by(id=snap['device']['id']).first()

View File

@ -21,14 +21,22 @@ def test_authenticate_success(app: Devicehub):
def test_authenticate_error(app: Devicehub):
"""Tests the authenticate method with wrong token values."""
with app.app_context():
MESSAGE = 'Provide a suitable token.'
create_user()
# Token doesn't exist
with pytest.raises(Unauthorized, message=MESSAGE):
with pytest.raises(Unauthorized):
app.auth.authenticate(token=str(uuid4()))
pytest.fail('Provide a suitable token.')
@pytest.mark.mvp
def test_authenticate_error_malformed_token(app: Devicehub):
"""Tests the authenticate method with malformed token."""
with app.app_context():
create_user()
# Wrong token format
with pytest.raises(Unauthorized, message=MESSAGE):
with pytest.raises(Unauthorized):
app.auth.authenticate(token='this is a wrong uuid')
pytest.fail('Provide a suitable token.')
@pytest.mark.mvp
@ -36,4 +44,6 @@ def test_auth_view(user: UserClient, client: Client):
"""Tests authentication at endpoint / view."""
user.get(res='User', item=user.user['id'], status=200)
client.get(res='User', item=user.user['id'], status=Unauthorized)
client.get(res='User', item=user.user['id'], token='wrong token', status=Unauthorized)
client.get(
res='User', item=user.user['id'], token='wrong token', status=Unauthorized
)

View File

@ -21,10 +21,12 @@ from tests.conftest import TestConfig
class NoExcCliRunner(click.testing.CliRunner):
"""Runner that interfaces with the Devicehub CLI."""
def invoke(self, *args, input=None, env=None, catch_exceptions=False, color=False,
**extra):
r = super().invoke(ereuse_devicehub.cli.cli,
args, input, env, catch_exceptions, color, **extra)
def invoke(
self, *args, input=None, env=None, catch_exceptions=False, color=False, **extra
):
r = super().invoke(
ereuse_devicehub.cli.cli, args, input, env, catch_exceptions, color, **extra
)
assert r.exit_code == 0, 'CLI code {}: {}'.format(r.exit_code, r.output)
return r
@ -69,16 +71,26 @@ def test_inventory_create_delete_user(cli, tdb1, tdb2):
"""
# Create first DB
cli.inv('tdb1')
cli.invoke('inv', 'add',
'-n', 'Test DB1',
'-on', 'ACME DB1',
'-oi', 'acme-id',
'-tu', 'https://example.com',
'-tt', '3c66a6ad-22de-4db6-ac46-d8982522ec40',
'--common')
cli.invoke(
'inv',
'add',
'-n',
'Test DB1',
'-on',
'ACME DB1',
'-oi',
'acme-id',
'-tu',
'https://example.com',
'-tt',
'3c66a6ad-22de-4db6-ac46-d8982522ec40',
'--common',
)
# Create an user for first DB
cli.invoke('user', 'add', 'foo@foo.com', '-a', 'Foo', '-c', 'ES', '-p', 'Such password')
cli.invoke(
'user', 'add', 'foo@foo.com', '-a', 'Foo', '-c', 'ES', '-p', 'Such password'
)
with tdb1.app_context():
# There is a row for the inventory
@ -98,12 +110,20 @@ def test_inventory_create_delete_user(cli, tdb1, tdb2):
cli.inv('tdb2')
# Create a second DB
# Note how we don't create common anymore
cli.invoke('inv', 'add',
'-n', 'Test DB2',
'-on', 'ACME DB2',
'-oi', 'acme-id-2',
'-tu', 'https://example.com',
'-tt', 'fbad1c08-ffdc-4a61-be49-464962c186a8')
cli.invoke(
'inv',
'add',
'-n',
'Test DB2',
'-on',
'ACME DB2',
'-oi',
'acme-id-2',
'-tu',
'https://example.com',
'-tt',
'fbad1c08-ffdc-4a61-be49-464962c186a8',
)
# Create an user for with access for both DB
cli.invoke('user', 'add', 'bar@bar.com', '-a', 'Bar', '-p', 'Wow password')
@ -144,5 +164,6 @@ def test_create_existing_inventory(cli, tdb1):
cli.invoke('inv', 'add', '--common')
with tdb1.app_context():
assert db.has_schema('tdb1')
with pytest.raises(AssertionError, message='Schema tdb1 already exists.'):
with pytest.raises(AssertionError):
cli.invoke('inv', 'add', '--common')
pytest.fail('Schema tdb1 already exists.')