generated from brylie/django-bootstrap-quick-start
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from GeriLife/add-home-user-assignment
Add home userassignment
- Loading branch information
Showing
19 changed files
with
931 additions
and
59 deletions.
There are no files selected for viewing
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,11 @@ | ||
import factory | ||
|
||
from .models import User | ||
|
||
|
||
class UserFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = User | ||
|
||
username = factory.Sequence(lambda n: f"user{n}") | ||
email = factory.Faker("email") |
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 |
---|---|---|
@@ -1 +1,58 @@ | ||
# Create your tests here. | ||
from django.test import TestCase | ||
from django.contrib.auth import get_user_model | ||
|
||
from residents.factories import ResidentFactory, ResidencyFactory | ||
from homes.factories import HomeFactory, HomeUserRelationFactory | ||
|
||
|
||
User = get_user_model() | ||
|
||
|
||
class CanManageResidentsTest(TestCase): | ||
def setUp(self): | ||
self.superuser = User.objects.create_superuser( | ||
username="superuser", | ||
email="[email protected]", | ||
password="testpassword", | ||
) | ||
self.regular_user = User.objects.create_user( | ||
username="regularuser", | ||
email="[email protected]", | ||
password="testpassword", | ||
) | ||
|
||
self.home1 = HomeFactory() | ||
self.home2 = HomeFactory() | ||
|
||
self.resident1 = ResidentFactory() | ||
self.resident2 = ResidentFactory() | ||
|
||
ResidencyFactory( | ||
resident=self.resident1, | ||
home=self.home1, | ||
) | ||
ResidencyFactory( | ||
resident=self.resident2, | ||
home=self.home2, | ||
) | ||
|
||
HomeUserRelationFactory( | ||
home=self.home1, | ||
user=self.regular_user, | ||
) | ||
|
||
def test_superuser_can_manage_all_residents(self): | ||
resident_ids = [self.resident1.id, self.resident2.id] | ||
self.assertTrue(self.superuser.can_manage_residents(resident_ids)) | ||
|
||
def test_regular_user_can_manage_associated_residents(self): | ||
resident_ids = [ | ||
self.resident1.id, | ||
] | ||
self.assertTrue(self.regular_user.can_manage_residents(resident_ids)) | ||
|
||
def test_regular_user_cannot_manage_unassociated_residents(self): | ||
resident_ids = [ | ||
self.resident2.id, | ||
] | ||
self.assertFalse(self.regular_user.can_manage_residents(resident_ids)) |
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
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 |
---|---|---|
@@ -1,10 +1,29 @@ | ||
import factory | ||
from factory import Sequence | ||
|
||
from .models import Home, HomeGroup, HomeUserRelation | ||
|
||
|
||
class HomeFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = "homes.Home" | ||
model = Home | ||
django_get_or_create = ("name",) | ||
|
||
name: str = Sequence(lambda n: f"Home {n}") | ||
|
||
|
||
class HomeGroupFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = HomeGroup | ||
django_get_or_create = ("name",) | ||
|
||
name: str = Sequence(lambda n: f"Home Group {n}") | ||
|
||
|
||
class HomeUserRelationFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = HomeUserRelation | ||
django_get_or_create = ("home", "user") | ||
|
||
home: Home = factory.SubFactory(HomeFactory) | ||
user: Home = factory.SubFactory(HomeFactory) |
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,30 @@ | ||
# Generated by Django 5.0 on 2024-01-04 19:24 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('homes', '0006_alter_home_home_group'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='HomeUserRelation', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('home', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='home_user_relations', to='homes.home')), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='home_user_relations', to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'verbose_name': 'home user relation', | ||
'verbose_name_plural': 'home user relations', | ||
'db_table': 'home_user_relation', | ||
'unique_together': {('user', 'home')}, | ||
}, | ||
), | ||
] |
Oops, something went wrong.