From adfa289e9b916f897019da28fb1ff54ef143f3c8 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 15 Feb 2022 09:11:14 +1100 Subject: [PATCH 1/2] Enforce proper formatting for 'quantity' field when importing BOM data --- InvenTree/part/serializers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index c5f5216f38..195ce15e4f 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -960,6 +960,9 @@ class BomExtractSerializer(serializers.Serializer): """ quantity = self.find_matching_data(row, 'quantity', self.dataset.headers) + # Ensure quantity field is provided + row['quantity'] = quantity + if quantity is None: row_error['quantity'] = _('Quantity not provided') else: From c048f3fb4ad10bbf83778346f447f18894349cf6 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 15 Feb 2022 10:50:30 +1100 Subject: [PATCH 2/2] Adds unit tests for index page Some fairly simple unit tests to ensure that the index page is being correctly loaded. --- InvenTree/InvenTree/test_views.py | 65 ++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/InvenTree/InvenTree/test_views.py b/InvenTree/InvenTree/test_views.py index 4f7dddfde4..f6e6de56ff 100644 --- a/InvenTree/InvenTree/test_views.py +++ b/InvenTree/InvenTree/test_views.py @@ -1,11 +1,14 @@ -""" Unit tests for the main web views """ +""" +Unit tests for the main web views +""" + +import re +import os from django.test import TestCase from django.urls import reverse from django.contrib.auth import get_user_model -import os - class ViewTests(TestCase): """ Tests for various top-level views """ @@ -16,9 +19,13 @@ class ViewTests(TestCase): def setUp(self): # Create a user - get_user_model().objects.create_user(self.username, 'user@email.com', self.password) + self.user = get_user_model().objects.create_user(self.username, 'user@email.com', self.password) + self.user.set_password(self.password) + self.user.save() - self.client.login(username=self.username, password=self.password) + result = self.client.login(username=self.username, password=self.password) + + self.assertEqual(result, True) def test_api_doc(self): """ Test that the api-doc view works """ @@ -27,3 +34,51 @@ class ViewTests(TestCase): response = self.client.get(api_url) self.assertEqual(response.status_code, 200) + + def test_index_redirect(self): + """ + top-level URL should redirect to "index" page + """ + + response = self.client.get("/") + + self.assertEqual(response.status_code, 302) + + def get_index_page(self): + """ + Retrieve the index page (used for subsequent unit tests) + """ + + response = self.client.get("/index/") + + self.assertEqual(response.status_code, 200) + + return str(response.content.decode()) + + def test_panels(self): + """ + Test that the required 'panels' are present + """ + + content = self.get_index_page() + + self.assertIn("
", content) + + # TODO: In future, run the javascript and ensure that the panels get created! + + def test_js_load(self): + """ + Test that the required javascript files are loaded correctly + """ + + # Change this number as more javascript files are added to the index page + N_SCRIPT_FILES = 35 + + content = self.get_index_page() + + # Extract all required javascript files from the index page content + script_files = re.findall("