Projet

Général

Profil

0001-tests-merge-intervention_id-occurences-57875.patch

Nicolas Roche, 02 novembre 2021 13:15

Télécharger (5,87 ko)

Voir les différences:

Subject: [PATCH 1/5] tests: merge intervention_id occurences (#57875)

 .../data/toulouse_smart/get_intervention.json | 54 -------------------
 tests/test_toulouse_smart.py                  | 18 ++++---
 2 files changed, 10 insertions(+), 62 deletions(-)
 delete mode 100644 tests/data/toulouse_smart/get_intervention.json
tests/data/toulouse_smart/get_intervention.json
1
{
2
  "id": "3f0558bd-7d85-49a8-97e4-d07bc7f8dc9b",
3
  "name": "DI-20210731-0103",
4
  "description": "Justice nul part",
5
  "geom": {
6
    "type": "Point",
7
    "coordinates": [
8
      2.1431744096480547,
9
      48.69856386916798
10
    ],
11
    "crs": "EPSG:3943"
12
  },
13
  "interventionData": {},
14
  "safeguardRequired": false,
15
  "media": null,
16
  "safeguardDone": null,
17
  "interventionCreated": "2021-07-30T22:44:38.748Z",
18
  "interventionDesired": "2021-07-31T00:40:03Z",
19
  "interventionDone": null,
20
  "submitter": {
21
    "id": null,
22
    "lastName": "",
23
    "firstName": "admin",
24
    "mail": "admin@localhost",
25
    "furtherInformation": null,
26
    "phoneNumber": "0699999999",
27
    "address": ""
28
  },
29
  "submitterType": "usager",
30
  "organizations": [
31
    {
32
      "id": "f1378d8a-12bf-4c14-913f-22624b0ecab8",
33
      "name": "Direction des P\u00f4les"
34
    },
35
    {
36
      "id": "8ad4af63-70b5-416f-a75d-c510d83ce1bd",
37
      "name": "Transport Logistique"
38
    }
39
  ],
40
  "domain": null,
41
  "state": {
42
    "id": "e844e67f-5382-4c0f-94d8-56f618263485",
43
    "table": null,
44
    "stateLabel": "Nouveau",
45
    "closes": false
46
  },
47
  "interventionTypeId": "407ef8d6-9b8c-4187-be51-d89f24424768",
48
  "onPrivateLand": false,
49
  "duplicates": null,
50
  "external_number": "36-10",
51
  "external_status": "statut 1",
52
  "cityId": "12345",
53
  "address": "https://wcs.dev.publik.love/backoffice/management/smart/10/"
54
}
tests/test_toulouse_smart.py
222 222
      </validation>
223 223
    </field>
224 224
  </fields>
225 225
</block>
226 226
'''
227 227
            )
228 228

  
229 229

  
230
INTERVENTION_ID = json.loads(get_json_file('create_intervention'))['id']
231

  
232

  
230 233
@mock_response(
231
    ['/v1/intervention', None, get_json_file('get_intervention')],
234
    ['/v1/intervention', None, get_json_file('create_intervention')],
232 235
)
233 236
def test_get_intervention(app, smart):
234
    resp = app.get(URL + 'get-intervention?id=3f0558bd-7d85-49a8-97e4-d07bc7f8dc9b')
237
    resp = app.get(URL + 'get-intervention?id=%s' % INTERVENTION_ID)
235 238
    assert not resp.json['err']
236
    assert resp.json['data']['id'] == '3f0558bd-7d85-49a8-97e4-d07bc7f8dc9b'
239
    assert resp.json['data']['id'] == INTERVENTION_ID
237 240
    assert resp.json['data']['state'] == {
238 241
        'id': 'e844e67f-5382-4c0f-94d8-56f618263485',
239 242
        'table': None,
240 243
        'stateLabel': 'Nouveau',
241 244
        'closes': False,
242 245
    }
243 246

  
244 247

  
245 248
@mock_response(
246 249
    ['/v1/intervention', None, None, 500],
247 250
)
248 251
def test_get_intervention_error_status(app, smart):
249
    resp = app.get(URL + 'get-intervention?id=3f0558bd-7d85-49a8-97e4-d07bc7f8dc9b')
252
    resp = app.get(URL + 'get-intervention?id=%s' % INTERVENTION_ID)
250 253
    assert resp.json['err']
251 254
    assert 'failed to get' in resp.json['err_desc']
252 255

  
253 256

  
254 257
@mock_response(
255 258
    ['/v1/intervention', None, None, 404],
256 259
)
257 260
def test_get_intervention_wrond_id(app, smart):
258
    resp = app.get(URL + 'get-intervention?id=3f0558bd-7d85-49a8-97e4-d07bc7f8dc9b')
261
    resp = app.get(URL + 'get-intervention?id=%s' % INTERVENTION_ID)
259 262
    assert resp.json['err']
260 263
    assert 'failed to get' in resp.json['err_desc']
261 264
    assert '404' in resp.json['err_desc']
262 265

  
263 266

  
264 267
CREATE_INTERVENTION_PAYLOAD_EXTRA = {
265 268
    'slug': 'coin',
266 269
    'description': 'coin coin',
......
672 675
    [
673 676
        '/api/forms/foo/2/hooks/update_intervention/',
674 677
        UPDATE_INTERVENTION_QUERY_ON_ASYNC_CREATION,
675 678
        WCS_RESPONSE_SUCCESS,
676 679
    ],
677 680
)
678 681
@mock.patch("django.db.models.fields.UUIDField.get_default", return_value=UUID)
679 682
def test_create_intervention_async(mocked_uuid4, app, smart, wcs_service):
680
    smart_id = json.loads(get_json_file('create_intervention'))['id']
681 683
    mocked_wcs_request_push = mock.patch(
682 684
        "passerelle.contrib.toulouse_smart.models.WcsRequest.push",
683 685
        return_value=False,
684 686
    )
685 687
    mocked_smart_request_push = mock.patch(
686 688
        "passerelle.contrib.toulouse_smart.models.SmartRequest.push",
687 689
        return_value=False,
688 690
    )
......
710 712
    # smart is up
711 713
    mocked_wcs_request_push.stop()
712 714
    smart.jobs()
713 715
    assert Job.objects.count() == 2
714 716

  
715 717
    job = Job.objects.get(method_name='create_intervention_job')
716 718
    assert job.status == 'completed'
717 719
    wcs_request = smart.wcs_requests.get(uuid=UUID)
718
    assert wcs_request.result['id'] == smart_id
720
    assert wcs_request.result['id'] == INTERVENTION_ID
719 721
    assert wcs_request.status == 'sent'
720 722

  
721 723
    job = Job.objects.get(method_name='update_intervention_job')
722 724
    assert job.status == 'registered'
723 725

  
724 726
    # wcs is up
725 727
    mocked_smart_request_push.stop()
726 728
    smart.jobs()
727 729

  
728 730
    job = Job.objects.get(method_name='update_intervention_job')
729 731
    assert job.status == 'completed'
730 732
    smart_request = wcs_request.smart_requests.get()
731 733
    assert smart_request.payload['creation_response']['uuid'] == str(UUID)
732
    assert smart_request.payload['creation_response']['result']['id'] == smart_id
734
    assert smart_request.payload['creation_response']['result']['id'] == INTERVENTION_ID
733
-