def test_sub_paths(self, request_client):
        rv = request_client.get("/api/v1/bananas/sub")
        assert "200" in str(rv.status)
        assert rv.get_json()["data"] == "sub"

        rv = request_client.get("/api/v1/test/sub_two")
        assert "401" in str(rv.status)
    def test_dynamic_params(self, request_client):
        rv = request_client.put("/api/v1/apples/sub/1")
        assert "200" in str(rv.status)

        rv = request_client.get("/api/v1/apples/sub/")
        assert "404" in str(rv.status)

        rv = request_client.get("/api/v1/apples/sub/hello")
        assert "404" in str(rv.status)
    def test_static_routes(self, request_client):
        """
        Tests if the static path is handled both by default and
        if the path is past to the static_folder kwarg
        """
        rv = request_client.get("/static/images/Group.jpg")
        assert "200" in str(rv.status)

        rv = request_client.get("/")
        assert "200" in str(rv.status)
    def test_get_attr_name(self, request_client):
        from tests.fixtures.models import TeacherModel
        from tests.fixtures.main_fixture import db
        teacher = TeacherModel(name="joe")
        db.session.add(teacher)
        db.session.commit()
        rv = request_client.post("/api/v1/test_entity")
        assert "200" in str(rv.status)
        assert "token" in str(rv.get_json())

        token = rv.get_json()["token"]

        decoded_token = jwt.decode(token,
                                   "__TEST_SECRET__",
                                   algorithms="HS256")

        assert decoded_token["table_name"] == "teachers"

        headers = {
            "Content-Type": "application/json",
            "Authorization": f"Bearer {token}",
        }
        rv_get = request_client.get("/api/v1/test_entity", headers=headers)

        assert "200" in str(rv_get.status)
        assert "token" in str(rv_get.get_json())
        assert rv_get.get_json()["data"] == {"teacher_id": 1, "name": "joe"}

        token_two = rv_get.get_json()["token"]

        decoded_token_two = jwt.decode(token_two,
                                       "__TEST_SECRET__",
                                       algorithms="HS256")

        assert decoded_token_two["table_name"] == "teachers"
    def test_routing_with_google_create_headers_scope(self, request_client,
                                                      MockAOuthModel,
                                                      google_oauth_user):
        email = "*****@*****.**"
        test_user = MockAOuthModel(email="*****@*****.**")
        test_metadata = {
            "email": email,
            "entity": test_user,
            "scope": "application"
        }
        google = jwt_routes.get_strategy("GoogleTestUtil")
        assert google.test_metadata == {}
        # Pure stateless test with no db
        oauth_headers = google.create_test_headers(email=email,
                                                   entity=test_user,
                                                   scope="application")

        assert google.test_metadata[email] == test_metadata
        assert oauth_headers == {'X-Auth-Token': f'Bearer {email}'}

        rv = request_client.get("/api/v1/test_google_oauth",
                                headers=oauth_headers)
        assert "200" in str(rv.status)
        assert email == rv.get_json()["email"]
        assert google.test_metadata[email] == test_metadata
 def test_ignored_route_path(self, request_client):
     rv = request_client.get("/")
     assert "200" in str(rv.status)
 def test_api_named_routes(self, request_client):
     rv = request_client.get("/api/v1/test")
     assert "200" in str(rv.status)