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
|
||||
`dh_test`. Execute to create it:
|
||||
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;`.
|
||||
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``.
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import io
|
||||
from contextlib import redirect_stdout
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
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.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):
|
||||
SQLALCHEMY_DATABASE_URI = 'postgresql://dhub:ereuse@localhost/dh_test'
|
||||
|
@ -40,6 +50,7 @@ def app(request, _app: Devicehub) -> Devicehub:
|
|||
|
||||
with _app.app_context():
|
||||
try:
|
||||
with redirect_stdout(io.StringIO()):
|
||||
_app.init_db()
|
||||
except ProgrammingError:
|
||||
print('Database was not correctly emptied. Re-empty and re-installing...')
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import ipaddress
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
from flask import current_app as app, g
|
||||
from sqlalchemy.util import OrderedSet
|
||||
from teal.enums import Currency, Subdivision
|
||||
|
||||
from ereuse_devicehub.client import UserClient
|
||||
from ereuse_devicehub.db import db
|
||||
|
@ -11,7 +12,6 @@ from ereuse_devicehub.resources.device.models import Desktop, Device, GraphicCar
|
|||
RamModule, SolidStateDrive
|
||||
from ereuse_devicehub.resources.enums import ComputerChassis, TestHardDriveLength
|
||||
from ereuse_devicehub.resources.event import models
|
||||
from teal.enums import Currency, Subdivision
|
||||
from tests import conftest
|
||||
from tests.conftest import create_user, file
|
||||
|
||||
|
@ -38,9 +38,7 @@ def test_erase_basic():
|
|||
erasure = models.EraseBasic(
|
||||
device=HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
||||
zeros=True,
|
||||
start_time=datetime.now(timezone.utc),
|
||||
end_time=datetime.now(timezone.utc),
|
||||
error=False
|
||||
**conftest.T
|
||||
)
|
||||
db.session.add(erasure)
|
||||
db.session.commit()
|
||||
|
@ -59,9 +57,7 @@ def test_validate_device_data_storage():
|
|||
models.EraseBasic(
|
||||
device=GraphicCard(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
||||
clean_with_zeros=True,
|
||||
start_time=datetime.now(timezone.utc),
|
||||
end_time=datetime.now(timezone.utc),
|
||||
error=False
|
||||
**conftest.T
|
||||
)
|
||||
|
||||
|
||||
|
@ -70,20 +66,12 @@ def test_erase_sectors_steps():
|
|||
erasure = models.EraseSectors(
|
||||
device=SolidStateDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
||||
zeros=True,
|
||||
start_time=datetime.now(timezone.utc),
|
||||
end_time=datetime.now(timezone.utc),
|
||||
error=False,
|
||||
steps=[
|
||||
models.StepZero(error=False,
|
||||
start_time=datetime.now(timezone.utc),
|
||||
end_time=datetime.now(timezone.utc)),
|
||||
models.StepRandom(error=False,
|
||||
start_time=datetime.now(timezone.utc),
|
||||
end_time=datetime.now(timezone.utc)),
|
||||
models.StepZero(error=False,
|
||||
start_time=datetime.now(timezone.utc),
|
||||
end_time=datetime.now(timezone.utc))
|
||||
]
|
||||
models.StepZero(**conftest.T),
|
||||
models.StepRandom(**conftest.T),
|
||||
models.StepZero(**conftest.T)
|
||||
],
|
||||
**conftest.T
|
||||
)
|
||||
db.session.add(erasure)
|
||||
db.session.commit()
|
||||
|
|
Reference in a new issue