diff --git a/tests/files/basic-stock.csv b/tests/files/basic-stock.csv new file mode 100644 index 00000000..f8cd616d --- /dev/null +++ b/tests/files/basic-stock.csv @@ -0,0 +1,2 @@ +Type ,Chassis ,Serial Number,Model,Manufacturer,Registered in ,Physical state,Trading state,Price,Processor,RAM (MB),Data Storage Size (MB),Rate,Range ,Processor Rate,Processor Range,RAM Rate,RAM Range,Data Storage Rate,Data Storage Range +Desktop,Microtower,d1s ,d1ml ,d1mr ,Tue Jul 2 10:35:10 2019, , , ,p1ml ,0 ,0 ,1.0 ,Very low,1.0 ,Very low ,1.0 ,Very low ,1.0 ,Very low \ No newline at end of file diff --git a/tests/test_documents.py b/tests/test_documents.py index 0b40bf23..37ca9c36 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -223,3 +223,31 @@ def test_export_multiple_different_devices(user: UserClient): del row[8] assert fixture_csv == export_csv + + +@pytest.mark.mvp +def test_report_devices_stock_control(user: UserClient): + """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='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) + + 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'