So I already have a working api endpoint for creating my model.
If I use Postman by sending it this data in the body. Everything works fine
{
"field1": "test",
"field2":"test",
"field3":"test"
}
But if I try to create a test for it by doing this:
new_data = {
"field1": "test",
"field2":"test",
"field3":"test"
}
resp = self.client.post(reverse('item_rest-list'), data=new_data)
And in my create function in view I pop some fields like so:
def create(self, request, *args, **kwargs):
field1 = request.data.pop('field1', None)
field1 becomes a list because request.data value is like this:
{
"field1": [u"test"],
"field2":[u"test"],
"field3":[u"test"]
}
If I do a .get rather than .pop i get it as a string but I need to remove it from the parameters because of some business logic.
field1 = request.data.get('field1')
Is there a way to make test not convert it to test?
so to summarize. request.data value if coming from Postman is this:
{
"field1": "test",
"field2":"test",
"field3":"test"
}
but if coming from self.client.post, its like this
{
"field1": [u"test"],
"field2":[u"test"],
"field3":[u"test"]
}