2020-07-07 15:17:41 +00:00
|
|
|
import csv
|
2020-12-21 10:34:03 +00:00
|
|
|
import hashlib
|
2020-07-07 15:17:41 +00:00
|
|
|
from datetime import datetime
|
2021-02-17 22:14:40 +00:00
|
|
|
from io import StringIO, BytesIO
|
2020-07-07 15:17:41 +00:00
|
|
|
from pathlib import Path
|
2021-02-17 22:14:40 +00:00
|
|
|
from flask import url_for
|
2018-11-21 13:26:56 +00:00
|
|
|
|
2020-08-17 09:18:52 +00:00
|
|
|
import pytest
|
2020-11-06 16:14:16 +00:00
|
|
|
from werkzeug.exceptions import Unauthorized
|
2020-08-17 09:18:52 +00:00
|
|
|
import teal.marshmallow
|
|
|
|
from ereuse_utils.test import ANY
|
|
|
|
|
2021-04-15 19:16:04 +00:00
|
|
|
from ereuse_devicehub import auth
|
2018-11-21 13:26:56 +00:00
|
|
|
from ereuse_devicehub.client import Client, UserClient
|
2020-10-21 11:05:28 +00:00
|
|
|
from ereuse_devicehub.devicehub import Devicehub
|
2021-04-13 16:34:18 +00:00
|
|
|
from ereuse_devicehub.resources.user.models import Session
|
2021-01-14 16:32:03 +00:00
|
|
|
from ereuse_devicehub.resources.action.models import Snapshot, Allocate, Live
|
2020-07-07 15:17:41 +00:00
|
|
|
from ereuse_devicehub.resources.documents import documents
|
2021-08-03 14:40:17 +00:00
|
|
|
from ereuse_devicehub.resources.tradedocument.models import TradeDocument
|
2020-10-21 11:05:28 +00:00
|
|
|
from ereuse_devicehub.resources.device import models as d
|
2020-07-28 14:14:56 +00:00
|
|
|
from ereuse_devicehub.resources.lot.models import Lot
|
2020-10-21 11:05:28 +00:00
|
|
|
from ereuse_devicehub.resources.tag.model import Tag
|
2020-12-21 10:34:03 +00:00
|
|
|
from ereuse_devicehub.resources.hash_reports import ReportHash
|
2021-04-13 16:34:18 +00:00
|
|
|
from ereuse_devicehub.resources.enums import SessionType
|
2020-10-21 11:05:28 +00:00
|
|
|
from ereuse_devicehub.db import db
|
2020-12-21 10:34:03 +00:00
|
|
|
from tests import conftest
|
2021-07-02 15:40:20 +00:00
|
|
|
from tests.conftest import file, yaml2json, json_encode
|
2018-11-21 13:26:56 +00:00
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
@pytest.mark.mvp
|
2018-11-21 13:26:56 +00:00
|
|
|
def test_erasure_certificate_public_one(user: UserClient, client: Client):
|
|
|
|
"""Public user can get certificate from one device as HTML or PDF."""
|
|
|
|
s = file('erase-sectors.snapshot')
|
2020-07-07 15:17:41 +00:00
|
|
|
snapshot, _ = user.post(s, res=Snapshot)
|
2018-11-21 13:26:56 +00:00
|
|
|
|
2020-08-05 16:19:27 +00:00
|
|
|
doc, response = user.get(res=documents.DocumentDef.t,
|
2021-08-02 08:46:35 +00:00
|
|
|
item='erasures/{}'.format(
|
|
|
|
snapshot['device']['id']),
|
|
|
|
accept=ANY)
|
2018-11-21 13:26:56 +00:00
|
|
|
assert 'html' in response.content_type
|
|
|
|
assert '<html' in doc
|
|
|
|
assert '2018' in doc
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
doc, response = client.get(res=documents.DocumentDef.t,
|
2021-08-02 08:46:35 +00:00
|
|
|
item='erasures/{}'.format(
|
|
|
|
snapshot['device']['id']),
|
2018-11-21 13:26:56 +00:00
|
|
|
query=[('format', 'PDF')],
|
|
|
|
accept='application/pdf')
|
|
|
|
assert 'application/pdf' == response.content_type
|
|
|
|
|
2021-08-02 08:46:35 +00:00
|
|
|
erasure = next(e for e in snapshot['actions']
|
|
|
|
if e['type'] == 'EraseSectors')
|
2018-11-21 13:26:56 +00:00
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
doc, response = client.get(res=documents.DocumentDef.t,
|
2018-11-21 13:26:56 +00:00
|
|
|
item='erasures/{}'.format(erasure['id']),
|
|
|
|
accept=ANY)
|
|
|
|
assert 'html' in response.content_type
|
|
|
|
assert '<html' in doc
|
|
|
|
assert '2018' in doc
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
@pytest.mark.mvp
|
2018-11-21 13:26:56 +00:00
|
|
|
def test_erasure_certificate_private_query(user: UserClient):
|
|
|
|
"""Logged-in user can get certificates using queries as HTML and
|
|
|
|
PDF.
|
|
|
|
"""
|
|
|
|
s = file('erase-sectors.snapshot')
|
2020-07-07 15:17:41 +00:00
|
|
|
snapshot, response = user.post(s, res=Snapshot)
|
2018-11-21 13:26:56 +00:00
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
doc, response = user.get(res=documents.DocumentDef.t,
|
2018-11-21 13:26:56 +00:00
|
|
|
item='erasures/',
|
2021-08-02 08:46:35 +00:00
|
|
|
query=[
|
2021-12-21 09:32:04 +00:00
|
|
|
('filter', {'ids': [snapshot['device']['id']]})],
|
2018-11-21 13:26:56 +00:00
|
|
|
accept=ANY)
|
|
|
|
assert 'html' in response.content_type
|
|
|
|
assert '<html' in doc
|
|
|
|
assert '2018' in doc
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
doc, response = user.get(res=documents.DocumentDef.t,
|
2018-11-21 13:26:56 +00:00
|
|
|
item='erasures/',
|
|
|
|
query=[
|
2021-08-02 08:46:35 +00:00
|
|
|
('filter', {
|
2021-12-21 09:32:04 +00:00
|
|
|
'ids': [snapshot['device']['id']]}),
|
2018-11-21 13:26:56 +00:00
|
|
|
('format', 'PDF')
|
|
|
|
],
|
|
|
|
accept='application/pdf')
|
|
|
|
assert 'application/pdf' == response.content_type
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
@pytest.mark.mvp
|
2018-11-21 13:26:56 +00:00
|
|
|
def test_erasure_certificate_wrong_id(client: Client):
|
2020-07-07 15:17:41 +00:00
|
|
|
client.get(res=documents.DocumentDef.t, item='erasures/this-is-not-an-id',
|
2018-11-21 13:26:56 +00:00
|
|
|
status=teal.marshmallow.ValidationError)
|
2020-07-07 15:17:41 +00:00
|
|
|
|
|
|
|
|
2020-11-06 16:14:16 +00:00
|
|
|
@pytest.mark.mvp
|
|
|
|
def test_export_csv_permitions(user: UserClient, user2: UserClient, client: Client):
|
2021-01-08 16:37:52 +00:00
|
|
|
"""test export device information in a csv file with others users."""
|
2020-11-06 16:14:16 +00:00
|
|
|
snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot)
|
2021-12-16 13:00:54 +00:00
|
|
|
dev_id = snapshot['device']['id']
|
2020-11-06 16:14:16 +00:00
|
|
|
csv_user, _ = user.get(res=documents.DocumentDef.t,
|
2021-08-02 08:46:35 +00:00
|
|
|
item='devices/',
|
|
|
|
accept='text/csv',
|
2021-12-16 13:00:54 +00:00
|
|
|
query=[('filter', {'type': ['Computer'], 'ids': [dev_id]})])
|
2020-11-06 16:14:16 +00:00
|
|
|
|
|
|
|
csv_user2, _ = user2.get(res=documents.DocumentDef.t,
|
2021-08-02 08:46:35 +00:00
|
|
|
item='devices/',
|
|
|
|
accept='text/csv',
|
2021-12-16 13:00:54 +00:00
|
|
|
query=[('filter', {'type': ['Computer'], 'ids': [dev_id]})])
|
2020-11-06 16:14:16 +00:00
|
|
|
|
|
|
|
_, res = client.get(res=documents.DocumentDef.t,
|
2021-08-02 08:46:35 +00:00
|
|
|
item='devices/',
|
|
|
|
accept='text/csv',
|
2021-12-16 13:00:54 +00:00
|
|
|
query=[('filter', {'type': ['Computer'], 'ids': [dev_id]})], status=401)
|
2020-11-06 16:14:16 +00:00
|
|
|
assert res.status_code == 401
|
|
|
|
|
|
|
|
assert len(csv_user) > 0
|
|
|
|
assert len(csv_user2) == 0
|
|
|
|
|
2020-12-21 10:34:03 +00:00
|
|
|
|
2021-01-08 16:37:52 +00:00
|
|
|
@pytest.mark.mvp
|
|
|
|
def test_export_csv_actions(user: UserClient, user2: UserClient, client: Client):
|
|
|
|
"""Test export device information in a csv file with others users."""
|
2021-07-02 15:40:20 +00:00
|
|
|
acer = yaml2json('acer.happy.battery.snapshot')
|
|
|
|
snapshot, _ = user.post(json_encode(acer), res=Snapshot)
|
2021-01-14 16:32:03 +00:00
|
|
|
device_id = snapshot['device']['id']
|
|
|
|
post_request = {"transaction": "ccc", "name": "John", "endUsers": 1,
|
|
|
|
"devices": [device_id], "description": "aaa",
|
|
|
|
"finalUserCode": "abcdefjhi",
|
|
|
|
"startTime": "2020-11-01T02:00:00+00:00",
|
|
|
|
"endTime": "2020-12-01T02:00:00+00:00"
|
2021-08-02 08:46:35 +00:00
|
|
|
}
|
2021-01-14 16:32:03 +00:00
|
|
|
|
|
|
|
user.post(res=Allocate, data=post_request)
|
|
|
|
hdd = [c for c in acer['components'] if c['type'] == 'HardDrive'][0]
|
2021-08-02 08:46:35 +00:00
|
|
|
hdd_action = [a for a in hdd['actions']
|
|
|
|
if a['type'] == 'TestDataStorage'][0]
|
2021-01-14 16:32:03 +00:00
|
|
|
hdd_action['lifetime'] += 1000
|
|
|
|
acer.pop('elapsed')
|
|
|
|
acer['licence_version'] = '1.0.0'
|
|
|
|
snapshot, _ = client.post(acer, res=Live)
|
|
|
|
|
2021-01-08 16:37:52 +00:00
|
|
|
csv_user, _ = user.get(res=documents.DocumentDef.t,
|
2021-08-02 08:46:35 +00:00
|
|
|
item='actions/',
|
|
|
|
accept='text/csv',
|
2021-12-09 09:59:26 +00:00
|
|
|
query=[('filter', {'type': ['Computer'], 'ids': [device_id]})])
|
2021-01-08 16:37:52 +00:00
|
|
|
|
|
|
|
csv_user2, _ = user2.get(res=documents.DocumentDef.t,
|
2021-08-02 08:46:35 +00:00
|
|
|
item='actions/',
|
|
|
|
accept='text/csv',
|
|
|
|
query=[('filter', {'type': ['Computer']})])
|
2021-01-08 16:37:52 +00:00
|
|
|
|
|
|
|
_, res = client.get(res=documents.DocumentDef.t,
|
2021-08-02 08:46:35 +00:00
|
|
|
item='actions/',
|
|
|
|
accept='text/csv',
|
|
|
|
query=[('filter', {'type': ['Computer']})], status=401)
|
2021-01-08 16:37:52 +00:00
|
|
|
assert res.status_code == 401
|
|
|
|
|
|
|
|
assert len(csv_user) > 0
|
|
|
|
assert len(csv_user2) == 0
|
|
|
|
|
|
|
|
|
2021-01-19 15:06:46 +00:00
|
|
|
@pytest.mark.mvp
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
|
|
|
def test_live_export_csv2(user: UserClient, client: Client, app: Devicehub):
|
|
|
|
"""Tests inserting a Live into the database and GETting it."""
|
2021-07-02 15:40:20 +00:00
|
|
|
acer = yaml2json('acer-happy.snapshot-test1')
|
|
|
|
snapshot, _ = user.post(json_encode(acer), res=Snapshot)
|
2021-01-19 15:06:46 +00:00
|
|
|
device_id = snapshot['device']['id']
|
|
|
|
post_request = {"transaction": "ccc", "name": "John", "endUsers": 1,
|
|
|
|
"devices": [device_id], "description": "aaa",
|
|
|
|
"finalUserCode": "abcdefjhi",
|
|
|
|
"startTime": "2020-11-01T02:00:00+00:00",
|
|
|
|
"endTime": "2020-12-01T02:00:00+00:00"
|
2021-08-02 08:46:35 +00:00
|
|
|
}
|
2021-01-19 15:06:46 +00:00
|
|
|
|
|
|
|
user.post(res=Allocate, data=post_request)
|
|
|
|
|
2021-07-02 15:40:20 +00:00
|
|
|
acer = yaml2json('acer-happy.live-test1')
|
2021-01-19 15:06:46 +00:00
|
|
|
live, _ = client.post(acer, res=Live)
|
|
|
|
csv_user, _ = user.get(res=documents.DocumentDef.t,
|
2021-08-02 08:46:35 +00:00
|
|
|
item='actions/',
|
|
|
|
accept='text/csv',
|
2021-12-09 09:59:26 +00:00
|
|
|
query=[('filter', {'type': ['Computer'], 'ids': [device_id]})])
|
2021-01-19 15:06:46 +00:00
|
|
|
|
|
|
|
assert "4692" in csv_user
|
|
|
|
assert "8692" in csv_user
|
2021-09-22 10:18:10 +00:00
|
|
|
assert "DHID" in csv_user
|
2021-01-19 15:06:46 +00:00
|
|
|
|
2021-08-02 08:46:35 +00:00
|
|
|
|
2021-01-19 15:06:46 +00:00
|
|
|
@pytest.mark.mvp
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
|
|
|
def test_live_example2(user: UserClient, client: Client, app: Devicehub):
|
|
|
|
"""Tests inserting a Live into the database and GETting it."""
|
2021-07-02 15:40:20 +00:00
|
|
|
acer = yaml2json('acer-happy.snapshot-test1')
|
|
|
|
snapshot, _ = user.post(json_encode(acer), res=Snapshot)
|
2021-01-19 15:06:46 +00:00
|
|
|
device_id = snapshot['device']['id']
|
|
|
|
post_request = {"transaction": "ccc", "name": "John", "endUsers": 1,
|
|
|
|
"devices": [device_id], "description": "aaa",
|
|
|
|
"finalUserCode": "abcdefjhi",
|
|
|
|
"startTime": "2020-11-01T02:00:00+00:00",
|
|
|
|
"endTime": "2020-12-01T02:00:00+00:00"
|
|
|
|
}
|
|
|
|
|
2021-01-19 15:31:01 +00:00
|
|
|
user.post(res=Allocate, data=post_request)
|
2021-01-19 15:06:46 +00:00
|
|
|
|
2021-07-02 15:40:20 +00:00
|
|
|
acer = yaml2json('acer-happy.live-test1')
|
2021-01-19 15:31:01 +00:00
|
|
|
live, _ = client.post(acer, res=Live)
|
|
|
|
db_device = d.Device.query.filter_by(id=device_id).one()
|
2021-01-19 15:06:46 +00:00
|
|
|
action_live = [a for a in db_device.actions if a.type == 'Live']
|
|
|
|
assert len(action_live) == 1
|
|
|
|
assert str(action_live[0].snapshot_uuid) == acer['uuid']
|
|
|
|
|
|
|
|
|
2021-04-13 16:34:18 +00:00
|
|
|
@pytest.mark.mvp
|
2020-07-07 15:17:41 +00:00
|
|
|
def test_export_basic_snapshot(user: UserClient):
|
|
|
|
"""Test export device information in a csv file."""
|
|
|
|
snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot)
|
2021-12-16 13:00:54 +00:00
|
|
|
dev_id = snapshot['device']['id']
|
2020-07-07 15:17:41 +00:00
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='devices/',
|
|
|
|
accept='text/csv',
|
2021-12-16 13:00:54 +00:00
|
|
|
query=[('filter', {'type': ['Computer'], 'ids': [dev_id]})])
|
2021-10-23 11:02:10 +00:00
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
f = StringIO(csv_str)
|
2020-10-21 20:33:58 +00:00
|
|
|
obj_csv = csv.reader(f, f, delimiter=';', quotechar='"')
|
2020-07-07 15:17:41 +00:00
|
|
|
export_csv = list(obj_csv)
|
|
|
|
|
|
|
|
# Open fixture csv and transform to list
|
|
|
|
with Path(__file__).parent.joinpath('files').joinpath('basic.csv').open() as csv_file:
|
2020-10-21 20:33:58 +00:00
|
|
|
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"')
|
2020-07-07 15:17:41 +00:00
|
|
|
fixture_csv = list(obj_csv)
|
|
|
|
|
2021-05-26 09:42:42 +00:00
|
|
|
assert isinstance(datetime.strptime(export_csv[1][19], '%c'), datetime), \
|
2020-07-07 15:17:41 +00:00
|
|
|
'Register in field is not a datetime'
|
|
|
|
|
|
|
|
assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
|
2021-05-26 09:42:42 +00:00
|
|
|
assert fixture_csv[1][:19] == export_csv[1][:19], 'Computer information are not equal'
|
|
|
|
assert fixture_csv[1][20] == export_csv[1][20], 'Computer information are not equal'
|
|
|
|
assert fixture_csv[1][22:] == export_csv[1][22:], 'Computer information are not equal'
|
2020-07-07 15:17:41 +00:00
|
|
|
|
2020-12-21 10:34:03 +00:00
|
|
|
|
|
|
|
@pytest.mark.mvp
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2020-12-21 15:09:30 +00:00
|
|
|
def test_check_insert_hash(app: Devicehub, user: UserClient, client: Client):
|
2020-12-21 10:34:03 +00:00
|
|
|
"""Test export device information in a csv file."""
|
|
|
|
snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot)
|
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='devices/',
|
|
|
|
accept='text/csv',
|
|
|
|
query=[('filter', {'type': ['Computer']})])
|
|
|
|
hash3 = hashlib.sha3_256(csv_str.encode('utf-8')).hexdigest()
|
|
|
|
assert ReportHash.query.filter_by(hash3=hash3).count() == 1
|
2020-12-21 15:09:30 +00:00
|
|
|
result, status = client.get(res=documents.DocumentDef.t, item='check/', query=[('hash', hash3)])
|
2020-12-21 12:40:07 +00:00
|
|
|
assert status.status_code == 200
|
2021-10-23 11:02:10 +00:00
|
|
|
assert result
|
2020-12-21 10:34:03 +00:00
|
|
|
|
2020-12-21 15:09:30 +00:00
|
|
|
ff = open('/tmp/test.csv', 'w')
|
|
|
|
ff.write(csv_str)
|
|
|
|
ff.close()
|
|
|
|
|
2021-10-23 11:02:10 +00:00
|
|
|
a = open('/tmp/test.csv').read()
|
2020-12-21 15:09:30 +00:00
|
|
|
assert hash3 == hashlib.sha3_256(a.encode('utf-8')).hexdigest()
|
|
|
|
|
2020-12-21 10:34:03 +00:00
|
|
|
|
2020-10-19 11:06:54 +00:00
|
|
|
@pytest.mark.mvp
|
2020-10-21 11:05:28 +00:00
|
|
|
def test_export_extended(app: Devicehub, user: UserClient):
|
2020-10-19 11:06:54 +00:00
|
|
|
"""Test a export device with all information and a lot of components."""
|
2020-10-21 20:07:56 +00:00
|
|
|
snapshot1, _ = user.post(file('real-eee-1001pxd.snapshot.12'), res=Snapshot, status=201)
|
|
|
|
snapshot2, _ = user.post(file('complete.export.snapshot'), res=Snapshot, status=201)
|
2021-12-16 13:00:54 +00:00
|
|
|
dev1_id = snapshot1['device']['id']
|
|
|
|
dev2_id = snapshot2['device']['id']
|
2020-10-21 11:05:28 +00:00
|
|
|
with app.app_context():
|
|
|
|
# Create a pc with a tag
|
2021-12-16 13:00:54 +00:00
|
|
|
pc = d.Device.query.filter_by(id=dev1_id).first()
|
2020-10-21 11:05:28 +00:00
|
|
|
db.session.add(pc)
|
|
|
|
db.session.commit()
|
2021-04-16 09:14:36 +00:00
|
|
|
|
2020-10-19 11:06:54 +00:00
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='devices/',
|
|
|
|
accept='text/csv',
|
2021-12-16 13:00:54 +00:00
|
|
|
query=[('filter', {'type': ['Computer'], 'ids': [dev1_id, dev2_id]})])
|
2020-10-21 11:05:28 +00:00
|
|
|
|
2020-10-19 11:06:54 +00:00
|
|
|
f = StringIO(csv_str)
|
2020-10-21 20:07:56 +00:00
|
|
|
obj_csv = csv.reader(f, f, delimiter=';', quotechar='"')
|
2020-10-19 11:06:54 +00:00
|
|
|
export_csv = list(obj_csv)
|
|
|
|
|
|
|
|
# Open fixture csv and transform to list
|
|
|
|
with Path(__file__).parent.joinpath('files').joinpath(
|
|
|
|
'proposal_extended_csv_report.csv').open() as csv_file:
|
2020-10-21 20:07:56 +00:00
|
|
|
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"')
|
2020-10-19 11:06:54 +00:00
|
|
|
fixture_csv = list(obj_csv)
|
|
|
|
|
2021-05-26 09:42:42 +00:00
|
|
|
assert isinstance(datetime.strptime(export_csv[1][19], '%c'), datetime), \
|
2020-10-21 20:33:58 +00:00
|
|
|
'Register in field is not a datetime'
|
|
|
|
|
2020-10-21 20:07:56 +00:00
|
|
|
assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
|
2021-05-26 09:42:42 +00:00
|
|
|
assert fixture_csv[1][:19] == export_csv[1][:19], 'Computer information are not equal'
|
|
|
|
assert fixture_csv[1][20] == export_csv[1][20], 'Computer information are not equal'
|
2021-08-02 08:46:35 +00:00
|
|
|
assert fixture_csv[1][22:82] == export_csv[1][22:82], 'Computer information are not equal'
|
|
|
|
assert fixture_csv[1][83] == export_csv[1][83], 'Computer information are not equal'
|
|
|
|
assert fixture_csv[1][86:] == export_csv[1][86:], 'Computer information are not equal'
|
2021-05-26 09:42:42 +00:00
|
|
|
assert fixture_csv[2][:19] == export_csv[2][:19], 'Computer information are not equal'
|
|
|
|
assert fixture_csv[2][20] == export_csv[2][20], 'Computer information are not equal'
|
2021-08-02 08:46:35 +00:00
|
|
|
assert fixture_csv[2][22:82] == export_csv[2][22:82], 'Computer information are not equal'
|
|
|
|
assert fixture_csv[2][83] == export_csv[2][83], 'Computer information are not equal'
|
|
|
|
assert fixture_csv[2][86:106] == export_csv[2][86:106], 'Computer information are not equal'
|
2021-11-23 14:27:16 +00:00
|
|
|
assert fixture_csv[2][109] == export_csv[2][109], 'Computer information are not equal'
|
|
|
|
assert fixture_csv[2][112:133] == export_csv[2][112:133], 'Computer information are not equal'
|
|
|
|
assert fixture_csv[2][135] == export_csv[2][135], 'Computer information are not equal'
|
|
|
|
assert fixture_csv[2][138:] == export_csv[2][138:], 'Computer information are not equal'
|
2020-10-19 11:06:54 +00:00
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
@pytest.mark.mvp
|
|
|
|
def test_export_empty(user: UserClient):
|
|
|
|
"""Test to check works correctly exporting csv without any information,
|
|
|
|
export a placeholder device.
|
|
|
|
"""
|
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
accept='text/csv',
|
|
|
|
item='devices/')
|
|
|
|
f = StringIO(csv_str)
|
|
|
|
obj_csv = csv.reader(f, f)
|
|
|
|
export_csv = list(obj_csv)
|
|
|
|
|
|
|
|
assert len(export_csv) == 0, 'Csv is not empty'
|
|
|
|
|
|
|
|
|
2020-08-12 09:59:12 +00:00
|
|
|
@pytest.mark.xfail(reason='Feature not developed (Beta)')
|
2020-07-07 15:17:41 +00:00
|
|
|
def test_export_computer_monitor(user: UserClient):
|
|
|
|
"""Test a export device type computer monitor."""
|
|
|
|
snapshot, _ = user.post(file('computer-monitor.snapshot'), res=Snapshot)
|
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='devices/',
|
|
|
|
accept='text/csv',
|
|
|
|
query=[('filter', {'type': ['ComputerMonitor']})])
|
|
|
|
f = StringIO(csv_str)
|
|
|
|
obj_csv = csv.reader(f, f)
|
|
|
|
export_csv = list(obj_csv)
|
|
|
|
# Open fixture csv and transform to list
|
|
|
|
with Path(__file__).parent.joinpath('files').joinpath('computer-monitor.csv').open() \
|
|
|
|
as csv_file:
|
|
|
|
obj_csv = csv.reader(csv_file)
|
|
|
|
fixture_csv = list(obj_csv)
|
|
|
|
|
|
|
|
# Pop dates fields from csv lists to compare them
|
|
|
|
fixture_csv[1] = fixture_csv[1][:8]
|
|
|
|
export_csv[1] = export_csv[1][:8]
|
|
|
|
|
|
|
|
assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
|
|
|
|
assert fixture_csv[1] == export_csv[1], 'Component information are not equal'
|
|
|
|
|
|
|
|
|
2020-08-12 09:59:12 +00:00
|
|
|
@pytest.mark.xfail(reason='Feature not developed (Beta)')
|
2020-07-07 15:17:41 +00:00
|
|
|
def test_export_keyboard(user: UserClient):
|
|
|
|
"""Test a export device type keyboard."""
|
|
|
|
snapshot, _ = user.post(file('keyboard.snapshot'), res=Snapshot)
|
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='devices/',
|
|
|
|
accept='text/csv',
|
|
|
|
query=[('filter', {'type': ['Keyboard']})])
|
|
|
|
f = StringIO(csv_str)
|
|
|
|
obj_csv = csv.reader(f, f)
|
|
|
|
export_csv = list(obj_csv)
|
|
|
|
# Open fixture csv and transform to list
|
|
|
|
with Path(__file__).parent.joinpath('files').joinpath('keyboard.csv').open() as csv_file:
|
|
|
|
obj_csv = csv.reader(csv_file)
|
|
|
|
fixture_csv = list(obj_csv)
|
|
|
|
|
|
|
|
# Pop dates fields from csv lists to compare them
|
|
|
|
fixture_csv[1] = fixture_csv[1][:8]
|
|
|
|
export_csv[1] = export_csv[1][:8]
|
|
|
|
|
|
|
|
assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
|
|
|
|
assert fixture_csv[1] == export_csv[1], 'Component information are not equal'
|
|
|
|
|
|
|
|
|
2020-08-12 09:59:12 +00:00
|
|
|
@pytest.mark.xfail(reason='Feature not developed (Beta)')
|
2020-07-07 15:17:41 +00:00
|
|
|
def test_export_multiple_different_devices(user: UserClient):
|
|
|
|
"""Test function 'Export' of multiple different device types (like
|
|
|
|
computers, keyboards, monitors, etc..)
|
|
|
|
"""
|
|
|
|
# Open fixture csv and transform to list
|
|
|
|
with Path(__file__).parent.joinpath('files').joinpath('multiples_devices.csv').open() \
|
|
|
|
as csv_file:
|
|
|
|
fixture_csv = list(csv.reader(csv_file))
|
|
|
|
for row in fixture_csv:
|
|
|
|
del row[8] # We remove the 'Registered in' column
|
|
|
|
|
|
|
|
# Post all devices snapshots
|
|
|
|
snapshot_pc, _ = user.post(file('real-eee-1001pxd.snapshot.11'), res=Snapshot)
|
|
|
|
snapshot_empty, _ = user.post(file('basic.snapshot'), res=Snapshot)
|
|
|
|
snapshot_keyboard, _ = user.post(file('keyboard.snapshot'), res=Snapshot)
|
|
|
|
snapshot_monitor, _ = user.post(file('computer-monitor.snapshot'), res=Snapshot)
|
|
|
|
|
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='devices/',
|
|
|
|
query=[('filter', {'type': ['Computer', 'Keyboard', 'Monitor']})],
|
|
|
|
accept='text/csv')
|
|
|
|
f = StringIO(csv_str)
|
|
|
|
obj_csv = csv.reader(f, f)
|
|
|
|
export_csv = list(obj_csv)
|
|
|
|
|
|
|
|
for row in export_csv:
|
|
|
|
del row[8]
|
|
|
|
|
|
|
|
assert fixture_csv == export_csv
|
2020-07-28 14:14:56 +00:00
|
|
|
|
|
|
|
|
2020-07-27 11:57:31 +00:00
|
|
|
@pytest.mark.mvp
|
2020-08-05 10:24:36 +00:00
|
|
|
def test_report_devices_stock_control(user: UserClient, user2: UserClient):
|
2020-07-27 11:57:31 +00:00
|
|
|
"""Test export device information in a csv file."""
|
|
|
|
snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot)
|
2020-08-05 10:24:36 +00:00
|
|
|
snapshot2, _ = user2.post(file('basic.snapshot2'), res=Snapshot)
|
|
|
|
|
2020-07-27 11:57:31 +00:00
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='stock/',
|
|
|
|
accept='text/csv',
|
|
|
|
query=[('filter', {'type': ['Computer']})])
|
|
|
|
f = StringIO(csv_str)
|
|
|
|
obj_csv = csv.reader(f, f)
|
|
|
|
export_csv = list(obj_csv)
|
|
|
|
|
|
|
|
# Open fixture csv and transform to list
|
|
|
|
with Path(__file__).parent.joinpath('files').joinpath('basic-stock.csv').open() as csv_file:
|
|
|
|
obj_csv = csv.reader(csv_file)
|
|
|
|
fixture_csv = list(obj_csv)
|
|
|
|
|
2020-08-05 10:24:36 +00:00
|
|
|
assert user.user['id'] != user2.user['id']
|
|
|
|
assert len(export_csv) == 2
|
|
|
|
|
2021-02-22 21:08:14 +00:00
|
|
|
export_csv[0] = export_csv[0][0].split(';')
|
|
|
|
export_csv[1] = export_csv[1][0].split(';')
|
2020-07-27 11:57:31 +00:00
|
|
|
assert isinstance(datetime.strptime(export_csv[1][5], '%c'), datetime), \
|
|
|
|
'Register in field is not a datetime'
|
|
|
|
|
|
|
|
# Pop dates fields from csv lists to compare them
|
|
|
|
fixture_csv[1] = fixture_csv[1][:5] + fixture_csv[1][6:]
|
|
|
|
export_csv[1] = export_csv[1][:5] + export_csv[1][6:]
|
|
|
|
|
|
|
|
assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
|
|
|
|
assert fixture_csv[1] == export_csv[1], 'Computer information are not equal'
|
2020-08-18 17:31:43 +00:00
|
|
|
assert fixture_csv == export_csv
|
|
|
|
|
|
|
|
|
2020-07-28 14:14:56 +00:00
|
|
|
@pytest.mark.mvp
|
2020-08-18 19:02:47 +00:00
|
|
|
def test_get_document_lots(user: UserClient, user2: UserClient):
|
2020-07-28 14:14:56 +00:00
|
|
|
"""Tests submitting and retreiving all lots."""
|
|
|
|
|
2020-08-18 19:02:47 +00:00
|
|
|
l, _ = user.post({'name': 'Lot1', 'description': 'comments,lot1,testcomment-lot1,'}, res=Lot)
|
|
|
|
l, _ = user.post({'name': 'Lot2', 'description': 'comments,lot2,testcomment-lot2,'}, res=Lot)
|
|
|
|
l, _ = user2.post({'name': 'Lot3-User2', 'description': 'comments,lot3,testcomment-lot3,'}, res=Lot)
|
2020-07-28 14:14:56 +00:00
|
|
|
|
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='lots/',
|
|
|
|
accept='text/csv')
|
2020-08-18 19:02:47 +00:00
|
|
|
|
|
|
|
csv2_str, _ = user2.get(res=documents.DocumentDef.t,
|
|
|
|
item='lots/',
|
|
|
|
accept='text/csv')
|
|
|
|
|
2020-07-28 14:14:56 +00:00
|
|
|
f = StringIO(csv_str)
|
|
|
|
obj_csv = csv.reader(f, f)
|
|
|
|
export_csv = list(obj_csv)
|
2020-08-18 19:02:47 +00:00
|
|
|
|
|
|
|
f = StringIO(csv2_str)
|
|
|
|
obj2_csv = csv.reader(f, f)
|
|
|
|
export2_csv = list(obj2_csv)
|
|
|
|
|
|
|
|
assert len(export_csv) == 3
|
|
|
|
assert len(export2_csv) == 2
|
|
|
|
|
|
|
|
assert export_csv[0] == export2_csv[0] == ['Id', 'Name', 'Registered in', 'Description']
|
|
|
|
|
|
|
|
assert export_csv[1][1] == 'Lot1' or 'Lot2'
|
|
|
|
assert export_csv[1][3] == 'comments,lot1,testcomment-lot1,' or 'comments,lot2,testcomment-lot2,'
|
|
|
|
assert export2_csv[1][1] == 'Lot3-User2'
|
|
|
|
assert export2_csv[1][3] == 'comments,lot3,testcomment-lot3,'
|
2021-02-19 11:53:42 +00:00
|
|
|
|
|
|
|
|
2021-04-13 16:34:18 +00:00
|
|
|
@pytest.mark.mvp
|
2021-02-17 22:14:40 +00:00
|
|
|
def test_verify_stamp(user: UserClient, client: Client):
|
|
|
|
"""Test verify stamp of one export device information in a csv file."""
|
|
|
|
snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot)
|
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='devices/',
|
|
|
|
accept='text/csv',
|
|
|
|
query=[('filter', {'type': ['Computer']})])
|
2021-04-13 16:34:18 +00:00
|
|
|
|
2021-02-17 22:14:40 +00:00
|
|
|
response, _ = client.post(res=documents.DocumentDef.t,
|
|
|
|
item='stamps/',
|
|
|
|
content_type='multipart/form-data',
|
|
|
|
accept='text/html',
|
2021-04-13 16:34:18 +00:00
|
|
|
data={'docUpload': [(BytesIO(bytes(csv_str, 'utf-8')), 'example.csv')]},
|
2021-02-17 22:14:40 +00:00
|
|
|
status=200)
|
|
|
|
assert "alert alert-info" in response
|
|
|
|
assert not "alert alert-danger" in response
|
|
|
|
|
|
|
|
response, _ = client.post(res=documents.DocumentDef.t,
|
2021-02-18 10:37:37 +00:00
|
|
|
item='stamps/',
|
|
|
|
content_type='multipart/form-data',
|
|
|
|
accept='text/html',
|
|
|
|
data={'docUpload': [(BytesIO(b'abc'), 'example.csv')]},
|
|
|
|
status=200)
|
2021-02-17 22:14:40 +00:00
|
|
|
|
|
|
|
assert not "alert alert-info" in response
|
|
|
|
assert "alert alert-danger" in response
|
|
|
|
|
|
|
|
response, _ = client.get(res=documents.DocumentDef.t,
|
2021-02-18 10:37:37 +00:00
|
|
|
item='stamps/',
|
|
|
|
accept='text/html',
|
|
|
|
status=200)
|
2021-02-17 22:14:40 +00:00
|
|
|
|
|
|
|
assert not "alert alert-info" in response
|
|
|
|
assert not "alert alert-danger" in response
|
2021-02-18 10:37:37 +00:00
|
|
|
|
|
|
|
|
2021-04-13 16:34:18 +00:00
|
|
|
@pytest.mark.mvp
|
2021-02-18 10:37:37 +00:00
|
|
|
def test_verify_stamp_log_info(user: UserClient, client: Client):
|
|
|
|
"""Test verify stamp of one export lots-info in a csv file."""
|
2021-04-13 16:34:18 +00:00
|
|
|
|
2021-02-18 10:37:37 +00:00
|
|
|
l, _ = user.post({'name': 'Lot1', 'description': 'comments,lot1,testcomment-lot1,'}, res=Lot)
|
|
|
|
l, _ = user.post({'name': 'Lot2', 'description': 'comments,lot2,testcomment-lot2,'}, res=Lot)
|
|
|
|
|
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='lots/',
|
|
|
|
accept='text/csv')
|
|
|
|
|
|
|
|
response, _ = client.post(res=documents.DocumentDef.t,
|
|
|
|
item='stamps/',
|
|
|
|
content_type='multipart/form-data',
|
|
|
|
accept='text/html',
|
2021-04-13 16:34:18 +00:00
|
|
|
data={'docUpload': [(BytesIO(bytes(csv_str, 'utf-8')),
|
|
|
|
'example.csv')]},
|
2021-02-18 10:37:37 +00:00
|
|
|
status=200)
|
|
|
|
assert "alert alert-info" in response
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
|
|
|
def test_verify_stamp_devices_stock(user: UserClient, client: Client):
|
|
|
|
"""Test verify stamp of one export device information in a csv file."""
|
|
|
|
|
|
|
|
snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot)
|
|
|
|
|
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='stock/',
|
|
|
|
accept='text/csv',
|
|
|
|
query=[('filter', {'type': ['Computer']})])
|
|
|
|
|
|
|
|
response, _ = client.post(res=documents.DocumentDef.t,
|
|
|
|
item='stamps/',
|
|
|
|
content_type='multipart/form-data',
|
|
|
|
accept='text/html',
|
|
|
|
data={'docUpload': [(BytesIO(bytes(csv_str, 'utf-8')),
|
2021-04-13 16:34:18 +00:00
|
|
|
'example.csv')]},
|
2021-02-18 10:37:37 +00:00
|
|
|
status=200)
|
|
|
|
assert "alert alert-info" in response
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
|
|
|
def test_verify_stamp_csv_actions(user: UserClient, client: Client):
|
|
|
|
"""Test verify stamp of one export device information in a csv file with others users."""
|
2021-07-02 15:40:20 +00:00
|
|
|
acer = yaml2json('acer.happy.battery.snapshot')
|
|
|
|
snapshot, _ = user.post(json_encode(acer), res=Snapshot)
|
2021-02-18 10:37:37 +00:00
|
|
|
device_id = snapshot['device']['id']
|
|
|
|
post_request = {"transaction": "ccc", "name": "John", "endUsers": 1,
|
|
|
|
"devices": [device_id], "description": "aaa",
|
|
|
|
"finalUserCode": "abcdefjhi",
|
|
|
|
"startTime": "2020-11-01T02:00:00+00:00",
|
|
|
|
"endTime": "2020-12-01T02:00:00+00:00"
|
|
|
|
}
|
|
|
|
|
|
|
|
user.post(res=Allocate, data=post_request)
|
|
|
|
hdd = [c for c in acer['components'] if c['type'] == 'HardDrive'][0]
|
|
|
|
hdd_action = [a for a in hdd['actions'] if a['type'] == 'TestDataStorage'][0]
|
|
|
|
hdd_action['lifetime'] += 1000
|
|
|
|
acer.pop('elapsed')
|
|
|
|
acer['licence_version'] = '1.0.0'
|
|
|
|
snapshot, _ = client.post(acer, res=Live)
|
|
|
|
|
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='actions/',
|
|
|
|
accept='text/csv',
|
|
|
|
query=[('filter', {'type': ['Computer']})])
|
|
|
|
|
|
|
|
response, _ = client.post(res=documents.DocumentDef.t,
|
|
|
|
item='stamps/',
|
|
|
|
content_type='multipart/form-data',
|
|
|
|
accept='text/html',
|
2021-04-13 16:34:18 +00:00
|
|
|
data={'docUpload': [(BytesIO(bytes(csv_str, 'utf-8')),
|
|
|
|
'example.csv')]},
|
2021-02-18 10:37:37 +00:00
|
|
|
status=200)
|
|
|
|
assert "alert alert-info" in response
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
|
|
|
def test_verify_stamp_erasure_certificate(user: UserClient, client: Client):
|
|
|
|
"""Test verify stamp of one export certificate in PDF."""
|
|
|
|
s = file('erase-sectors.snapshot')
|
|
|
|
snapshot, response = user.post(s, res=Snapshot)
|
|
|
|
|
|
|
|
doc, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='erasures/',
|
2021-12-21 09:32:04 +00:00
|
|
|
query=[('filter', {'ids': [snapshot['device']['id']]})],
|
2021-02-18 10:37:37 +00:00
|
|
|
accept=ANY)
|
|
|
|
|
|
|
|
response, _ = client.post(res=documents.DocumentDef.t,
|
|
|
|
item='stamps/',
|
|
|
|
content_type='multipart/form-data',
|
|
|
|
accept='text/html',
|
2021-04-13 16:34:18 +00:00
|
|
|
data={'docUpload': [(BytesIO(bytes(doc, 'utf-8')),
|
|
|
|
'example.csv')]},
|
2021-02-18 10:37:37 +00:00
|
|
|
status=200)
|
|
|
|
assert "alert alert-danger" in response
|
|
|
|
|
|
|
|
doc, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
item='erasures/',
|
|
|
|
query=[
|
2021-12-21 09:32:04 +00:00
|
|
|
('filter', {'ids': [snapshot['device']['id']]}),
|
2021-02-18 10:37:37 +00:00
|
|
|
('format', 'PDF')
|
|
|
|
],
|
|
|
|
accept='application/pdf')
|
|
|
|
|
|
|
|
response, _ = client.post(res=documents.DocumentDef.t,
|
|
|
|
item='stamps/',
|
|
|
|
content_type='multipart/form-data',
|
|
|
|
accept='text/html',
|
2021-04-13 16:34:18 +00:00
|
|
|
data={'docUpload': [(BytesIO(doc),
|
|
|
|
'example.csv')]},
|
2021-02-18 10:37:37 +00:00
|
|
|
status=200)
|
|
|
|
assert "alert alert-info" in response
|
2021-03-04 09:51:20 +00:00
|
|
|
|
|
|
|
|
2021-02-19 11:53:42 +00:00
|
|
|
@pytest.mark.mvp
|
2021-02-22 20:17:07 +00:00
|
|
|
def test_get_document_internal_stats(user: UserClient, user2: UserClient):
|
2021-03-01 18:21:57 +00:00
|
|
|
"""Tests for get the internal stats."""
|
2021-02-19 11:53:42 +00:00
|
|
|
|
2021-02-22 20:17:07 +00:00
|
|
|
# csv_str, _ = user.get(res=documents.DocumentDef.t,
|
|
|
|
# item='internalstats/')
|
2021-02-19 11:53:42 +00:00
|
|
|
csv_str, _ = user.get(res=documents.DocumentDef.t,
|
2021-02-22 20:17:07 +00:00
|
|
|
item='internalstats/',
|
|
|
|
accept='text/csv',
|
|
|
|
query=[])
|
|
|
|
|
|
|
|
f = StringIO(csv_str)
|
|
|
|
obj_csv = csv.reader(f, f)
|
|
|
|
export_csv = list(obj_csv)
|
|
|
|
|
|
|
|
assert len(export_csv) == 1
|
|
|
|
|
|
|
|
csv_str, _ = user2.get(res=documents.DocumentDef.t,
|
|
|
|
item='internalstats/',
|
|
|
|
accept='text/csv',
|
|
|
|
query=[])
|
2021-02-19 11:53:42 +00:00
|
|
|
|
|
|
|
f = StringIO(csv_str)
|
|
|
|
obj_csv = csv.reader(f, f)
|
|
|
|
export_csv = list(obj_csv)
|
|
|
|
|
2021-02-22 20:17:07 +00:00
|
|
|
assert csv_str.strip() == '""'
|
2021-03-01 18:21:57 +00:00
|
|
|
|
2021-04-15 19:16:04 +00:00
|
|
|
|
2021-03-01 18:21:57 +00:00
|
|
|
@pytest.mark.mvp
|
2021-04-13 16:34:18 +00:00
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2021-03-01 18:21:57 +00:00
|
|
|
def test_get_wbconf(user: UserClient):
|
|
|
|
"""Tests for get env file for usb wb."""
|
|
|
|
|
2021-03-02 10:42:07 +00:00
|
|
|
env, _ = user.get(res=documents.DocumentDef.t, item='wbconf/usodyrate', accept=ANY)
|
2021-05-26 09:42:42 +00:00
|
|
|
assert 'WB_ERASE =' in env
|
2021-03-02 10:42:07 +00:00
|
|
|
|
|
|
|
env, _ = user.get(res=documents.DocumentDef.t, item='wbconf/usodywipe', accept=ANY)
|
2021-05-26 09:42:42 +00:00
|
|
|
assert 'WB_ERASE =' in env
|
2021-04-12 10:31:07 +00:00
|
|
|
# assert 'WB_ERASE = True' in env
|
2021-04-13 16:34:18 +00:00
|
|
|
|
|
|
|
session = Session.query.filter_by(user_id=user.user['id'],
|
|
|
|
type=SessionType.Internal).first()
|
2021-04-15 19:16:04 +00:00
|
|
|
token = session.token
|
|
|
|
token = auth.Auth.encode(session.token)
|
|
|
|
assert token in env
|
|
|
|
user.user['token'] = token
|
2021-04-14 11:21:46 +00:00
|
|
|
snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot)
|
2021-08-03 09:28:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
|
|
|
def test_trade_documents(user: UserClient):
|
2021-08-03 11:08:03 +00:00
|
|
|
"""Tests upload one document"""
|
2021-08-03 09:28:18 +00:00
|
|
|
|
2021-08-03 14:40:17 +00:00
|
|
|
lot, _ = user.post({'name': 'MyLot'}, res=Lot)
|
|
|
|
request_post = {
|
|
|
|
'filename': 'test.pdf',
|
|
|
|
'hash': 'bbbbbbbb',
|
|
|
|
'url': 'http://www.ereuse.org/',
|
|
|
|
'lot': lot['id']
|
|
|
|
}
|
|
|
|
doc, _ = user.post(res=TradeDocument, data=request_post)
|
|
|
|
assert doc['filename'] == request_post['filename']
|
|
|
|
assert doc['url'] == request_post['url']
|
|
|
|
assert doc['hash'] == request_post['hash']
|
|
|
|
assert doc['lot']['name'] == lot['name']
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
|
|
|
def test_trade_documents_with_weight(user: UserClient):
|
|
|
|
"""Tests upload one document"""
|
|
|
|
|
|
|
|
lot, _ = user.post({'name': 'MyLot'}, res=Lot)
|
2021-08-10 10:45:03 +00:00
|
|
|
# long url
|
|
|
|
url = 'http://www.ereuse.org/apapaapaapaapaapaapaapaapaapaapapaapaapaapaapaapaapaapaapaapapaapaapaapaapaapaapaapaapaapaaaa',
|
2021-08-03 14:40:17 +00:00
|
|
|
request_post = {
|
|
|
|
'filename': 'test.pdf',
|
|
|
|
'hash': 'bbbbbbbb',
|
2021-08-10 10:45:03 +00:00
|
|
|
'url': url,
|
2021-08-03 14:40:17 +00:00
|
|
|
'weight': 15,
|
|
|
|
'lot': lot['id']
|
|
|
|
}
|
|
|
|
doc, _ = user.post(res=TradeDocument, data=request_post)
|
|
|
|
assert doc['weight'] == request_post['weight']
|