Browse Source

[REF] emc_api: rename service subscription-request

pull/71/head
robin.keunen 5 years ago
parent
commit
1c70a2d40f
  1. 5
      easy_my_coop_api/controllers/controllers.py
  2. 3
      easy_my_coop_api/models/auth_api_key.py
  3. 3
      easy_my_coop_api/services/subscription_request_service.py
  4. 10
      easy_my_coop_api/tests/common.py
  5. 5
      easy_my_coop_api/tests/test_ping.py
  6. 2
      easy_my_coop_api/tests/test_registry.py
  7. 31
      easy_my_coop_api/tests/test_subscription_requests.py

5
easy_my_coop_api/controllers/controllers.py

@ -3,9 +3,10 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.addons.base_rest.controllers import main
from odoo.http import route
from odoo.addons.base_rest.controllers import main
class UserController(main.RestController):
_root_path = "/api/"
@ -20,5 +21,5 @@ class UserController(main.RestController):
)
def test(self, _service_name):
return self._process_method(
_service_name, "test", _id=None, params=None,
_service_name, "test", _id=None, params=None
)

3
easy_my_coop_api/models/auth_api_key.py

@ -27,8 +27,7 @@ class AuthApiKey(models.Model):
now = fields.Datetime.now()
key.name = "{login}-{now}".format(
now=fields.Datetime.to_string(now),
login=key.user_id.login,
now=fields.Datetime.to_string(now), login=key.user_id.login
)
else:
key.name = "no-user"

3
easy_my_coop_api/services/subscription_request_service.py

