|
28 | 28 | from requests import exceptions |
29 | 29 |
|
30 | 30 | from business_model.models import Amalgamation, Batch, Business, Filing, RegistrationBootstrap |
31 | | -from legal_api.services.authz import ACCOUNT_IDENTITY, PUBLIC_USER, STAFF_ROLE, SYSTEM_ROLE |
| 31 | +from legal_api.services.authz import ( |
| 32 | + ACCOUNT_IDENTITY, |
| 33 | + COLIN_SVC_ROLE, |
| 34 | + CONTACT_CENTRE_STAFF_ROLE, |
| 35 | + MAXIMUS_STAFF_ROLE, |
| 36 | + PUBLIC_USER, |
| 37 | + SBC_STAFF_ROLE, |
| 38 | + STAFF_ROLE, |
| 39 | + SYSTEM_ROLE, |
| 40 | +) |
32 | 41 | from legal_api.services import flags |
33 | 42 | from legal_api.services.cache import cache |
34 | 43 | from legal_api.services.bootstrap import RegistrationBootstrapService |
@@ -243,6 +252,40 @@ def test_get_business_info(app, session, client, jwt, requests_mock, test_name, |
243 | 252 | assert registry_schemas.validate(rv.json, 'business') |
244 | 253 |
|
245 | 254 |
|
| 255 | +@pytest.mark.parametrize('role,expected_staff', [ |
| 256 | + (STAFF_ROLE, True), |
| 257 | + (SYSTEM_ROLE, True), |
| 258 | + (COLIN_SVC_ROLE, True), |
| 259 | + (SBC_STAFF_ROLE, True), |
| 260 | + (CONTACT_CENTRE_STAFF_ROLE, True), |
| 261 | + (MAXIMUS_STAFF_ROLE, True), |
| 262 | + (PUBLIC_USER, False), |
| 263 | +]) |
| 264 | +def test_get_business_info_passes_staff_status_to_warnings( |
| 265 | + app, session, client, jwt, role, expected_staff, monkeypatch, requests_mock): |
| 266 | + """Assert that business warnings receive the correct staff status for each role.""" |
| 267 | + identifier = 'BC7654321' |
| 268 | + factory_business_model(legal_name=f'{identifier} legal name', |
| 269 | + identifier=identifier, |
| 270 | + founding_date=datetime.fromtimestamp(0, UTC), |
| 271 | + last_ledger_timestamp=datetime.fromtimestamp(0, UTC), |
| 272 | + last_modified=datetime.fromtimestamp(0, UTC)) |
| 273 | + warning_staff_values = [] |
| 274 | + monkeypatch.setattr( |
| 275 | + 'legal_api.resources.v2.business.business.check_warnings', |
| 276 | + lambda business, is_staff: warning_staff_values.append(is_staff) or [] |
| 277 | + ) |
| 278 | + if role == PUBLIC_USER: |
| 279 | + requests_mock.get(f"{app.config['AUTH_SVC_URL']}/entities/{identifier}/authorizations", |
| 280 | + json={'roles': ['view']}) |
| 281 | + |
| 282 | + rv = client.get(f'/api/v2/businesses/{identifier}', |
| 283 | + headers=create_header(jwt, [role], identifier)) |
| 284 | + |
| 285 | + assert rv.status_code == HTTPStatus.OK |
| 286 | + assert warning_staff_values == [expected_staff] |
| 287 | + |
| 288 | + |
246 | 289 | @pytest.mark.parametrize('test_name,role,amalgamated', [ |
247 | 290 | ('regular', PUBLIC_USER, False), |
248 | 291 | ('amalgamated', PUBLIC_USER, True), |
|
0 commit comments