Use reverse to get Build URL

- Add test cases to Build
This commit is contained in:
Oliver Walters 2019-04-24 23:42:50 +10:00
parent d46afcdfe8
commit 5098712d9c
2 changed files with 56 additions and 2 deletions

View File

@ -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

View File

@ -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