mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 13:05:42 +00:00
Merge branch 'inventree:master' into not-working-tests
This commit is contained in:
@ -45,6 +45,7 @@ class PartResource(ModelResource):
|
||||
exclude = [
|
||||
'bom_checksum', 'bom_checked_by', 'bom_checked_date',
|
||||
'lft', 'rght', 'tree_id', 'level',
|
||||
'metadata',
|
||||
]
|
||||
|
||||
def get_queryset(self):
|
||||
@ -98,6 +99,7 @@ class PartCategoryResource(ModelResource):
|
||||
exclude = [
|
||||
# Exclude MPTT internal model fields
|
||||
'lft', 'rght', 'tree_id', 'level',
|
||||
'metadata',
|
||||
]
|
||||
|
||||
def after_import(self, dataset, result, using_transactions, dry_run, **kwargs):
|
||||
|
@ -822,6 +822,58 @@ class PartAPITest(InvenTreeAPITestCase):
|
||||
response = self.get('/api/part/10004/', {})
|
||||
self.assertEqual(response.data['variant_stock'], 500)
|
||||
|
||||
def test_part_download(self):
|
||||
"""Test download of part data via the API"""
|
||||
|
||||
url = reverse('api-part-list')
|
||||
|
||||
required_cols = [
|
||||
'id',
|
||||
'name',
|
||||
'description',
|
||||
'in_stock',
|
||||
'category_name',
|
||||
'keywords',
|
||||
'is_template',
|
||||
'virtual',
|
||||
'trackable',
|
||||
'active',
|
||||
'notes',
|
||||
'creation_date',
|
||||
]
|
||||
|
||||
excluded_cols = [
|
||||
'lft', 'rght', 'level', 'tree_id',
|
||||
'metadata',
|
||||
]
|
||||
|
||||
with self.download_file(
|
||||
url,
|
||||
{
|
||||
'export': 'csv',
|
||||
},
|
||||
expected_fn='InvenTree_Parts.csv',
|
||||
) as fo:
|
||||
|
||||
data = self.process_csv(
|
||||
fo,
|
||||
excluded_cols=excluded_cols,
|
||||
required_cols=required_cols,
|
||||
required_rows=Part.objects.count(),
|
||||
)
|
||||
|
||||
for row in data:
|
||||
part = Part.objects.get(pk=row['id'])
|
||||
|
||||
if part.IPN:
|
||||
self.assertEqual(part.IPN, row['IPN'])
|
||||
|
||||
self.assertEqual(part.name, row['name'])
|
||||
self.assertEqual(part.description, row['description'])
|
||||
|
||||
if part.category:
|
||||
self.assertEqual(part.category.name, row['category_name'])
|
||||
|
||||
|
||||
class PartDetailTests(InvenTreeAPITestCase):
|
||||
"""
|
||||
@ -1046,24 +1098,29 @@ class PartDetailTests(InvenTreeAPITestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertIn('Upload a valid image', str(response.data))
|
||||
|
||||
# Now try to upload a valid image file
|
||||
img = PIL.Image.new('RGB', (128, 128), color='red')
|
||||
img.save('dummy_image.jpg')
|
||||
# Now try to upload a valid image file, in multiple formats
|
||||
for fmt in ['jpg', 'png', 'bmp', 'webp']:
|
||||
fn = f'dummy_image.{fmt}'
|
||||
|
||||
with open('dummy_image.jpg', 'rb') as dummy_image:
|
||||
response = upload_client.patch(
|
||||
url,
|
||||
{
|
||||
'image': dummy_image,
|
||||
},
|
||||
format='multipart',
|
||||
)
|
||||
img = PIL.Image.new('RGB', (128, 128), color='red')
|
||||
img.save(fn)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
with open(fn, 'rb') as dummy_image:
|
||||
response = upload_client.patch(
|
||||
url,
|
||||
{
|
||||
'image': dummy_image,
|
||||
},
|
||||
format='multipart',
|
||||
)
|
||||
|
||||
# And now check that the image has been set
|
||||
p = Part.objects.get(pk=pk)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
# And now check that the image has been set
|
||||
p = Part.objects.get(pk=pk)
|
||||
self.assertIsNotNone(p.image)
|
||||
|
||||
def test_details(self):
|
||||
"""
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
from allauth.account.models import EmailAddress
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from django.test import TestCase
|
||||
@ -64,11 +65,21 @@ class TemplateTagTest(TestCase):
|
||||
|
||||
def test_hash(self):
|
||||
result_hash = inventree_extras.inventree_commit_hash()
|
||||
self.assertGreater(len(result_hash), 5)
|
||||
if settings.DOCKER:
|
||||
# Testing inside docker environment *may* return an empty git commit hash
|
||||
# In such a case, skip this check
|
||||
pass
|
||||
else:
|
||||
self.assertGreater(len(result_hash), 5)
|
||||
|
||||
def test_date(self):
|
||||
d = inventree_extras.inventree_commit_date()
|
||||
self.assertEqual(len(d.split('-')), 3)
|
||||
if settings.DOCKER:
|
||||
# Testing inside docker environment *may* return an empty git commit hash
|
||||
# In such a case, skip this check
|
||||
pass
|
||||
else:
|
||||
self.assertEqual(len(d.split('-')), 3)
|
||||
|
||||
def test_github(self):
|
||||
self.assertIn('github.com', inventree_extras.inventree_github_url())
|
||||
|
Reference in New Issue
Block a user