Hi I am now using Django REST3.5.3. I can do CRUD perfectly fine with browsable API.
My problem is my test does not pass.
tests.py
import os
from django.test import Client
from apps.price_list_excel_files.models import PriceListExcelFile
def upload_excel(user: str, passwd: str) -> tuple:
client = Client()
client.login(username=user, password=passwd)
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(dir_path + '/mixed_case.xlsx', 'rb') as fp:
response = client.post(
'/api/price-list-excel-files/',
{'file': fp},
format='multipart'
)
return client, response
def test_mgmt_user_upload_excel(prepare_mgmt_users):
client, response = upload_excel("John", "johnpassword")
assert 201 == response.status_code
assert 1 == PriceListExcelFile.objects.count()
# TODO: Fix this testcase
def test_mgmt_user_remove_excel(prepare_mgmt_users):
client, response = upload_excel("John", "johnpassword")
excel_id = response.data.get('id')
url = '/api/price-list-excel-files/' + str(excel_id) + '/'
res2 = client.delete(url, data={'format': 'json'})
import pdb;
pdb.set_trace()
assert 0 == PriceListExcelFile.objects.count()
Here is my pdb
console:
apps/price_list_excel_files/tests.py .
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB set_trace (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /Users/el/Code/siam-sbrand/portal/apps/price_list_excel_files/tests.py(37)test_mgmt_user_remove_excel()
-> assert 0 == PriceListExcelFile.objects.count()
(Pdb) list
32 url = '/api/price-list-excel-files/' + str(excel_id) + '/'
33 res2 = client.delete(url, data={'format': 'json'})
34 import pdb;
35 pdb.set_trace()
36
37 -> assert 0 == PriceListExcelFile.objects.count()
[EOF]
(Pdb) res2
*** KeyError: 'content-type'
(Pdb) url
'/api/price-list-excel-files/2/'
(Pdb) res3 = client.delete(url)
(Pdb) res3
<Response status_code=404, "application/json">
Am I miss something?
Aucun commentaire:
Enregistrer un commentaire