lundi 4 avril 2016

Why request is not posted on unit test while it works by simple API call?

This is my code:

#!flask/bin/python
from myProject import app
import unittest


class TestCase(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_login(self):
        response = app.test_client().post('/login', data={})
        self.assertEqual(response.status_code, 200)

if __name__ == '__main__':
    unittest.main()

When I run this script I get the following error:

======================================================================
FAIL: test_login (__main__.TestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_login.py", line 16, in test_login
    self.assertEqual(response.status_code, 200)
AssertionError: 404 != 200

----------------------------------------------------------------------
Ran 1 test in 0.096s

FAILED (failures=1)

I've got 404. But simple API call to /login works as expected. My app in on port 5000 if it is related on anyway. Is there something here I am missing?

Aucun commentaire:

Enregistrer un commentaire