feat: Update user's trust bridge information
This commit is contained in:
parent
818b19cf6b
commit
2ebb0b7ee4
6 changed files with 63 additions and 1 deletions
28
userausfall/migrations/0012_auto_20211021_0901.py
Normal file
28
userausfall/migrations/0012_auto_20211021_0901.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
# Generated by Django 3.2.8 on 2021-10-21 09:01
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('userausfall', '0011_trustbridge'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='trustbridge',
|
||||
old_name='user',
|
||||
new_name='trust_taker',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='trustbridge',
|
||||
name='id',
|
||||
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='id',
|
||||
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||
),
|
||||
]
|
20
userausfall/migrations/0013_trustbridge_trust_giver.py
Normal file
20
userausfall/migrations/0013_trustbridge_trust_giver.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 3.2.8 on 2021-10-21 09:04
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('userausfall', '0012_auto_20211021_0901'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='trustbridge',
|
||||
name='trust_giver',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
|
@ -7,3 +7,4 @@ class TrustBridgeSerializer(serializers.ModelSerializer):
|
|||
class Meta:
|
||||
model = TrustBridge
|
||||
fields = ["is_trusted", "trust_giver"]
|
||||
read_only_fields = ["is_trusted"]
|
||||
|
|
|
@ -20,3 +20,15 @@ class TrustBridgeTestCase(UserMixin, UserausfallAPITestCase):
|
|||
"trust_giver": None,
|
||||
},
|
||||
)
|
||||
|
||||
def test_update_trust_bridge(self):
|
||||
"""
|
||||
Update the trust giver of the user's trust bridge.
|
||||
"""
|
||||
url = "/trust-bridge/"
|
||||
other_user = self.create_user()
|
||||
self.create_user()
|
||||
self.authenticate_user()
|
||||
response = self.client.put(self.get_api_url(url), {"trust_giver": other_user.pk})
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(self.user.trust_bridge.trust_giver, other_user)
|
||||
|
|
|
@ -7,7 +7,7 @@ from userausfall.rest_api.serializers import TrustBridgeSerializer
|
|||
from userausfall.views import get_authenticated_user
|
||||
|
||||
|
||||
class TrustBridgeView(generics.RetrieveAPIView):
|
||||
class TrustBridgeView(generics.RetrieveUpdateAPIView):
|
||||
serializer_class = TrustBridgeSerializer
|
||||
|
||||
def get_object(self):
|
||||
|
|
|
@ -10,6 +10,7 @@ class UserMixin:
|
|||
self.username = f"test{User.objects.count()}"
|
||||
self.password = "test12345"
|
||||
self.user = User.objects.create_user(self.username, self.password)
|
||||
return self.user
|
||||
|
||||
def ensure_user_exists(self):
|
||||
if not hasattr(self, "user"):
|
||||
|
|
Reference in a new issue