-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: policy can be designated as a template (#578)
- Loading branch information
1 parent
6729fa8
commit 6d6dd89
Showing
5 changed files
with
129 additions
and
18 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
policykit/policyengine/migrations/0016_policy_is_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.2 on 2022-12-12 16:12 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('policyengine', '0015_auto_20221120_1740'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='policy', | ||
name='is_template', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
19 changes: 19 additions & 0 deletions
19
policykit/policyengine/migrations/0017_alter_policy_community.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 3.2.2 on 2022-12-12 16:18 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('policyengine', '0016_policy_is_template'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='policy', | ||
name='community', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='policyengine.community'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.test import TestCase | ||
from policyengine.models import Policy | ||
|
||
import tests.utils as TestUtils | ||
|
||
|
||
class PolicyCommunityTests(TestCase): | ||
""" | ||
Test policy create/save as it relates to the community field | ||
""" | ||
def test_saving_policy_without_community_raises_exception(self): | ||
# Check that an exception is raied when a non-template policy is saved without a community | ||
with self.assertRaisesRegexp(Exception, "Non template policies must have a community"): | ||
Policy.objects.create( | ||
**TestUtils.ALL_ACTIONS_PROPOSED, | ||
kind=Policy.CONSTITUTION, | ||
is_template=False | ||
) | ||
|
||
def test_saving_template_policy_without_community(self): | ||
# Check that a template policy can be created without a community | ||
policy = Policy.objects.create( | ||
**TestUtils.ALL_ACTIONS_PROPOSED, | ||
kind=Policy.CONSTITUTION, | ||
is_template=True | ||
) | ||
|
||
self.assertEqual(policy.pk, 1) |