1

I have a problem writing tests for my API routes. I can GET and POST data via Postman or via browser but when I do a POST, GET request from the testing environment it always returns 404 response. I tried different routes none of them works. What I've been doing wrong?

base.py:

    class BaseTestCase(unittest.TestCase):

        def __init__(self, *args, **kwargs):
            self.app = create_app()
            self.app_context = self.app.app_context()
            self.app_context.push()
            super(BaseTestCase, self).__init__(*args, **kwargs)

        def create_app(self):
            self.app.config.from_object("project.config.TestingConfig")
            return self.app

        def setUp(self):
            db.create_all()
            db.session.commit()

test_users.py:

    class TestUsers(BaseTestCase):
        """ Test Users service"""

        def __init__(self, *args, **kwargs):
            self.app = create_app()
            self.app_test = self.app.test_client()
            super(TestUsers, self).__init__(*args, **kwargs)

        def test_add_user(self):
            with self.app.test_client() as client:
                res = client.get('/register')
                print(res.status_code)
                self.assertEqual(res.status_code, 200)

Test fails:

    self.assertEqual(res.status_code, 200)
AssertionError: 404 != 200
Andrew
  • 1,507
  • 1
  • 22
  • 42

0 Answers0