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.
Top comments (0)