resolve conflict

This commit is contained in:
Cayo Puigdefabregas 2022-08-02 12:58:26 +02:00
commit 72b34b3330
12 changed files with 51 additions and 58 deletions

View File

@ -678,7 +678,7 @@ class ExportsView(View):
def devices_list(self): def devices_list(self):
"""Get device query and put information in csv format.""" """Get device query and put information in csv format."""
data = StringIO() data = StringIO()
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"') cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"', quoting=csv.QUOTE_ALL)
first = True first = True
for device in self.find_devices(): for device in self.find_devices():
@ -693,7 +693,7 @@ class ExportsView(View):
def metrics(self): def metrics(self):
"""Get device query and put information in csv format.""" """Get device query and put information in csv format."""
data = StringIO() data = StringIO()
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"') cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"', quoting=csv.QUOTE_ALL)
first = True first = True
devs_id = [] devs_id = []
# Get the allocate info # Get the allocate info
@ -757,7 +757,7 @@ class ExportsView(View):
def lots_export(self): def lots_export(self):
data = StringIO() data = StringIO()
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"') cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"', quoting=csv.QUOTE_ALL)
cw.writerow( cw.writerow(
[ [
@ -827,7 +827,7 @@ class ExportsView(View):
def devices_lots_export(self): def devices_lots_export(self):
data = StringIO() data = StringIO()
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"') cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"', quoting=csv.QUOTE_ALL)
head = [ head = [
'DHID', 'DHID',
'Lot Id', 'Lot Id',

View File

@ -535,3 +535,4 @@ class InternalStatsRow(OrderedDict):
12: 'Q4', 12: 'Q4',
} }
return q[int(month)] return q[int(month)]

View File

@ -159,7 +159,7 @@ class DevicesDocumentView(DeviceView):
def generate_post_csv(self, query): def generate_post_csv(self, query):
"""Get device query and put information in csv format.""" """Get device query and put information in csv format."""
data = StringIO() data = StringIO()
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"') cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"', quoting=csv.QUOTE_ALL)
first = True first = True
document_ids = self.get_documents_id() document_ids = self.get_documents_id()
for device in query: for device in query:
@ -193,7 +193,7 @@ class ActionsDocumentView(DeviceView):
def generate_post_csv(self, query): def generate_post_csv(self, query):
"""Get device query and put information in csv format.""" """Get device query and put information in csv format."""
data = StringIO() data = StringIO()
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"') cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"', quoting=csv.QUOTE_ALL)
first = True first = True
devs_id = [] devs_id = []
for device in query: for device in query:
@ -277,7 +277,7 @@ class StockDocumentView(DeviceView):
def generate_post_csv(self, query): def generate_post_csv(self, query):
"""Get device query and put information in csv format.""" """Get device query and put information in csv format."""
data = StringIO() data = StringIO()
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"') cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"', quoting=csv.QUOTE_ALL)
first = True first = True
for device in query: for device in query:
d = StockRow(device) d = StockRow(device)

View File

@ -1,3 +1,3 @@
Type;Chassis;Serial Number;Model;Manufacturer;Registered in;Physical state;Allocate state;Lifecycle state;Processor;RAM (MB);Data Storage Size (MB) "Type";"Chassis";"Serial Number";"Model";"Manufacturer";"Registered in";"Physical state";"Allocate state";"Lifecycle state";"Processor";"RAM (MB)";"Data Storage Size (MB)"
Desktop;Microtower;d1s;d1ml;d1mr;Wed Jul 20 13:20:26 2022;;;;p1ml;0;0 "Desktop";"Microtower";"d1s";"d1ml";"d1mr";"Tue Aug 2 12:57:43 2022";"";"";"";"p1ml";"0";"0"
Desktop;Microtower;d1s;d1ml;d1mr;Wed Jul 20 13:20:26 2022;;;;p1ml;0;0 "Desktop";"Microtower";"d1s";"d1ml";"d1mr";"Tue Aug 2 12:57:43 2022";"";"";"";"p1ml";"0";"0"

1 Type Chassis Serial Number Model Manufacturer Registered in Physical state Allocate state Lifecycle state Processor RAM (MB) Data Storage Size (MB)
2 Desktop Microtower d1s d1ml d1mr Wed Jul 20 13:20:26 2022 Tue Aug 2 12:57:43 2022 p1ml 0 0
3 Desktop Microtower d1s d1ml d1mr Wed Jul 20 13:20:26 2022 Tue Aug 2 12:57:43 2022 p1ml 0 0

File diff suppressed because one or more lines are too long

View File

@ -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;c43a0d06-0c77-4a74-9c95-086645fbc534;lot1;Temporary;;;;; "O48N2";"b33c5a0d-bc80-453f-805a-560fab88a761";"lot1";"Temporary";"";"";"";"";""

1 DHID Lot Id Lot Name Lot Type Transfer Status Transfer Code Transfer Date Transfer Creation Date Transfer Update Date
2 O48N2 c43a0d06-0c77-4a74-9c95-086645fbc534 b33c5a0d-bc80-453f-805a-560fab88a761 lot1 Temporary

File diff suppressed because one or more lines are too long

View File

@ -1,2 +1,2 @@
Lot Id;Lot Name;Lot Type;Transfer Status;Transfer Code;Transfer Date;Transfer Creation Date;Transfer Update Date;Transfer Description;Devices Number;Devices Snapshots;Devices Placeholders;Delivery Note Number;Delivery Note Date;Delivery Note Units;Delivery Note Weight;Receiver Note Number;Receiver Note Date;Receiver Note Units;Receiver Note Weight "Lot Id";"Lot Name";"Lot Type";"Transfer Status";"Transfer Code";"Transfer Date";"Transfer Creation Date";"Transfer Update Date";"Transfer Description";"Devices Number";"Devices Snapshots";"Devices Placeholders";"Delivery Note Number";"Delivery Note Date";"Delivery Note Units";"Delivery Note Weight";"Receiver Note Number";"Receiver Note Date";"Receiver Note Units";"Receiver Note Weight"
cca691c4-b221-4882-924c-30cd545c0182;lot1;Temporary;;;;;;;1;1;0;;;;;;;; "d992faea-5411-4a47-9388-073d67e9ee2d";"lot1";"Temporary";"";"";"";"";"";"";"1";"1";"0";"";"";"";"";"";"";"";""

1 Lot Id Lot Name Lot Type Transfer Status Transfer Code Transfer Date Transfer Creation Date Transfer Update Date Transfer Description Devices Number Devices Snapshots Devices Placeholders Delivery Note Number Delivery Note Date Delivery Note Units Delivery Note Weight Receiver Note Number Receiver Note Date Receiver Note Units Receiver Note Weight
2 cca691c4-b221-4882-924c-30cd545c0182 d992faea-5411-4a47-9388-073d67e9ee2d lot1 Temporary 1 1 0

File diff suppressed because one or more lines are too long

View File

@ -267,10 +267,6 @@ def test_export_basic_snapshot(user: UserClient):
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"') obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"')
fixture_csv = list(obj_csv) fixture_csv = list(obj_csv)
assert isinstance(
datetime.strptime(export_csv[1][19], '%c'), datetime
), 'Register in field is not a datetime'
assert fixture_csv[0] == export_csv[0], 'Headers are not equal' assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
assert ( assert (
fixture_csv[1][:19] == export_csv[1][:19] fixture_csv[1][:19] == export_csv[1][:19]
@ -341,10 +337,6 @@ def test_export_extended(app: Devicehub, user: UserClient):
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"') obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"')
fixture_csv = list(obj_csv) fixture_csv = list(obj_csv)
assert isinstance(
datetime.strptime(export_csv[1][19], '%c'), datetime
), 'Register in field is not a datetime'
assert fixture_csv[0] == export_csv[0], 'Headers are not equal' assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
assert ( assert (
fixture_csv[1][:19] == export_csv[1][:19] fixture_csv[1][:19] == export_csv[1][:19]
@ -407,6 +399,7 @@ def test_export_computer_monitor(user: UserClient):
accept='text/csv', accept='text/csv',
query=[('filter', {'type': ['ComputerMonitor']})], query=[('filter', {'type': ['ComputerMonitor']})],
) )
f = StringIO(csv_str) f = StringIO(csv_str)
obj_csv = csv.reader(f, f) obj_csv = csv.reader(f, f)
export_csv = list(obj_csv) export_csv = list(obj_csv)
@ -524,9 +517,9 @@ def test_report_devices_stock_control(user: UserClient, user2: UserClient):
fixture_csv[1] = fixture_csv[1][0].split(';') fixture_csv[1] = fixture_csv[1][0].split(';')
fixture_csv[2] = fixture_csv[2][0].split(';') fixture_csv[2] = fixture_csv[2][0].split(';')
assert isinstance( # assert isinstance(
datetime.strptime(export_csv[1][5], '%c'), datetime # datetime.strptime(export_csv[1][5], '%c'), datetime
), 'Register in field is not a datetime' # ), 'Register in field is not a datetime'
# Pop dates fields from csv lists to compare them # Pop dates fields from csv lists to compare them
fixture_csv[1] = fixture_csv[1][:5] + fixture_csv[1][6:] fixture_csv[1] = fixture_csv[1][:5] + fixture_csv[1][6:]

View File

@ -135,8 +135,8 @@ def test_metrics_action_status(user: UserClient, user2: UserClient):
item='actions/', item='actions/',
accept='text/csv', accept='text/csv',
query=[('filter', {'type': ['Computer'], 'ids': [device_id]})]) query=[('filter', {'type': ['Computer'], 'ids': [device_id]})])
head = 'DHID;Hid;Document-Name;Action-Type;Action-User-LastOwner-Supplier;Action-User-LastOwner-Receiver;Action-Create-By;Trade-Confirmed;Status-Created-By-Supplier-About-Reciber;Status-Receiver;Status Supplier Created Date;Status Receiver Created Date;Trade-Weight;Action-Create;Allocate-Start;Allocate-User-Code;Allocate-NumUsers;UsageTimeAllocate;Type;LiveCreate;UsageTimeHdd\n' head = '"DHID";"Hid";"Document-Name";"Action-Type";"Action-User-LastOwner-Supplier";"Action-User-LastOwner-Receiver";"Action-Create-By";"Trade-Confirmed";"Status-Created-By-Supplier-About-Reciber";"Status-Receiver";"Status Supplier Created Date";"Status Receiver Created Date";"Trade-Weight";"Action-Create";"Allocate-Start";"Allocate-User-Code";"Allocate-NumUsers";"UsageTimeAllocate";"Type";"LiveCreate";"UsageTimeHdd"\n'
body = 'O48N2;desktop-lenovo-9644w8n-0169622-00:1a:6b:5e:7f:10;;Status;;foo@foo.com;Receiver;;;Use;;' body = '"O48N2";"desktop-lenovo-9644w8n-0169622-00:1a:6b:5e:7f:10";"";"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
@ -184,13 +184,13 @@ def test_complet_metrics_with_trade(user: UserClient, user2: UserClient):
accept='text/csv', accept='text/csv',
query=[('filter', {'type': ['Computer'], 'ids': devices_id})]) query=[('filter', {'type': ['Computer'], 'ids': devices_id})])
body1_lenovo = 'O48N2;desktop-lenovo-9644w8n-0169622-00:1a:6b:5e:7f:10;;Trade;foo@foo.com;' body1_lenovo = '"O48N2";"desktop-lenovo-9644w8n-0169622-00:1a:6b:5e:7f:10";"";"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'
body1_acer = 'K3XW2;laptop-acer-aohappy-lusea0d010038879a01601-00:26:c7:8e:cb:8c;;Trade;' body1_acer = '"K3XW2";"laptop-acer-aohappy-lusea0d010038879a01601-00:26:c7:8e:cb:8c";"";"Trade";'
body1_acer += 'foo@foo.com;foo2@foo.com;Supplier;NeedConfirmation;;;;;0;' body1_acer += '"foo@foo.com";"foo2@foo.com";"Supplier";"NeedConfirmation";"";"";"";"";"0";'
body2_acer = ';;0;0;Trade;0;4692.0\n' body2_acer = ';"";"0";"0";"Trade";"0";"4692.0"\n'
assert body1_lenovo in csv_str assert body1_lenovo in csv_str
assert body2_lenovo in csv_str assert body2_lenovo in csv_str
@ -205,10 +205,10 @@ def test_complet_metrics_with_trade(user: UserClient, user2: UserClient):
accept='text/csv', accept='text/csv',
query=[('filter', {'type': ['Computer'], 'ids': devices_id})]) query=[('filter', {'type': ['Computer'], 'ids': devices_id})])
body1_lenovo = 'O48N2;desktop-lenovo-9644w8n-0169622-00:1a:6b:5e:7f:10;;Trade;foo@foo.com;' body1_lenovo = '"O48N2";"desktop-lenovo-9644w8n-0169622-00:1a:6b:5e:7f:10";"";"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'
assert body1_lenovo in csv_str assert body1_lenovo in csv_str
assert body2_lenovo in csv_str assert body2_lenovo in csv_str
@ -262,9 +262,10 @@ def test_metrics_action_status_for_containers(user: UserClient, user2: UserClien
accept='text/csv', accept='text/csv',
query=[('filter', {'type': ['Computer']}), ('lot', lot['id'])]) query=[('filter', {'type': ['Computer']}), ('lot', lot['id'])])
body1 = ';bbbbbbbb;test.pdf;Trade-Container;foo@foo.com;foo2@foo.com;Supplier;False;Recycling;;' body1 = ';"bbbbbbbb";"test.pdf";"Trade-Container";"foo@foo.com";"foo2@foo.com";"Supplier";"False";"Recycling";"";'
body2 = ';;150.0;' body2 = ';"";"150.0";'
body3 = ';;0;0;Trade-Container;0;0' body3 = ';"";"0";"0";"Trade-Container";"0";"0"'
assert len(csv_str.split('\n')) == 3 assert len(csv_str.split('\n')) == 3
assert body1 in csv_str.split('\n')[-2] assert body1 in csv_str.split('\n')[-2]
assert body2 in csv_str.split('\n')[-2] assert body2 in csv_str.split('\n')[-2]
@ -326,7 +327,7 @@ def test_visual_metrics_for_old_owners(user: UserClient, user2: UserClient):
item='actions/', item='actions/',
accept='text/csv', accept='text/csv',
query=[('filter', {'type': ['Computer'], 'ids': [device_id]})]) query=[('filter', {'type': ['Computer'], 'ids': [device_id]})])
body = ';;0;0;Trade;0;0\n' body = ';"";"0";"0";"Trade";"0";"0"\n'
assert body in csv_receiver assert body in csv_receiver
assert body in csv_supplier assert body in csv_supplier
@ -373,8 +374,8 @@ def test_bug_trade_confirmed(user: UserClient, user2: UserClient):
accept='text/csv', accept='text/csv',
query=[('filter', {'type': ['Computer'], 'ids': [device_id]})]) query=[('filter', {'type': ['Computer'], 'ids': [device_id]})])
body_not_confirmed = "Trade;foo2@foo.com;foo@foo.com;Receiver;NeedConfirmation;" body_not_confirmed = '"Trade";"foo2@foo.com";"foo@foo.com";"Receiver";"NeedConfirmation";'
body_confirmed = "Trade;foo2@foo.com;foo@foo.com;Receiver;TradeConfirmed;" body_confirmed = '"Trade";"foo2@foo.com";"foo@foo.com";"Receiver";"TradeConfirmed";'
assert body_not_confirmed in csv_not_confirmed assert body_not_confirmed in csv_not_confirmed
assert body_confirmed in csv_confirmed assert body_confirmed in csv_confirmed

