Logo

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
Categories
3 categories in total
django
open
drf
open
unittest
open
Author
9 person written this
hyun_hyun
open
I just tried to compare values between model and serializer

I encountered tests like below. And I want to know why he checked the value through serializer. So, I check the values.

  1. Create board
  2. Add param
  3. 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)
Enter fullscreen mode Exit fullscreen mode

board

Sunday Roast secret
Enter fullscreen mode Exit fullscreen mode

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(...)
Enter fullscreen mode Exit fullscreen mode

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
Favicon
Djoser+SimpleJWT
Favicon
AssertionError: 403
Favicon
extra_kwargs arguments
Favicon
To Django or to DjangoREST?
Favicon
Django API | queryset & object, filter() & get()
Favicon
I just tried to compare values between model and serializer
Favicon
Customize Schema with @extend_schema_view
Favicon
Seperate serializers
Favicon
Leveraging Headers for Dynamic Localization in Django
Favicon
Django REST Framework warning: `UnorderedObjectListWarning`
Favicon
DRF create @property decorator in view and use property in serializer
Favicon
why Serializers used for? easy to understand
Favicon
Async API Calls Unleashed: Exploring Django 4 and Django Rest Framework
Favicon
# Comprehensive Security for Class-Based Views in Django Rest Framework
Favicon
HATEOAS Principle - Generating Full Paths for Objects in Django Rest Framework.
Favicon
Instance version control in DRF with Django Reversion
Favicon
Django News #171 - DjangoCon US 2023 Preview
Favicon
How to create thumbnails programmatically in Django
Favicon
Automatically Add Logged In User Under 'created_by' and 'updated_by' to Model in Django Rest Framework
Favicon
how to fix raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
Favicon
CSRF verification failed. Request aborted. in django rest framework
Favicon
CSRF verification failed. Request aborted. in django rest framework
Favicon
How to fix "Must supply api_key"
Favicon
Updating A Many-To-Many Relationship In Django
Favicon
Excluding Fields in Django Rest Framework Serializers
Favicon
JWT Authentication with Django REST Framework - What? Why? How?
Favicon
How to implement Auto Expiring Token in Django Rest Framework
Favicon
Building web applications with Django, Django REST Framework and Nuxt
Favicon
How to use Postman to authenticate to Django Rest Framework
Favicon
Setting Up Django Rest Framework

Featured ones: