mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Unit testing fixes
This commit is contained in:
parent
d691b15f4b
commit
b3e4efd96e
@ -3,13 +3,13 @@ from rest_framework import status
|
||||
|
||||
from django.urls import reverse
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
|
||||
from part.models import Part
|
||||
from stock.models import StockItem
|
||||
from company.models import Company
|
||||
|
||||
from InvenTree.status_codes import StockStatus
|
||||
from InvenTree.helpers import addUserPermissions
|
||||
|
||||
|
||||
class PartAPITest(APITestCase):
|
||||
@ -36,27 +36,20 @@ class PartAPITest(APITestCase):
|
||||
password='password'
|
||||
)
|
||||
|
||||
# Add the permissions required to access the API endpoints
|
||||
perms = [
|
||||
'view_part',
|
||||
'add_part',
|
||||
'change_part',
|
||||
'delete_part',
|
||||
'view_partcategory',
|
||||
'add_partcategory',
|
||||
'change_partcategory',
|
||||
'view_bomitem',
|
||||
'add_bomitem',
|
||||
'change_bomitem',
|
||||
'view_partattachment',
|
||||
'change_partattachment',
|
||||
'add_partattachment',
|
||||
'view_parttesttemplate',
|
||||
'add_parttesttemplate',
|
||||
'change_parttesttemplate',
|
||||
]
|
||||
# Put the user into a group with the correct permissions
|
||||
group = Group.objects.create(name='mygroup')
|
||||
self.user.groups.add(group)
|
||||
|
||||
addUserPermissions(self.user, perms)
|
||||
# Give the group *all* the permissions!
|
||||
for rule in group.rule_sets.all():
|
||||
rule.can_view = True
|
||||
rule.can_change = True
|
||||
rule.can_add = True
|
||||
rule.can_delete = True
|
||||
|
||||
rule.save()
|
||||
|
||||
group.save()
|
||||
|
||||
self.client.login(username='testuser', password='password')
|
||||
|
||||
|
@ -3,8 +3,7 @@
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
from django.contrib.auth import get_user_model
|
||||
|
||||
from InvenTree.helpers import addUserPermissions
|
||||
from django.contrib.auth.models import Group
|
||||
|
||||
from .models import Part
|
||||
|
||||
@ -31,26 +30,18 @@ class PartViewTestCase(TestCase):
|
||||
password='password'
|
||||
)
|
||||
|
||||
# Add the permissions required to access the pages
|
||||
perms = [
|
||||
'view_part',
|
||||
'add_part',
|
||||
'change_part',
|
||||
'delete_part',
|
||||
'view_partcategory',
|
||||
'add_partcategory',
|
||||
'change_partcategory',
|
||||
'view_bomitem',
|
||||
'add_bomitem',
|
||||
'change_bomitem',
|
||||
'view_partattachment',
|
||||
'change_partattachment',
|
||||
'add_partattachment',
|
||||
]
|
||||
# Put the user into a group with the correct permissions
|
||||
group = Group.objects.create(name='mygroup')
|
||||
self.user.groups.add(group)
|
||||
|
||||
addUserPermissions(self.user, perms)
|
||||
# Give the group *all* the permissions!
|
||||
for rule in group.rule_sets.all():
|
||||
rule.can_view = True
|
||||
rule.can_change = True
|
||||
rule.can_add = True
|
||||
rule.can_delete = True
|
||||
|
||||
self.user.save()
|
||||
rule.save()
|
||||
|
||||
self.client.login(username='username', password='password')
|
||||
|
||||
|
@ -171,6 +171,10 @@ class RuleSet(models.Model):
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
if self.group:
|
||||
# Update the group too!
|
||||
self.group.save()
|
||||
|
||||
def get_models(self):
|
||||
"""
|
||||
Return the database tables / models that this ruleset covers.
|
||||
@ -328,11 +332,6 @@ def create_missing_rule_sets(sender, instance, **kwargs):
|
||||
group permissions.
|
||||
"""
|
||||
|
||||
created = kwargs.get('created', False)
|
||||
# To trigger the group permissions update: update_fields should not be None
|
||||
update_fields = kwargs.get('update_fields', None)
|
||||
|
||||
if created or update_fields:
|
||||
update_group_roles(instance)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user