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:
parent
d9ba3889c0
commit
814f36d4ee
|
@ -1,5 +1,4 @@
|
||||||
import copy
|
import copy
|
||||||
import ipaddress
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -7,7 +6,7 @@ from datetime import datetime, timedelta
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from json.decoder import JSONDecodeError
|
from json.decoder import JSONDecodeError
|
||||||
from typing import Tuple, Type
|
from typing import Tuple
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from dateutil.tz import tzutc
|
from dateutil.tz import tzutc
|
||||||
|
@ -15,7 +14,7 @@ from flask import current_app as app
|
||||||
from flask import g
|
from flask import g
|
||||||
from pytest import raises
|
from pytest import raises
|
||||||
from sqlalchemy.util import OrderedSet
|
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.client import Client, UserClient
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
|
@ -82,11 +81,7 @@ def test_erase_basic():
|
||||||
def test_validate_device_data_storage():
|
def test_validate_device_data_storage():
|
||||||
"""Checks the validation for data-storage-only actions works."""
|
"""Checks the validation for data-storage-only actions works."""
|
||||||
# We can't set a GraphicCard
|
# We can't set a GraphicCard
|
||||||
with pytest.raises(
|
with pytest.raises(TypeError):
|
||||||
TypeError,
|
|
||||||
message='EraseBasic.device must be a DataStorage '
|
|
||||||
'but you passed <GraphicCard None model=\'foo-bar\' S/N=\'foo\'>',
|
|
||||||
):
|
|
||||||
models.EraseBasic(
|
models.EraseBasic(
|
||||||
device=GraphicCard(
|
device=GraphicCard(
|
||||||
serial_number='foo', manufacturer='bar', model='foo-bar'
|
serial_number='foo', manufacturer='bar', model='foo-bar'
|
||||||
|
@ -94,6 +89,10 @@ def test_validate_device_data_storage():
|
||||||
clean_with_zeros=True,
|
clean_with_zeros=True,
|
||||||
**conftest.T,
|
**conftest.T,
|
||||||
)
|
)
|
||||||
|
pytest.fail(
|
||||||
|
'EraseBasic.device must be a DataStorage '
|
||||||
|
'but you passed <GraphicCard None model=\'foo-bar\' S/N=\'foo\'>'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
|
@ -292,9 +291,7 @@ def test_generic_action(
|
||||||
for ams in [models.Recycling, models.Use, models.Refurbish, models.Management]
|
for ams in [models.Recycling, models.Use, models.Refurbish, models.Management]
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
def test_simple_status_actions(
|
def test_simple_status_actions(action_model: models.Action, user2: UserClient):
|
||||||
action_model: models.Action, user2: UserClient
|
|
||||||
):
|
|
||||||
"""Simple test of status action."""
|
"""Simple test of status action."""
|
||||||
user = user2
|
user = user2
|
||||||
snap, _ = user.post(file('basic.snapshot'), res=models.Snapshot)
|
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]
|
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."""
|
"""Test of status actions for devices in a temporary lot."""
|
||||||
snap, _ = user.post(file('basic.snapshot'), res=models.Snapshot)
|
snap, _ = user.post(file('basic.snapshot'), res=models.Snapshot)
|
||||||
abstract = Device.query.filter_by(id=snap['device']['id']).first()
|
abstract = Device.query.filter_by(id=snap['device']['id']).first()
|
||||||
|
|
|
@ -21,14 +21,22 @@ def test_authenticate_success(app: Devicehub):
|
||||||
def test_authenticate_error(app: Devicehub):
|
def test_authenticate_error(app: Devicehub):
|
||||||
"""Tests the authenticate method with wrong token values."""
|
"""Tests the authenticate method with wrong token values."""
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
MESSAGE = 'Provide a suitable token.'
|
|
||||||
create_user()
|
create_user()
|
||||||
# Token doesn't exist
|
# Token doesn't exist
|
||||||
with pytest.raises(Unauthorized, message=MESSAGE):
|
with pytest.raises(Unauthorized):
|
||||||
app.auth.authenticate(token=str(uuid4()))
|
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
|
# Wrong token format
|
||||||
with pytest.raises(Unauthorized, message=MESSAGE):
|
with pytest.raises(Unauthorized):
|
||||||
app.auth.authenticate(token='this is a wrong uuid')
|
app.auth.authenticate(token='this is a wrong uuid')
|
||||||
|
pytest.fail('Provide a suitable token.')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
|
@ -36,4 +44,6 @@ def test_auth_view(user: UserClient, client: Client):
|
||||||
"""Tests authentication at endpoint / view."""
|
"""Tests authentication at endpoint / view."""
|
||||||
user.get(res='User', item=user.user['id'], status=200)
|
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'], 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
|
||||||
|
)
|
||||||
|
|
|
@ -21,10 +21,12 @@ from tests.conftest import TestConfig
|
||||||
class NoExcCliRunner(click.testing.CliRunner):
|
class NoExcCliRunner(click.testing.CliRunner):
|
||||||
"""Runner that interfaces with the Devicehub CLI."""
|
"""Runner that interfaces with the Devicehub CLI."""
|
||||||
|
|
||||||
def invoke(self, *args, input=None, env=None, catch_exceptions=False, color=False,
|
def invoke(
|
||||||
**extra):
|
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)
|
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)
|
assert r.exit_code == 0, 'CLI code {}: {}'.format(r.exit_code, r.output)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
@ -69,16 +71,26 @@ def test_inventory_create_delete_user(cli, tdb1, tdb2):
|
||||||
"""
|
"""
|
||||||
# Create first DB
|
# Create first DB
|
||||||
cli.inv('tdb1')
|
cli.inv('tdb1')
|
||||||
cli.invoke('inv', 'add',
|
cli.invoke(
|
||||||
'-n', 'Test DB1',
|
'inv',
|
||||||
'-on', 'ACME DB1',
|
'add',
|
||||||
'-oi', 'acme-id',
|
'-n',
|
||||||
'-tu', 'https://example.com',
|
'Test DB1',
|
||||||
'-tt', '3c66a6ad-22de-4db6-ac46-d8982522ec40',
|
'-on',
|
||||||
'--common')
|
'ACME DB1',
|
||||||
|
'-oi',
|
||||||
|
'acme-id',
|
||||||
|
'-tu',
|
||||||
|
'https://example.com',
|
||||||
|
'-tt',
|
||||||
|
'3c66a6ad-22de-4db6-ac46-d8982522ec40',
|
||||||
|
'--common',
|
||||||
|
)
|
||||||
|
|
||||||
# Create an user for first DB
|
# 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():
|
with tdb1.app_context():
|
||||||
# There is a row for the inventory
|
# There is a row for the inventory
|
||||||
|
@ -98,12 +110,20 @@ def test_inventory_create_delete_user(cli, tdb1, tdb2):
|
||||||
cli.inv('tdb2')
|
cli.inv('tdb2')
|
||||||
# Create a second DB
|
# Create a second DB
|
||||||
# Note how we don't create common anymore
|
# Note how we don't create common anymore
|
||||||
cli.invoke('inv', 'add',
|
cli.invoke(
|
||||||
'-n', 'Test DB2',
|
'inv',
|
||||||
'-on', 'ACME DB2',
|
'add',
|
||||||
'-oi', 'acme-id-2',
|
'-n',
|
||||||
'-tu', 'https://example.com',
|
'Test DB2',
|
||||||
'-tt', 'fbad1c08-ffdc-4a61-be49-464962c186a8')
|
'-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
|
# Create an user for with access for both DB
|
||||||
cli.invoke('user', 'add', 'bar@bar.com', '-a', 'Bar', '-p', 'Wow password')
|
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')
|
cli.invoke('inv', 'add', '--common')
|
||||||
with tdb1.app_context():
|
with tdb1.app_context():
|
||||||
assert db.has_schema('tdb1')
|
assert db.has_schema('tdb1')
|
||||||
with pytest.raises(AssertionError, message='Schema tdb1 already exists.'):
|
with pytest.raises(AssertionError):
|
||||||
cli.invoke('inv', 'add', '--common')
|
cli.invoke('inv', 'add', '--common')
|
||||||
|
pytest.fail('Schema tdb1 already exists.')
|
||||||
|
|
Reference in New Issue