mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Remove outdated unit tests
This commit is contained in:
parent
17c84141b1
commit
104f9d4a70
@ -5,6 +5,9 @@ from datetime import datetime, timedelta
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
from rest_framework.test import APITestCase
|
||||
from rest_framework import status
|
||||
|
||||
from part.models import Part
|
||||
from build.models import Build, BuildItem
|
||||
from stock.models import StockItem
|
||||
@ -13,6 +16,84 @@ from InvenTree.status_codes import BuildStatus
|
||||
from InvenTree.api_tester import InvenTreeAPITestCase
|
||||
|
||||
|
||||
class TestBuildAPI(APITestCase):
|
||||
"""
|
||||
Series of tests for the Build DRF API
|
||||
- Tests for Build API
|
||||
- Tests for BuildItem API
|
||||
"""
|
||||
|
||||
fixtures = [
|
||||
'category',
|
||||
'part',
|
||||
'location',
|
||||
'build',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
# Create a user for auth
|
||||
user = get_user_model()
|
||||
self.user = user.objects.create_user('testuser', 'test@testing.com', 'password')
|
||||
|
||||
g = Group.objects.create(name='builders')
|
||||
self.user.groups.add(g)
|
||||
|
||||
for rule in g.rule_sets.all():
|
||||
if rule.name == 'build':
|
||||
rule.can_change = True
|
||||
rule.can_add = True
|
||||
rule.can_delete = True
|
||||
|
||||
rule.save()
|
||||
|
||||
g.save()
|
||||
|
||||
self.client.login(username='testuser', password='password')
|
||||
|
||||
def test_get_build_list(self):
|
||||
"""
|
||||
Test that we can retrieve list of build objects
|
||||
"""
|
||||
|
||||
url = reverse('api-build-list')
|
||||
response = self.client.get(url, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
self.assertEqual(len(response.data), 5)
|
||||
|
||||
# Filter query by build status
|
||||
response = self.client.get(url, {'status': 40}, format='json')
|
||||
|
||||
self.assertEqual(len(response.data), 4)
|
||||
|
||||
# Filter by "active" status
|
||||
response = self.client.get(url, {'active': True}, format='json')
|
||||
self.assertEqual(len(response.data), 1)
|
||||
self.assertEqual(response.data[0]['pk'], 1)
|
||||
|
||||
response = self.client.get(url, {'active': False}, format='json')
|
||||
self.assertEqual(len(response.data), 4)
|
||||
|
||||
# Filter by 'part' status
|
||||
response = self.client.get(url, {'part': 25}, format='json')
|
||||
self.assertEqual(len(response.data), 1)
|
||||
|
||||
# Filter by an invalid part
|
||||
response = self.client.get(url, {'part': 99999}, format='json')
|
||||
self.assertEqual(len(response.data), 0)
|
||||
|
||||
def test_get_build_item_list(self):
|
||||
""" Test that we can retrieve list of BuildItem objects """
|
||||
url = reverse('api-build-item-list')
|
||||
|
||||
response = self.client.get(url, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
# Test again, filtering by park ID
|
||||
response = self.client.get(url, {'part': '1'}, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
|
||||
class BuildAPITest(InvenTreeAPITestCase):
|
||||
"""
|
||||
Series of tests for the Build DRF API
|
||||
|
@ -6,10 +6,6 @@ from django.urls import reverse
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
|
||||
from rest_framework.test import APITestCase
|
||||
from rest_framework import status
|
||||
|
||||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from .models import Build
|
||||
@ -112,84 +108,6 @@ class BuildTestSimple(TestCase):
|
||||
self.assertEqual(build.status, BuildStatus.CANCELLED)
|
||||
|
||||
|
||||
class TestBuildAPI(APITestCase):
|
||||
"""
|
||||
Series of tests for the Build DRF API
|
||||
- Tests for Build API
|
||||
- Tests for BuildItem API
|
||||
"""
|
||||
|
||||
fixtures = [
|
||||
'category',
|
||||
'part',
|
||||
'location',
|
||||
'build',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
# Create a user for auth
|
||||
user = get_user_model()
|
||||
self.user = user.objects.create_user('testuser', 'test@testing.com', 'password')
|
||||
|
||||
g = Group.objects.create(name='builders')
|
||||
self.user.groups.add(g)
|
||||
|
||||
for rule in g.rule_sets.all():
|
||||
if rule.name == 'build':
|
||||
rule.can_change = True
|
||||
rule.can_add = True
|
||||
rule.can_delete = True
|
||||
|
||||
rule.save()
|
||||
|
||||
g.save()
|
||||
|
||||
self.client.login(username='testuser', password='password')
|
||||
|
||||
def test_get_build_list(self):
|
||||
"""
|
||||
Test that we can retrieve list of build objects
|
||||
"""
|
||||
|
||||
url = reverse('api-build-list')
|
||||
response = self.client.get(url, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
self.assertEqual(len(response.data), 5)
|
||||
|
||||
# Filter query by build status
|
||||
response = self.client.get(url, {'status': 40}, format='json')
|
||||
|
||||
self.assertEqual(len(response.data), 4)
|
||||
|
||||
# Filter by "active" status
|
||||
response = self.client.get(url, {'active': True}, format='json')
|
||||
self.assertEqual(len(response.data), 1)
|
||||
self.assertEqual(response.data[0]['pk'], 1)
|
||||
|
||||
response = self.client.get(url, {'active': False}, format='json')
|
||||
self.assertEqual(len(response.data), 4)
|
||||
|
||||
# Filter by 'part' status
|
||||
response = self.client.get(url, {'part': 25}, format='json')
|
||||
self.assertEqual(len(response.data), 1)
|
||||
|
||||
# Filter by an invalid part
|
||||
response = self.client.get(url, {'part': 99999}, format='json')
|
||||
self.assertEqual(len(response.data), 0)
|
||||
|
||||
def test_get_build_item_list(self):
|
||||
""" Test that we can retrieve list of BuildItem objects """
|
||||
url = reverse('api-build-item-list')
|
||||
|
||||
response = self.client.get(url, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
# Test again, filtering by park ID
|
||||
response = self.client.get(url, {'part': '1'}, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
|
||||
class TestBuildViews(TestCase):
|
||||
""" Tests for Build app views """
|
||||
|
||||
@ -251,28 +169,3 @@ class TestBuildViews(TestCase):
|
||||
content = str(response.content)
|
||||
|
||||
self.assertIn(build.title, content)
|
||||
|
||||
def test_build_cancel(self):
|
||||
""" Test the build cancellation form """
|
||||
|
||||
url = reverse('build-cancel', args=(1,))
|
||||
|
||||
# Test without confirmation
|
||||
response = self.client.post(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
data = json.loads(response.content)
|
||||
self.assertFalse(data['form_valid'])
|
||||
|
||||
b = Build.objects.get(pk=1)
|
||||
self.assertEqual(b.status, 10) # Build status is still PENDING
|
||||
|
||||
# Test with confirmation
|
||||
response = self.client.post(url, {'confirm_cancel': 1}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
data = json.loads(response.content)
|
||||
self.assertTrue(data['form_valid'])
|
||||
|
||||
b = Build.objects.get(pk=1)
|
||||
self.assertEqual(b.status, 30) # Build status is now CANCELLED
|
||||
|
@ -76,30 +76,3 @@ class POTests(OrderViewTestCase):
|
||||
|
||||
# Response should be streaming-content (file download)
|
||||
self.assertIn('streaming_content', dir(response))
|
||||
|
||||
def test_po_issue(self):
|
||||
""" Test PurchaseOrderIssue view """
|
||||
|
||||
url = reverse('po-issue', args=(1,))
|
||||
|
||||
order = PurchaseOrder.objects.get(pk=1)
|
||||
self.assertEqual(order.status, PurchaseOrderStatus.PENDING)
|
||||
|
||||
# Test without confirmation
|
||||
response = self.client.post(url, {'confirm': 0}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
data = json.loads(response.content)
|
||||
|
||||
self.assertFalse(data['form_valid'])
|
||||
|
||||
# Test WITH confirmation
|
||||
response = self.client.post(url, {'confirm': 1}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
data = json.loads(response.content)
|
||||
self.assertTrue(data['form_valid'])
|
||||
|
||||
# Test that the order was actually placed
|
||||
order = PurchaseOrder.objects.get(pk=1)
|
||||
self.assertEqual(order.status, PurchaseOrderStatus.PLACED)
|
||||
|
Loading…
Reference in New Issue
Block a user