Merge branch 'testing' into feature/4463-solar-panel
This commit is contained in:
commit
9209e3cfaa
|
@ -0,0 +1,24 @@
|
||||||
|
import click
|
||||||
|
|
||||||
|
from ereuse_devicehub.db import db
|
||||||
|
from ereuse_devicehub.resources.agent.models import Person
|
||||||
|
from ereuse_devicehub.resources.user.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class AddUser:
|
||||||
|
def __init__(self, app) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.app = app
|
||||||
|
self.schema = app.config.get('DB_SCHEMA')
|
||||||
|
self.app.cli.command('adduser', short_help='add a user.')(self.run)
|
||||||
|
|
||||||
|
@click.argument('email')
|
||||||
|
@click.argument('password')
|
||||||
|
def run(self, email, password):
|
||||||
|
name = email.split('@')[0]
|
||||||
|
|
||||||
|
user = User(email=email, password=password)
|
||||||
|
user.individuals.add(Person(name=name))
|
||||||
|
db.session.add(user)
|
||||||
|
|
||||||
|
db.session.commit()
|
|
@ -0,0 +1,40 @@
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
from boltons.urlutils import URL
|
||||||
|
|
||||||
|
from ereuse_devicehub.db import db
|
||||||
|
from ereuse_devicehub.resources.agent.models import Person
|
||||||
|
from ereuse_devicehub.resources.inventory.model import Inventory
|
||||||
|
from ereuse_devicehub.resources.user.models import User
|
||||||
|
|
||||||
|
|
||||||
|
class InitDatas:
|
||||||
|
def __init__(self, app) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.app = app
|
||||||
|
self.schema = app.config.get('DB_SCHEMA')
|
||||||
|
self.app.cli.command(
|
||||||
|
'initdata', short_help='Save a minimum structure of datas.'
|
||||||
|
)(self.run)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
inv = Inventory(
|
||||||
|
id=self.schema,
|
||||||
|
name="usody",
|
||||||
|
tag_provider=URL('http://localhost:8081'),
|
||||||
|
tag_token=uuid4(),
|
||||||
|
org_id=uuid4(),
|
||||||
|
)
|
||||||
|
|
||||||
|
db.session.add(inv)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
email = 'user@dhub.com'
|
||||||
|
password = '1234'
|
||||||
|
name = 'user'
|
||||||
|
|
||||||
|
user = User(email=email, password=password)
|
||||||
|
user.individuals.add(Person(name=name))
|
||||||
|
db.session.add(user)
|
||||||
|
|
||||||
|
db.session.commit()
|
|
@ -5,20 +5,22 @@ from typing import Type
|
||||||
import boltons.urlutils
|
import boltons.urlutils
|
||||||
import click
|
import click
|
||||||
import click_spinner
|
import click_spinner
|
||||||
import ereuse_devicehub.ereuse_utils.cli
|
|
||||||
from ereuse_devicehub.ereuse_utils.session import DevicehubClient
|
|
||||||
from flask import _app_ctx_stack, g
|
from flask import _app_ctx_stack, g
|
||||||
from flask_login import LoginManager, current_user
|
from flask_login import LoginManager, current_user
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
|
import ereuse_devicehub.ereuse_utils.cli
|
||||||
from ereuse_devicehub.auth import Auth
|
from ereuse_devicehub.auth import Auth
|
||||||
from ereuse_devicehub.client import Client, UserClient
|
from ereuse_devicehub.client import Client, UserClient
|
||||||
|
from ereuse_devicehub.commands.adduser import AddUser
|
||||||
|
from ereuse_devicehub.commands.initdatas import InitDatas
|
||||||
|
|
||||||
# from ereuse_devicehub.commands.reports import Report
|
# from ereuse_devicehub.commands.reports import Report
|
||||||
from ereuse_devicehub.commands.users import GetToken
|
from ereuse_devicehub.commands.users import GetToken
|
||||||
from ereuse_devicehub.config import DevicehubConfig
|
from ereuse_devicehub.config import DevicehubConfig
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.dummy.dummy import Dummy
|
from ereuse_devicehub.dummy.dummy import Dummy
|
||||||
|
from ereuse_devicehub.ereuse_utils.session import DevicehubClient
|
||||||
from ereuse_devicehub.resources.device.search import DeviceSearch
|
from ereuse_devicehub.resources.device.search import DeviceSearch
|
||||||
from ereuse_devicehub.resources.inventory import Inventory, InventoryDef
|
from ereuse_devicehub.resources.inventory import Inventory, InventoryDef
|
||||||
from ereuse_devicehub.resources.user.models import User
|
from ereuse_devicehub.resources.user.models import User
|
||||||
|
@ -73,6 +75,8 @@ class Devicehub(Teal):
|
||||||
self.dummy = Dummy(self)
|
self.dummy = Dummy(self)
|
||||||
# self.report = Report(self)
|
# self.report = Report(self)
|
||||||
self.get_token = GetToken(self)
|
self.get_token = GetToken(self)
|
||||||
|
self.initdata = InitDatas(self)
|
||||||
|
self.adduser = AddUser(self)
|
||||||
|
|
||||||
@self.cli.group(
|
@self.cli.group(
|
||||||
short_help='Inventory management.',
|
short_help='Inventory management.',
|
||||||
|
|
|
@ -8,12 +8,11 @@ Create Date: 2020-05-07 10:04:40.269511
|
||||||
import citext
|
import citext
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
import sqlalchemy_utils
|
import sqlalchemy_utils
|
||||||
from ereuse_devicehub import teal
|
from alembic import context, op
|
||||||
from alembic import context
|
|
||||||
from alembic import op
|
|
||||||
from sqlalchemy.dialects import postgresql
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
from ereuse_devicehub.resources.enums import TransferState, Severity
|
from ereuse_devicehub import teal
|
||||||
|
from ereuse_devicehub.resources.enums import Severity, TransferState
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = 'fbb7e2a0cde0'
|
revision = 'fbb7e2a0cde0'
|
||||||
|
@ -348,6 +347,7 @@ def upgrade():
|
||||||
postgresql_using='hash',
|
postgresql_using='hash',
|
||||||
schema=f'{get_inv()}',
|
schema=f'{get_inv()}',
|
||||||
)
|
)
|
||||||
|
op.execute(f"CREATE SEQUENCE {get_inv()}.device_seq START 1;")
|
||||||
op.create_table(
|
op.create_table(
|
||||||
'agent',
|
'agent',
|
||||||
sa.Column(
|
sa.Column(
|
||||||
|
|
|
@ -76,8 +76,8 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def create_code(context):
|
def create_code(context):
|
||||||
_id = Device.query.order_by(Device.id.desc()).first() or 3
|
_id = Device.query.order_by(Device.id.desc()).first() or 1
|
||||||
if not _id == 3:
|
if not _id == 1:
|
||||||
_id = _id.id + 1
|
_id = _id.id + 1
|
||||||
return hashcode.encode(_id)
|
return hashcode.encode(_id)
|
||||||
|
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
"DHID";"Lot Id";"Lot Name";"Lot Type";"Transfer Status";"Transfer Code";"Transfer Date";"Transfer Creation Date";"Transfer Update Date"
|
"DHID";"Lot Id";"Lot Name";"Lot Type";"Transfer Status";"Transfer Code";"Transfer Date";"Transfer Creation Date";"Transfer Update Date"
|
||||||
"O48N2";"b33c5a0d-bc80-453f-805a-560fab88a761";"lot1";"Temporary";"";"";"";"";""
|
"93652";"b33c5a0d-bc80-453f-805a-560fab88a761";"lot1";"Temporary";"";"";"";"";""
|
||||||
|
|
|
|
@ -160,7 +160,7 @@ def test_metrics_action_status(user: UserClient, user2: UserClient):
|
||||||
head += '"Status Supplier – Created Date";"Status Receiver – Created Date";"Trade-Weight";'
|
head += '"Status Supplier – Created Date";"Status Receiver – Created Date";"Trade-Weight";'
|
||||||
head += '"Action-Create";"Allocate-Start";"Allocate-User-Code";"Allocate-NumUsers";'
|
head += '"Action-Create";"Allocate-Start";"Allocate-User-Code";"Allocate-NumUsers";'
|
||||||
head += '"UsageTimeAllocate";"Type";"LiveCreate";"UsageTimeHdd"\n'
|
head += '"UsageTimeAllocate";"Type";"LiveCreate";"UsageTimeHdd"\n'
|
||||||
body = '"O48N2";"adebcc5506213fac43cd8473a9c81bcf0cadaed9cb98b2eae651e377a3533c5a";'
|
body = '"93652";"adebcc5506213fac43cd8473a9c81bcf0cadaed9cb98b2eae651e377a3533c5a";'
|
||||||
body += '"";"Status";"";"foo@foo.com";"Receiver";"";"";"Use";"";"'
|
body += '"";"Status";"";"foo@foo.com";"Receiver";"";"";"Use";"";"'
|
||||||
assert head in csv_str
|
assert head in csv_str
|
||||||
assert body in csv_str
|
assert body in csv_str
|
||||||
|
@ -207,7 +207,7 @@ def test_complet_metrics_with_trade(user: UserClient, user2: UserClient):
|
||||||
query=[('filter', {'type': ['Computer'], 'ids': devices_id})],
|
query=[('filter', {'type': ['Computer'], 'ids': devices_id})],
|
||||||
)
|
)
|
||||||
|
|
||||||
body1_lenovo = '"O48N2";"adebcc5506213fac43cd8473a9c81bcf0cadaed9cb98b2eae651e377a3533c5a";"";"Trade";"foo@foo.com";'
|
body1_lenovo = '"93652";"adebcc5506213fac43cd8473a9c81bcf0cadaed9cb98b2eae651e377a3533c5a";"";"Trade";"foo@foo.com";'
|
||||||
body1_lenovo += '"foo2@foo.com";"Supplier";"NeedConfirmation";"Use";"";'
|
body1_lenovo += '"foo2@foo.com";"Supplier";"NeedConfirmation";"Use";"";'
|
||||||
body2_lenovo = ';"";"0";"0";"Trade";"0";"0"\n'
|
body2_lenovo = ';"";"0";"0";"Trade";"0";"0"\n'
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ def test_complet_metrics_with_trade(user: UserClient, user2: UserClient):
|
||||||
query=[('filter', {'type': ['Computer'], 'ids': devices_id})],
|
query=[('filter', {'type': ['Computer'], 'ids': devices_id})],
|
||||||
)
|
)
|
||||||
|
|
||||||
body1_lenovo = '"O48N2";"adebcc5506213fac43cd8473a9c81bcf0cadaed9cb98b2eae651e377a3533c5a";"";"Trade";"foo@foo.com";'
|
body1_lenovo = '"93652";"adebcc5506213fac43cd8473a9c81bcf0cadaed9cb98b2eae651e377a3533c5a";"";"Trade";"foo@foo.com";'
|
||||||
body1_lenovo += '"foo2@foo.com";"Supplier";"NeedConfirmation";"Use";"Use";'
|
body1_lenovo += '"foo2@foo.com";"Supplier";"NeedConfirmation";"Use";"Use";'
|
||||||
body2_lenovo = ';"";"0";"0";"Trade";"0";"0"\n'
|
body2_lenovo = ';"";"0";"0";"Trade";"0";"0"\n'
|
||||||
body2_acer = ';"";"0";"0";"Trade";"0";"4692.0"\n'
|
body2_acer = ';"";"0";"0";"Trade";"0";"4692.0"\n'
|
||||||
|
|
|
@ -531,7 +531,7 @@ def test_add_monitor(user3: UserClientFlask):
|
||||||
assert dev.placeholder.id_device_supplier == "b2"
|
assert dev.placeholder.id_device_supplier == "b2"
|
||||||
assert dev.hid == 'monitor-samsung-lc27t55-aaaab'
|
assert dev.hid == 'monitor-samsung-lc27t55-aaaab'
|
||||||
assert phid == '1'
|
assert phid == '1'
|
||||||
assert dhid == 'O48N2'
|
assert dhid == '93652'
|
||||||
|
|
||||||
txt = f'Device "{typ}" placeholder with PHID {phid} and DHID {dhid} '
|
txt = f'Device "{typ}" placeholder with PHID {phid} and DHID {dhid} '
|
||||||
txt += 'created successfully'
|
txt += 'created successfully'
|
||||||
|
@ -571,7 +571,7 @@ def test_update_monitor(user3: UserClientFlask):
|
||||||
assert dev.placeholder.id_device_supplier == "b2"
|
assert dev.placeholder.id_device_supplier == "b2"
|
||||||
assert dev.hid == 'monitor-samsung-lc27t55-aaaab'
|
assert dev.hid == 'monitor-samsung-lc27t55-aaaab'
|
||||||
assert phid == '1'
|
assert phid == '1'
|
||||||
assert dhid == 'O48N2'
|
assert dhid == '93652'
|
||||||
assert dev.model == 'lc27t55'
|
assert dev.model == 'lc27t55'
|
||||||
assert dev.depth == 0.1
|
assert dev.depth == 0.1
|
||||||
assert dev.placeholder.pallet == "l34"
|
assert dev.placeholder.pallet == "l34"
|
||||||
|
@ -640,7 +640,7 @@ def test_add_2_monitor(user3: UserClientFlask):
|
||||||
assert dev.placeholder.id_device_supplier == "b1"
|
assert dev.placeholder.id_device_supplier == "b1"
|
||||||
assert dev.hid == 'monitor-samsung-lc27t55-aaaab'
|
assert dev.hid == 'monitor-samsung-lc27t55-aaaab'
|
||||||
assert phid == '1'
|
assert phid == '1'
|
||||||
assert dhid == 'O48N2'
|
assert dhid == '93652'
|
||||||
assert dev.model == 'lc27t55'
|
assert dev.model == 'lc27t55'
|
||||||
assert dev.placeholder.pallet == "l34"
|
assert dev.placeholder.pallet == "l34"
|
||||||
|
|
||||||
|
@ -717,7 +717,7 @@ def test_add_laptop(user3: UserClientFlask):
|
||||||
dev.chid == '274f05421e4d394c5b3cd10266fed6f0500029b104b5db3521689bda589e3150'
|
dev.chid == '274f05421e4d394c5b3cd10266fed6f0500029b104b5db3521689bda589e3150'
|
||||||
)
|
)
|
||||||
assert phid == '1'
|
assert phid == '1'
|
||||||
assert dhid == 'O48N2'
|
assert dhid == '93652'
|
||||||
|
|
||||||
txt = f'Device "{typ}" placeholder with PHID {phid} and DHID {dhid} '
|
txt = f'Device "{typ}" placeholder with PHID {phid} and DHID {dhid} '
|
||||||
txt += 'created successfully'
|
txt += 'created successfully'
|
||||||
|
@ -1891,7 +1891,7 @@ def test_edit_laptop(user3: UserClientFlask):
|
||||||
assert dev.serial_number == 'aaaab'
|
assert dev.serial_number == 'aaaab'
|
||||||
assert dev.model == 'lc27t55'
|
assert dev.model == 'lc27t55'
|
||||||
assert phid == '1'
|
assert phid == '1'
|
||||||
assert dhid == 'O48N2'
|
assert dhid == '93652'
|
||||||
|
|
||||||
txt = f'Device "{typ}" placeholder with PHID {phid} and DHID {dhid} '
|
txt = f'Device "{typ}" placeholder with PHID {phid} and DHID {dhid} '
|
||||||
txt += 'created successfully'
|
txt += 'created successfully'
|
||||||
|
|
Reference in New Issue