From 67ebe907422ce09c526f6ee2f58673b30341bcf7 Mon Sep 17 00:00:00 2001 From: enrico Date: Fri, 19 Aug 2022 18:01:18 +0800 Subject: [PATCH] Fixed post unit tests --- tests/test_views.py | 61 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/tests/test_views.py b/tests/test_views.py index da6271d2c..2bcee571e 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -81,21 +81,20 @@ class ClassBasedViewIntegrationTests(TestCase): self.view = BasicView.as_view() def test_get_succeeds(self): - request = factory.get('/', content_type='application/json') + request = factory.get('/') response = self.view(request) assert response.status_code == status.HTTP_200_OK assert response.data == {'method': 'GET'} - # def test_post_succeeds(self): - # request = factory.post('/', {"test": "foo"}, content_type='application/json') - # response = self.view(request) - # import pdb; pdb.set_trace() - # expected = { - # 'method': 'POST', - # 'data': {'test': 'foo'} - # } - # assert response.status_code == status.HTTP_200_OK - # assert response.data == expected + def test_post_succeeds(self): + request = factory.post('/', {'test': 'foo'}) + response = self.view(request) + expected = { + 'method': 'POST', + 'data': {'test': ['foo']} + } + assert response.status_code == status.HTTP_200_OK + assert response.data == expected def test_400_parse_error(self): request = factory.post('/', 'f00bar', content_type='application/json') @@ -112,20 +111,20 @@ class FunctionBasedViewIntegrationTests(TestCase): self.view = basic_view def test_get_succeeds(self): - request = factory.get('/', content_type='application/json') + request = factory.get('/') response = self.view(request) assert response.status_code == status.HTTP_200_OK assert response.data == {'method': 'GET'} - # def test_post_succeeds(self): - # request = factory.post('/', {'test': 'foo'}, content_type='application/json') - # response = self.view(request) - # expected = { - # 'method': 'POST', - # 'data': {'test': 'foo'} - # } - # assert response.status_code == status.HTTP_200_OK - # assert response.data == expected + def test_post_succeeds(self): + request = factory.post('/', {'test': 'foo'}) + response = self.view(request) + expected = { + 'method': 'POST', + 'data': {'test': ['foo']} + } + assert response.status_code == status.HTTP_200_OK + assert response.data == expected def test_400_parse_error(self): request = factory.post('/', 'f00bar', content_type='application/json') @@ -142,20 +141,20 @@ class ClassBasedAsyncViewIntegrationTests(TestCase): self.view = BasicAsyncView.as_view() def test_get_succeeds(self): - request = factory.get('/', content_type='application/json') + request = factory.get('/') response = self.view(request) assert response.status_code == status.HTTP_200_OK assert response.data == {'method': 'GET'} -# def test_post_succeeds(self): -# request = factory.post('/', {'test': 'foo'}, content_type='application/json') -# response = self.view(request) -# expected = { -# 'method': 'POST', -# 'data': {'test': 'foo'} -# } -# assert response.status_code == status.HTTP_200_OK -# assert response.data == expected + def test_post_succeeds(self): + request = factory.post('/', {'test': 'foo'}) + response = self.view(request) + expected = { + 'method': 'POST', + 'data': {'test': ['foo']} + } + assert response.status_code == status.HTTP_200_OK + assert response.data == expected def test_400_parse_error(self): request = factory.post('/', 'f00bar', content_type='application/json')