3π
β
If you are running the test cases, it will auto create the database to execute test. In shell you already have database and user is there, itβs authenticating. So you need to create the user here and authenticate. Follow this code:
class RiskViewSetTest(unittest.TestCase):
def setUp(self):
self.client = APIClient()
User.objects.create_user(
username='test@test.us', password='realpassword')
def testClientView(self):
self.client.login(
username='test@test.us',password='realpassword')
response = self.client.get('/api/v1/risks/', format='json')
self.assertTrue(response.status_code, 200)
π€Seenu S
Source:stackexchange.com