dev-resources.site
for different kinds of informations.
I just tried to compare values between model and serializer
Published at
10/18/2024
Categories
django
drf
unittest
Author
hyun_hyun
Author
9 person written this
hyun_hyun
open
I encountered tests like below. And I want to know why he checked the value through serializer. So, I check the values.
- Create board
- Add param
- Check the param in the board
def test(self):
board = create_board(user=self.user, title='Sunday Roast secret')
com = Command.objects.create(user=self.user, content='So interesting')
board.commands.add(com)
params = {'commands': f'{com.id}'}
res = self.client.get(BOARD_URL, params)
b1 = BoardSerializer(board)
self.assertIn(b1.data, res.data)
board
Sunday Roast secret
b1
BoardSerializer(<Board: Sunday Roast secret>):
id = IntegerField(label='ID', read_only=True)
title = CharField(max_length=255)
tags = TagSerializer(many=True, required=False):
id = IntegerField(label='ID', read_only=True)
name = CharField(max_length=255)
commands = CommandSerializer(...)
Serializer returns all the values stored. If you want to check the value through the data included, you can use this way.
drf Article's
30 articles in total
Djoser+SimpleJWT
read article
AssertionError: 403
read article
extra_kwargs arguments
read article
To Django or to DjangoREST?
read article
Django API | queryset & object, filter() & get()
read article
I just tried to compare values between model and serializer
currently reading
Customize Schema with @extend_schema_view
read article
Seperate serializers
read article
Leveraging Headers for Dynamic Localization in Django
read article
Django REST Framework warning: `UnorderedObjectListWarning`
read article
DRF create @property decorator in view and use property in serializer
read article
why Serializers used for? easy to understand
read article
Async API Calls Unleashed: Exploring Django 4 and Django Rest Framework
read article
# Comprehensive Security for Class-Based Views in Django Rest Framework
read article
HATEOAS Principle - Generating Full Paths for Objects in Django Rest Framework.
read article
Instance version control in DRF with Django Reversion
read article
Django News #171 - DjangoCon US 2023 Preview
read article
How to create thumbnails programmatically in Django
read article
Automatically Add Logged In User Under 'created_by' and 'updated_by' to Model in Django Rest Framework
read article
how to fix raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
read article
CSRF verification failed. Request aborted. in django rest framework
read article
CSRF verification failed. Request aborted. in django rest framework
read article
How to fix "Must supply api_key"
read article
Updating A Many-To-Many Relationship In Django
read article
Excluding Fields in Django Rest Framework Serializers
read article
JWT Authentication with Django REST Framework - What? Why? How?
read article
How to implement Auto Expiring Token in Django Rest Framework
read article
Building web applications with Django, Django REST Framework and Nuxt
read article
How to use Postman to authenticate to Django Rest Framework
read article
Setting Up Django Rest Framework
read article
Featured ones: