From 0ba71956cd0ac0af9f3773311f34c7407337dbcf Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 4 Mar 2022 00:02:30 +1100 Subject: [PATCH] Add unit tests --- InvenTree/part/templates/part/detail.html | 5 --- InvenTree/stock/test_api.py | 53 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 9007d91839..462389c476 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -28,11 +28,6 @@
- {% if part.is_template %} -
- {% blocktrans with full_name=part.full_name%}Showing stock for all variants of {{full_name}}{% endblocktrans %} -
- {% endif %} {% include "stock_table.html" %}
diff --git a/InvenTree/stock/test_api.py b/InvenTree/stock/test_api.py index a9dbe9e723..81973aed31 100644 --- a/InvenTree/stock/test_api.py +++ b/InvenTree/stock/test_api.py @@ -6,9 +6,12 @@ Unit testing for the Stock API from __future__ import unicode_literals import os +import io +import tablib from datetime import datetime, timedelta +import django.http from django.urls import reverse from rest_framework import status @@ -261,6 +264,56 @@ class StockItemListTest(StockAPITestCase): self.assertEqual(len(response['results']), n) + def export_data(self, filters=None): + + if not filters: + filters = {} + + filters['export'] = 'csv' + + response = self.client.get(self.list_url, data=filters) + + self.assertEqual(response.status_code, 200) + + self.assertTrue(isinstance(response, django.http.response.StreamingHttpResponse)) + + file_object = io.StringIO(response.getvalue().decode('utf-8')) + + dataset = tablib.Dataset().load(file_object, 'csv', headers=True) + + return dataset + + def test_export(self): + """ + Test exporting of Stock data via the API + """ + + dataset = self.export_data({}) + + self.assertEqual(len(dataset), 20) + + # Expected headers + headers = [ + 'part', + 'customer', + 'location', + 'parent', + 'quantity', + 'status', + ] + + for h in headers: + self.assertIn(h, dataset.headers) + + # Now, add a filter to the results + dataset = self.export_data({'location': 1}) + + self.assertEqual(len(dataset), 2) + + dataset = self.export_data({'part': 25}) + + self.assertEqual(len(dataset), 8) + class StockItemTest(StockAPITestCase): """