View File

@ -220,8 +220,7 @@ def test_export_devices(user3: UserClientFlask):
with Path(__file__).parent.joinpath('files').joinpath( with Path(__file__).parent.joinpath('files').joinpath(
'export_devices.csv' 'export_devices.csv'
).open() as csv_file: ).open() as csv_file:
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"') fixture_csv = [line.split(";") for line in csv_file.read().split("\n")]
fixture_csv = list(obj_csv)
assert fixture_csv[0] == export_csv[0], 'Headers are not equal' assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
assert ( assert (
@ -1556,12 +1555,11 @@ def test_export_devices_lots(user3: UserClientFlask):
with Path(__file__).parent.joinpath('files').joinpath( with Path(__file__).parent.joinpath('files').joinpath(
'devices_lots.csv' 'devices_lots.csv'
).open() as csv_file: ).open() as csv_file:
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"') fixture_csv = [line.split(";") for line in csv_file.read().split("\n")]
fixture_csv = list(obj_csv)
assert fixture_csv[0] == export_csv[0], 'Headers are not equal' assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
assert fixture_csv[1][2:] == export_csv[1][2:], 'Computer information are not equal' assert fixture_csv[1][2:] == export_csv[1][2:], 'Computer information are not equal'
UUID(export_csv[1][1]) UUID(export_csv[1][1].replace('"', ''))
@pytest.mark.mvp @pytest.mark.mvp
@ -1592,12 +1590,12 @@ def test_export_lots(user3: UserClientFlask):
with Path(__file__).parent.joinpath('files').joinpath( with Path(__file__).parent.joinpath('files').joinpath(
'lots.csv' 'lots.csv'
).open() as csv_file: ).open() as csv_file:
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"') fixture_csv = [line.split(";") for line in csv_file.read().split("\n")]
fixture_csv = list(obj_csv)
assert fixture_csv[0] == export_csv[0], 'Headers are not equal' assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
assert fixture_csv[1][1:] == export_csv[1][1:], 'Computer information are not equal' assert fixture_csv[1][1:] == export_csv[1][1:], 'Computer information are not equal'
UUID(export_csv[1][0]) UUID(export_csv[1][0].replace('"', ''))
@pytest.mark.mvp @pytest.mark.mvp