Skip to content

Commit d55763c

Browse files
committed
[Feature: #159833284] Add /questions get endpoint
1 parent c488001 commit d55763c

File tree

10 files changed

+56
-14
lines changed

10 files changed

+56
-14
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from flask import jsonify
2+
from api.app.models import Question
3+
4+
5+
class QuestionsController:
6+
def index(self):
7+
return jsonify({
8+
"data": Question.all()
9+
})

api/app/controllers/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .HomeController import HomeController
2+
from .QuestionsController import QuestionsController
23

34

4-
__all__ = ["HomeController"]
5+
__all__ = ["HomeController", "QuestionsController"]

api/app/models/Question.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from api.core.storage import Model
2+
3+
4+
class Question(Model):
5+
pass

api/app/models/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .Question import Question
2+
3+
__all__ = ["Question"]

api/app/routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
Router.group([
66
Router.get("/", HomeController, "index"),
7-
Router.resource("/questions", HomeController)
7+
Router.resource("/questions", QuestionsController)
88
]).prefix("/api/v1.0")

api/core/storage/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from .storage import Storage, Model
1+
from .storage import Storage, Model, ModelCollection
22

3-
__all__ = ["Storage", "Model"]
3+
__all__ = ["Storage", "Model", "ModelCollection"]

tests/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
from unittest import TestCase
2-
from api.app import create_app
3-
4-
5-
class BaseTestCase(TestCase):
6-
7-
def setUp(self):
8-
self.app = create_app("testing")
9-
self.client = self.app.test_client()

tests/feature/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from unittest import TestCase
2+
from api.app import create_app
3+
4+
5+
class BaseTestCase(TestCase):
6+
7+
def setUp(self):
8+
self.app = create_app("testing")
9+
self.client = self.app.test_client()
10+
self.url_prefix = "api"
11+
self.api_version = "v1.0"
12+
13+
def get(self, url):
14+
return self.client.get(**self._make_options(url))
15+
16+
def post(self, url, json=None):
17+
return self.client.get(**self._make_options(url, json))
18+
19+
def _base_url(self, url):
20+
return f"/{self.url_prefix}/{self.api_version}{url}"
21+
22+
def _make_options(self, url, json=None):
23+
options = dict(path=self._base_url(url))
24+
if json:
25+
options["json"] = json
26+
return options

tests/feature/test_HomeController.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from tests import BaseTestCase
1+
from tests.feature import BaseTestCase
22

33

44
class TestHomeController(BaseTestCase):

tests/feature/test_Questions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from tests.feature import BaseTestCase
2+
3+
4+
class TestQuestions(BaseTestCase):
5+
def test_it_returns_a_200_response_for_index_route(self):
6+
rv = self.get("/questions")
7+
self.assertEqual(rv.status_code, 200)

0 commit comments

Comments
 (0)