@ -21,8 +21,7 @@ _logger = logging.getLogger(__name__)
class SubscriptionRequestService(Component):
_inherit = "base.rest.service"
_name = "subscription.request.services"
# service_name todo subscription-request
_usage = "subscription_request"
_usage = "subscription-request"
_collection = "emc.services"
_description = """
Subscription requests

10
easy_my_coop_api/tests/common.py

@ -3,12 +3,14 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import requests
import json
import odoo
import requests
from lxml import html
import odoo
from odoo.fields import Date
from odoo.addons.base_rest.tests.common import BaseRestCase
HOST = "127.0.0.1"
@ -66,7 +68,7 @@ class BaseEMCRestCase(BaseRestCase):
def http_get(self, url, headers=None):
headers = _add_api_key(headers)
if url.startswith("/"):
url = "http://%s:%s%s" % (HOST, PORT, url)
url = "http://{}:{}{}".format(HOST, PORT, url)
return self.session.get(url, headers=headers)
@ -79,7 +81,7 @@ class BaseEMCRestCase(BaseRestCase):
def http_post(self, url, data, headers=None):
headers = _add_api_key(headers)
if url.startswith("/"):
url = "http://%s:%s%s" % (HOST, PORT, url)
url = "http://{}:{}{}".format(HOST, PORT, url)
return self.session.post(url, json=data, headers=headers)

5
easy_my_coop_api/tests/test_ping.py

@ -4,12 +4,13 @@
import json
import requests
from odoo.addons.base_rest.controllers.main import _PseudoCollection
from odoo.addons.component.core import WorkContext
from .common import BaseEMCRestCase, HOST, PORT
from .common import HOST, PORT, BaseEMCRestCase
class TestPing(BaseEMCRestCase):
@ -27,7 +28,7 @@ class TestPing(BaseEMCRestCase):
def test_ping_route(self):
# public route
path = "/api/ping/test"
url = "http://%s:%s%s" % (HOST, PORT, path)
url = "http://{}:{}{}".format(HOST, PORT, path)
response = requests.get(url)
self.assertEquals(response.status_code, 200)
content = json.loads(response.content.decode("utf-8"))

2
easy_my_coop_api/tests/test_registry.py

@ -4,8 +4,8 @@
import odoo
from odoo.http import controllers_per_module
from odoo.addons.base_rest.tests.common import BaseRestCase
from ..controllers.controllers import UserController

31
easy_my_coop_api/tests/test_subscription_requests.py

@ -4,8 +4,10 @@
import json
from datetime import timedelta
import odoo
from odoo.fields import Date
from odoo.addons.base_rest.controllers.main import _PseudoCollection
from odoo.addons.component.core import WorkContext
@ -20,7 +22,7 @@ class TestSRController(BaseEMCRestCase):
model_name="rest.service.registration", collection=collection
)
self.service = emc_services_env.component(usage="subscription_request")
self.service = emc_services_env.component(usage="subscription-request")
def test_service(self):
# kept as example
@ -41,23 +43,23 @@ class TestSRController(BaseEMCRestCase):
def test_route_get(self):
id_ = self.demo_request_1.id
route = "/api/subscription_request/%s" % id_
route = "/api/subscription-request/%s" % id_
content = self.http_get_content(route)
self.assertEquals(self.demo_request_1_dict, content)
@odoo.tools.mute_logger("odoo.addons.base_rest.http")
def test_route_get_returns_not_found(self):
route = "/api/subscription_request/%s" % "99999"
route = "/api/subscription-request/%s" % "99999"
response = self.http_get(route)
self.assertEquals(response.status_code, 404)
def test_route_get_string_returns_method_not_allowed(self):
route = "/api/subscription_request/%s" % "abc"
route = "/api/subscription-request/%s" % "abc"
response = self.http_get(route)
self.assertEquals(response.status_code, 405)
def test_route_search_all(self):
route = "/api/subscription_request"
route = "/api/subscription-request"
content = self.http_get_content(route)
self.assertIn(self.demo_request_1_dict, content["rows"])
@ -66,37 +68,36 @@ class TestSRController(BaseEMCRestCase):
date_from = Date.to_string(sr_date - timedelta(days=1))
date_to = Date.to_string(sr_date + timedelta(days=1))
route = "/api/subscription_request?date_from=%s" % date_from
route = "/api/subscription-request?date_from=%s" % date_from
content = self.http_get_content(route)
self.assertIn(self.demo_request_1_dict, content["rows"])
route = "/api/subscription_request?date_to=%s" % date_to
route = "/api/subscription-request?date_to=%s" % date_to
content = self.http_get_content(route)
self.assertIn(self.demo_request_1_dict, content["rows"])
route = "/api/subscription_request?date_from=%s&date_to=%s" % (
date_from,
date_to,
route = "/api/subscription-request?date_from={}&date_to={}".format(
date_from, date_to
)
content = self.http_get_content(route)
self.assertIn(self.demo_request_1_dict, content["rows"])
route = "/api/subscription_request?date_from=%s" % "2300-01-01"
route = "/api/subscription-request?date_from=%s" % "2300-01-01"
content = self.http_get_content(route)
self.assertEquals(content["count"], 0)
route = "/api/subscription_request?date_to=%s" % "1900-01-01"
route = "/api/subscription-request?date_to=%s" % "1900-01-01"
content = self.http_get_content(route)
self.assertEquals(content["count"], 0)
@odoo.tools.mute_logger("odoo.addons.base_rest.http")
def test_route_search_acd_date_returns_bad_request(self):
route = "/api/subscription_request?date_from=%s" % "20200101"
route = "/api/subscription-request?date_from=%s" % "20200101"
response = self.http_get(route)
self.assertEquals(response.status_code, 400)
def test_route_create(self):
url = "/api/subscription_request"
url = "/api/subscription-request"
data = {
"name": "Lisa des Danses",
"email": "lisa@desdanses.be",
@ -130,7 +131,7 @@ class TestSRController(BaseEMCRestCase):
self.assertEquals(expected, content)
def test_route_update(self):
url = "/api/subscription_request/%s" % self.demo_request_1.id
url = "/api/subscription-request/%s" % self.demo_request_1.id
data = {"state": "done"}
response = self.http_post(url, data=data)

Loading…
Cancel
Save