有人知道为什么会发生这个错误吗?我一直在为我的其他测试运行同一行,只有这一行返回一个错误test_coverageReturnSuccess + test_coverageReturnCorrectCoverage中的两行都返回这个错误:
response.render()
AttributeError: 'HttpResponse' object has no attribute 'render'
这是我的API测试用例
class CoverageTest(APITestCase):
protein = None
domain = None
protein_domain = None
good_url = ''
bad_url = ''
def setUp(self):
self.protein = ProteinFactory.create(pk=1, protein_id='A0A014PQC0', length=338)
self.domain = PfamFactory.create()
self.protein_domain = ProteinDomainLinkFactory.create(protein=self.protein,
pfam_id=self.domain,
start=157,
stop=314)
# Set urls
self.good_url = reverse('coverage', kwargs={'protein_id': 'A0A014PQC0'})
def tearDown(self):
# Reset test tables
Protein.objects.all().delete()
Pfam.objects.all().delete()
ProteinDomainLink.objects.all().delete()
# Reset primary keys
ProteinFactory.reset_sequence(0)
PfamFactory.reset_sequence(0)
ProteinDomainLinkFactory.reset_sequence(0)
def test_coverageReturnSuccess(self):
"""
Ensure we get an 200 OK status code when making a valid GET request.
"""
response = self.client.get(self.good_url, format='json')
response.render()
self.assertEqual(response.status_code, 200)
def test_coverageReturnCorrectCoverage(self):
"""
Ensure we get the right coverage of the requested protein
"""
response = self.client.get(self.good_url, format='json')
response.render()
data = json.loads(response.content)
self.assertEqual(data, 0.46449704142011833)
1条答案
按热度按时间aiqt4smr1#
您不应该 render 响应,因为
response
已经呈现了,所以例如:对于JSON,您用途: