change start/endtime of tests with dummy values; fix readme for testing
This commit is contained in:
parent
1b66888bd7
commit
9dbe76670c
|
@ -91,6 +91,8 @@ To run the tests you will need to:
|
||||||
2. Create a database for testing. By default the database used is
|
2. Create a database for testing. By default the database used is
|
||||||
`dh_test`. Execute to create it:
|
`dh_test`. Execute to create it:
|
||||||
1. `postgres $ createdb dh_test`.
|
1. `postgres $ createdb dh_test`.
|
||||||
2. `postgres $ psql devicehub`.
|
2. `postgres $ psql dh_test`.
|
||||||
3. `postgres $ GRANT ALL PRIVILEGES ON DATABASE dh_test TO dhub;`.
|
3. `postgres $ GRANT ALL PRIVILEGES ON DATABASE dh_test TO dhub;`.
|
||||||
|
4. `CREATE EXTENSION pgcrypto SCHEMA public;`
|
||||||
|
5. `CREATE EXTENSION ltree SCHEMA public;`
|
||||||
3. Execute at the root folder of the project ``python3 setup.py test``.
|
3. Execute at the root folder of the project ``python3 setup.py test``.
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import io
|
||||||
|
from contextlib import redirect_stdout
|
||||||
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -12,6 +15,13 @@ from ereuse_devicehub.resources.agent.models import Person
|
||||||
from ereuse_devicehub.resources.tag import Tag
|
from ereuse_devicehub.resources.tag import Tag
|
||||||
from ereuse_devicehub.resources.user.models import User
|
from ereuse_devicehub.resources.user.models import User
|
||||||
|
|
||||||
|
STARTT = datetime(year=2000, month=1, day=1, hour=1)
|
||||||
|
"""A dummy starting time to use in tests."""
|
||||||
|
ENDT = datetime(year=2000, month=1, day=1, hour=2)
|
||||||
|
"""A dummy ending time to use in tests."""
|
||||||
|
T = {'start_time': STARTT, 'end_time': ENDT}
|
||||||
|
"""A dummy start_time/end_time to use as function keywords."""
|
||||||
|
|
||||||
|
|
||||||
class TestConfig(DevicehubConfig):
|
class TestConfig(DevicehubConfig):
|
||||||
SQLALCHEMY_DATABASE_URI = 'postgresql://dhub:ereuse@localhost/dh_test'
|
SQLALCHEMY_DATABASE_URI = 'postgresql://dhub:ereuse@localhost/dh_test'
|
||||||
|
@ -40,7 +50,8 @@ def app(request, _app: Devicehub) -> Devicehub:
|
||||||
|
|
||||||
with _app.app_context():
|
with _app.app_context():
|
||||||
try:
|
try:
|
||||||
_app.init_db()
|
with redirect_stdout(io.StringIO()):
|
||||||
|
_app.init_db()
|
||||||
except ProgrammingError:
|
except ProgrammingError:
|
||||||
print('Database was not correctly emptied. Re-empty and re-installing...')
|
print('Database was not correctly emptied. Re-empty and re-installing...')
|
||||||
_drop()
|
_drop()
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import ipaddress
|
import ipaddress
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import timedelta
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from flask import current_app as app, g
|
from flask import current_app as app, g
|
||||||
from sqlalchemy.util import OrderedSet
|
from sqlalchemy.util import OrderedSet
|
||||||
|
from teal.enums import Currency, Subdivision
|
||||||
|
|
||||||
from ereuse_devicehub.client import UserClient
|
from ereuse_devicehub.client import UserClient
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
|
@ -11,7 +12,6 @@ from ereuse_devicehub.resources.device.models import Desktop, Device, GraphicCar
|
||||||
RamModule, SolidStateDrive
|
RamModule, SolidStateDrive
|
||||||
from ereuse_devicehub.resources.enums import ComputerChassis, TestHardDriveLength
|
from ereuse_devicehub.resources.enums import ComputerChassis, TestHardDriveLength
|
||||||
from ereuse_devicehub.resources.event import models
|
from ereuse_devicehub.resources.event import models
|
||||||
from teal.enums import Currency, Subdivision
|
|
||||||
from tests import conftest
|
from tests import conftest
|
||||||
from tests.conftest import create_user, file
|
from tests.conftest import create_user, file
|
||||||
|
|
||||||
|
@ -38,9 +38,7 @@ def test_erase_basic():
|
||||||
erasure = models.EraseBasic(
|
erasure = models.EraseBasic(
|
||||||
device=HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
device=HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
||||||
zeros=True,
|
zeros=True,
|
||||||
start_time=datetime.now(timezone.utc),
|
**conftest.T
|
||||||
end_time=datetime.now(timezone.utc),
|
|
||||||
error=False
|
|
||||||
)
|
)
|
||||||
db.session.add(erasure)
|
db.session.add(erasure)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -59,9 +57,7 @@ def test_validate_device_data_storage():
|
||||||
models.EraseBasic(
|
models.EraseBasic(
|
||||||
device=GraphicCard(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
device=GraphicCard(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
||||||
clean_with_zeros=True,
|
clean_with_zeros=True,
|
||||||
start_time=datetime.now(timezone.utc),
|
**conftest.T
|
||||||
end_time=datetime.now(timezone.utc),
|
|
||||||
error=False
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,20 +66,12 @@ def test_erase_sectors_steps():
|
||||||
erasure = models.EraseSectors(
|
erasure = models.EraseSectors(
|
||||||
device=SolidStateDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
device=SolidStateDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
||||||
zeros=True,
|
zeros=True,
|
||||||
start_time=datetime.now(timezone.utc),
|
|
||||||
end_time=datetime.now(timezone.utc),
|
|
||||||
error=False,
|
|
||||||
steps=[
|
steps=[
|
||||||
models.StepZero(error=False,
|
models.StepZero(**conftest.T),
|
||||||
start_time=datetime.now(timezone.utc),
|
models.StepRandom(**conftest.T),
|
||||||
end_time=datetime.now(timezone.utc)),
|
models.StepZero(**conftest.T)
|
||||||
models.StepRandom(error=False,
|
],
|
||||||
start_time=datetime.now(timezone.utc),
|
**conftest.T
|
||||||
end_time=datetime.now(timezone.utc)),
|
|
||||||
models.StepZero(error=False,
|
|
||||||
start_time=datetime.now(timezone.utc),
|
|
||||||
end_time=datetime.now(timezone.utc))
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
db.session.add(erasure)
|
db.session.add(erasure)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
Reference in New Issue