mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-28 17:32:38 +02:00
List supported currencies in API under api/currencies (#961)
* List supported currencies in API under api/currencies * Added test for /currencies route
This commit is contained in:
parent
915c832acc
commit
470c19fe4d
4 changed files with 35 additions and 0 deletions
20
docs/api.md
20
docs/api.md
|
@ -242,3 +242,23 @@ You can get some project stats with a `GET` on
|
|||
"balance": -10.5
|
||||
}
|
||||
]
|
||||
|
||||
### Currencies
|
||||
|
||||
You can get a list of supported currencies with a `GET` on
|
||||
`/api/currencies`:
|
||||
|
||||
$ curl --basic https://ihatemoney.org/api/currencies
|
||||
[
|
||||
"XXX",
|
||||
"AED",
|
||||
"AFN",
|
||||
.
|
||||
.
|
||||
.
|
||||
"ZAR",
|
||||
"ZMW",
|
||||
"ZWL"
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ from flask_restful import Resource, abort
|
|||
from werkzeug.security import check_password_hash
|
||||
from wtforms.fields.core import BooleanField
|
||||
|
||||
from ihatemoney.currency_convertor import CurrencyConverter
|
||||
from ihatemoney.emails import send_creation_email
|
||||
from ihatemoney.forms import EditProjectForm, MemberForm, ProjectForm, get_billform_for
|
||||
from ihatemoney.models import Bill, Person, Project, db
|
||||
|
@ -49,6 +50,13 @@ def need_auth(f):
|
|||
return wrapper
|
||||
|
||||
|
||||
class CurrenciesHandler(Resource):
|
||||
currency_helper = CurrencyConverter()
|
||||
|
||||
def get(self):
|
||||
return self.currency_helper.get_currencies()
|
||||
|
||||
|
||||
class ProjectsHandler(Resource):
|
||||
def post(self):
|
||||
form = ProjectForm(meta={"csrf": False})
|
||||
|
|
|
@ -5,6 +5,7 @@ from flask_restful import Api
|
|||
from ihatemoney.api.common import (
|
||||
BillHandler,
|
||||
BillsHandler,
|
||||
CurrenciesHandler,
|
||||
MemberHandler,
|
||||
MembersHandler,
|
||||
ProjectHandler,
|
||||
|
@ -17,6 +18,7 @@ api = Blueprint("api", __name__, url_prefix="/api")
|
|||
CORS(api)
|
||||
restful_api = Api(api)
|
||||
|
||||
restful_api.add_resource(CurrenciesHandler, "/currencies")
|
||||
restful_api.add_resource(ProjectsHandler, "/projects")
|
||||
restful_api.add_resource(ProjectHandler, "/projects/<string:project_id>")
|
||||
restful_api.add_resource(TokenHandler, "/projects/<string:project_id>/token")
|
||||
|
|
|
@ -576,6 +576,11 @@ class APITestCase(IhatemoneyTestCase):
|
|||
self.assertStatus(400, req)
|
||||
|
||||
def test_currencies(self):
|
||||
# check /currencies for list of supported currencies
|
||||
resp = self.client.get("/api/currencies")
|
||||
self.assertTrue(201, resp.status_code)
|
||||
self.assertIn("XXX", json.loads(resp.data.decode("utf-8")))
|
||||
|
||||
# create project with a default currency
|
||||
resp = self.api_create("raclette", default_currency="EUR")
|
||||
self.assertTrue(201, resp.status_code)
|
||||
|
|
Loading…
Reference in a new issue