Skip to content

Instantly share code, notes, and snippets.

@luiscberrocal
Created January 24, 2019 13:51
Show Gist options
  • Save luiscberrocal/40bbd103d8ad2076ee0613b5e3e91eb6 to your computer and use it in GitHub Desktop.
Save luiscberrocal/40bbd103d8ad2076ee0613b5e3e91eb6 to your computer and use it in GitHub Desktop.
class Test$MODEL$Serializer(TestCase):
def test_expected_fields(self):
$MODEL_LOWER$ = $MODEL$Factory.create()
serializer = $MODEL$Serializer(instance=$MODEL_LOWER$)
$MODEL_LOWER$_data = serializer.data
$MODEL_LOWER$_data_keys = ['id'] #Fixme Poner el resto de los campos del modelo
self.assertEqual(set($MODEL_LOWER$_data.keys()), set($MODEL_LOWER$_data_keys))
def test_creation(self):
$MODEL_LOWER$ = $MODEL$Factory.create()
$MODEL_LOWER$_dict = model_to_dict($MODEL_LOWER$)
$MODEL_LOWER$.delete()
$MODEL_LOWER$_dict.pop('id')
serializer = $MODEL$Serializer(data=$MODEL_LOWER$_dict)
self.assertTrue(serializer.is_valid())
serializer.save()
self.assertEqual($MODEL$.objects.count(), 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment