From 5098712d9c88bd8fac7f2e91a587b152c5cc8fb5 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 24 Apr 2019 23:42:50 +1000 Subject: [PATCH] Use reverse to get Build URL - Add test cases to Build --- InvenTree/build/models.py | 3 ++- InvenTree/build/tests.py | 55 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index d09e751878..c72aa5209b 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from django.utils.translation import ugettext as _ +from django.urls import reverse from django.db import models from django.core.validators import MinValueValidator @@ -14,7 +15,7 @@ class Build(models.Model): """ def get_absolute_url(self): - return '/build/{pk}/'.format(pk=self.id) + return reverse('build-detail', kwargs={'pk': self.id}) # Build status codes PENDING = 10 # Build is pending / active diff --git a/InvenTree/build/tests.py b/InvenTree/build/tests.py index c2de5b3ab1..43281c34b7 100644 --- a/InvenTree/build/tests.py +++ b/InvenTree/build/tests.py @@ -1,6 +1,59 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -# from django.test import TestCase +from django.test import TestCase + +from .models import Build +from part.models import Part # Create your tests here. + + +class BuildTestSimple(TestCase): + + def setUp(self): + part = Part.objects.create(name='Test part', + description='Simple description') + Build.objects.create(part=part, + batch='B1', + status=Build.PENDING, + title='Building 7 parts', + quantity=7, + notes='Some simple notes') + + Build.objects.create(part=part, + batch='B2', + status=Build.COMPLETE, + title='Building 21 parts', + quantity=21, + notes='Some simple notes') + + def test_build_objects(self): + # Ensure the Build objects were correctly created + self.assertEqual(Build.objects.count(), 2) + b = Build.objects.get(pk=2) + self.assertEqual(b.batch, 'B2') + self.assertEqual(b.quantity, 21) + + def test_url(self): + b1 = Build.objects.get(pk=1) + self.assertEqual(b1.get_absolute_url(), '/build/1/') + + def test_is_complete(self): + b1 = Build.objects.get(pk=1) + b2 = Build.objects.get(pk=2) + + self.assertEqual(b1.is_complete, False) + self.assertEqual(b2.is_complete, True) + + def test_is_active(self): + b1 = Build.objects.get(pk=1) + b2 = Build.objects.get(pk=2) + + self.assertEqual(b1.is_active, True) + self.assertEqual(b2.is_active, False) + + def test_required_parts(self): + # TODO - Generate BOM for test part + pass + \ No newline at end of file