Skip to content
Snippets Groups Projects
Commit 1356e850 authored by Daniel Palomar's avatar Daniel Palomar
Browse files

Add message to check_sponsor method in Partner resource

parent 2a37ffc9
No related branches found
No related tags found
1 merge request!32Add check_sponsor method to Partner resource
Pipeline #4837 passed
......@@ -95,9 +95,7 @@ class Partner:
)
if not response_data:
raise ResourceNotFound(resource=cls.__name__, filter=params)
if response_data["result"] == "allowed":
return True
return False
return response_data["result"] == "allowed", response_data["message"]
@classmethod
def _get(cls, id=None, params={}):
......
interactions:
- request:
body: null
headers:
API-KEY:
- DUMMY
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.27.1
method: GET
uri: http://odoo-sc.local:8069/api/partner/check_sponsor?vat=ES62308540E&sponsor_code=ry12u
response:
body:
string: '{"result": "not_allowed", "message": "maximum number of sponsees exceeded"}'
headers:
Content-Length:
- '38'
Content-Type:
- application/json
Date:
- Wed, 20 Apr 2022 08:50:41 GMT
Server:
- Werkzeug/0.11.15 Python/3.7.7
Set-Cookie:
- session_id=e4b4f7d9ae6e1ae1fcb67f6840bc96a8eed715f4; Expires=Tue, 19-Jul-2022
08:50:41 GMT; Max-Age=7776000; HttpOnly; Path=/
status:
code: 200
message: OK
version: 1
......@@ -13,22 +13,22 @@ interactions:
User-Agent:
- python-requests/2.27.1
method: GET
uri: http://odoo-sc.local:8069/api/partner/check_sponsor?vat=ES11673039X&sponsor_code=e75rc
uri: http://odoo-sc.local:8069/api/partner/check_sponsor?vat=ES11673039X&sponsor_code=abc12
response:
body:
string: '{"result": "not_allowed"}'
string: '{"result": "not_allowed", "message": "invalid code or vat number"}'
headers:
Content-Length:
- '25'
- '66'
Content-Type:
- application/json
Date:
- Mon, 11 Apr 2022 16:07:55 GMT
- Wed, 20 Apr 2022 08:50:41 GMT
Server:
- Werkzeug/0.11.15 Python/3.7.7
Set-Cookie:
- session_id=20c68ab430c8537aa79eb887f400d898a3c9aafc; Expires=Sun, 10-Jul-2022
16:07:55 GMT; Max-Age=7776000; HttpOnly; Path=/
- session_id=30eb767887dce773eaebbd493ba4d36cb7b150d7; Expires=Tue, 19-Jul-2022
08:50:41 GMT; Max-Age=7776000; HttpOnly; Path=/
status:
code: 200
message: OK
......
......@@ -16,7 +16,7 @@ interactions:
uri: http://odoo-sc.local:8069/api/partner/check_sponsor?vat=ES76230724F&sponsor_code=cac3c
response:
body:
string: '{"result": "allowed"}'
string: '{"result": "allowed", "message": "ok"}'
headers:
Content-Length:
- '21'
......
......@@ -42,14 +42,25 @@ class PartnerTests(unittest.TestCase):
def test_check_sponsor_ok(self):
sponsor_code = "cac3c"
vat = "ES76230724F"
result = Partner.check_sponsor(vat, sponsor_code)
result, message = Partner.check_sponsor(vat, sponsor_code)
assert result
assert message == "ok"
@pytest.mark.vcr()
def test_check_sponsor_ko(self):
sponsor_code = "e75rc"
def test_check_sponsor_ko_maximum_exceeded(self):
sponsor_code = "ry12u"
vat = "ES62308540E"
result, message = Partner.check_sponsor(vat, sponsor_code)
assert not result
assert message == "maximum number of sponsees exceeded"
@pytest.mark.vcr()
def test_check_sponsor_ko_wrong_code(self):
sponsor_code = "abc12"
vat = "ES11673039X"
result = Partner.check_sponsor(vat, sponsor_code)
result, message = Partner.check_sponsor(vat, sponsor_code)
assert not result
assert message == "invalid code or vat number"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment