def test_update_subscription_to_uas_zones_updates__is_updated__returns_ok_200( mock_sm_client, test_client, test_user): uas_zones_subscription = make_uas_zones_subscription(user=test_user) uas_zones_subscription.save() sm_subscription = Mock() sm_subscription.id = uas_zones_subscription.sm_subscription.id mock_sm_client.get_subscription_by_id = Mock(return_value=sm_subscription) mock_sm_client.put_subscription = Mock() data = {"active": not uas_zones_subscription.sm_subscription.active} response = test_client.put(URL + uas_zones_subscription.id, data=json.dumps(data), content_type='application/json', headers=make_basic_auth_header( test_user.username, DEFAULT_LOGIN_PASS)) assert 200 == response.status_code response_data = json.loads(response.data) assert "OK" == response_data['genericReply']['RequestStatus'] updated_subscription = UASZonesSubscription.objects.get( id=uas_zones_subscription.id) assert updated_subscription.sm_subscription.active == \ (not uas_zones_subscription.sm_subscription.active) mock_sm_client.put_subscription.assert_called_once_with( sm_subscription.id, data)
def test_create_uas_zone__valid_input__object_is_saved__returns_ok__201( test_client, test_user, uas_zone_input): uas_zone = make_uas_zone(BASILIQUE_POLYGON) # saving the expected uas_zone at this point contradicts a bit the nature of this test but here # we are actually testing the event outcome uas_zone.save() context = UASZoneContext(uas_zone=uas_zone, user=test_user) with mock.patch('geofencing_service.events.events.create_uas_zone_event.handle', return_value=context) as mock_event: response = test_client.post(URL_UAS_ZONES, data=json.dumps(uas_zone_input), content_type='application/json', headers=make_basic_auth_header(test_user.username, DEFAULT_LOGIN_PASS)) response_data = json.loads(response.data) assert 201 == response.status_code assert "OK" == response_data['genericReply']['RequestStatus'] assert context.uas_zone in UASZone.objects.all() assert uas_zone_input['identifier'] == \ mock_event.call_args[1]['context'].uas_zone.identifier
def test_get_uas_zones__invalid_polygon_input__returns_nok__400( test_client, test_user, horizontal_projection, expected_exception_description): data = { "airspaceVolume": { "lowerLimit": 0, "lowerVerticalReference": "AMSL", "horizontalProjection": horizontal_projection, "upperLimit": 0, "upperVerticalReference": "AMSL" }, "endDateTime": "2019-11-05T13:10:39.315Z", "regions": [ 0 ], "startDateTime": "2019-11-05T13:10:39.315Z" } response = test_client.post( URL_UAS_ZONES_FILTER, data=json.dumps(data), content_type='application/json', headers=make_basic_auth_header(test_user.username, DEFAULT_LOGIN_PASS) ) assert 400 == response.status_code response_data = json.loads(response.data) assert "NOK" == response_data['genericReply']['RequestStatus'] assert expected_exception_description == \ response_data['genericReply']["RequestExceptionDescription"]
def test_get_uas_zones__valid_input__returns_ok_and_empty_uas_zone_list__200(test_client, test_user): data = { "airspaceVolume": { "lowerLimit": 0, "lowerVerticalReference": "AMSL", "horizontalProjection": { "type": "Polygon", "coordinates": [[ [1.0, 2.0], [3.0, 4.0], [5.0, 6.0], [1.0, 2.0] ]] }, "upperLimit": 0, "upperVerticalReference": "AMSL" }, "endDateTime": "2019-11-05T13:10:39.315Z", "regions": [ 0 ], "startDateTime": "2019-11-05T13:10:39.315Z" } response = test_client.post(URL_UAS_ZONES_FILTER, data=json.dumps(data), content_type='application/json', headers=make_basic_auth_header(test_user.username, DEFAULT_LOGIN_PASS)) assert 200 == response.status_code response_data = json.loads(response.data) assert "OK" == response_data['genericReply']['RequestStatus'] assert [] == response_data['UASZoneList']
def test_get_subscriptions_to_uas_zones_updates__no_subscription_exists__returns_empty_list_200( test_client, test_user): response = test_client.get(URL, headers=make_basic_auth_header( test_user.username, DEFAULT_LOGIN_PASS)) assert 200 == response.status_code response_data = json.loads(response.data) assert [] == response_data['subscriptions']
def test_delete_uas_zone___invalid_user__returns_nok__401(test_client): response = test_client.delete(URL_UAS_ZONES + 'identifier', headers=make_basic_auth_header('fake_username', 'fake_password')) assert 401 == response.status_code response_data = json.loads(response.data) assert "NOK" == response_data['genericReply']['RequestStatus'] assert "Invalid credentials" == response_data['genericReply']["RequestExceptionDescription"]
def test_delete_uas_zone___valid_identifier__uas_zone_is_deleted__returns_ok__204( test_client, test_user, db_uas_zone_basilique): response = test_client.delete(URL_UAS_ZONES + db_uas_zone_basilique.identifier, headers=make_basic_auth_header(test_user.username, DEFAULT_LOGIN_PASS)) assert 204 == response.status_code assert get_uas_zones_by_identifier(db_uas_zone_basilique.identifier) is None
def test_delete_uas_zone___invalid_identifier__returns_nok__404(test_client, test_user): response = test_client.delete(URL_UAS_ZONES + 'invalid_identifier', headers=make_basic_auth_header(test_user.username, DEFAULT_LOGIN_PASS)) assert 404 == response.status_code response_data = json.loads(response.data) assert "NOK" == response_data['genericReply']['RequestStatus'] assert "UASZone with identifier 'invalid_identifier' does not exist" == \ response_data['genericReply']["RequestExceptionDescription"]
def test_get_subscription_to_uas_zones_updates__invalid_subscription_id__returns_nok_404( test_client, test_user): response = test_client.get(URL + 'invalid_subscription_id', headers=make_basic_auth_header( test_user.username, DEFAULT_LOGIN_PASS)) assert 404 == response.status_code response_data = json.loads(response.data) assert "NOK" == response_data['genericReply']['RequestStatus'] assert "Subscription with id invalid_subscription_id does not exist" == \ response_data['genericReply']["RequestExceptionDescription"]
def test_create_subscription_to_uas_zones_updates__invalid_user__returns_nok_401( test_client): response = test_client.post(URL, headers=make_basic_auth_header( 'fake_username', 'fake_password')) assert 401 == response.status_code response_data = json.loads(response.data) assert "NOK" == response_data['genericReply']['RequestStatus'] assert "Invalid credentials" == response_data['genericReply'][ "RequestExceptionDescription"]
def test_update_subscription_to_uas_zones_updates__invalid_data__returns_nok_400( test_client, test_user, invalid_data): uas_zones_subscription = make_uas_zones_subscription(user=test_user) uas_zones_subscription.save() response = test_client.put(URL + uas_zones_subscription.id, data=json.dumps(invalid_data), content_type='application/json', headers=make_basic_auth_header( test_user.username, DEFAULT_LOGIN_PASS)) assert 400 == response.status_code response_data = json.loads(response.data) assert "NOK" == response_data['genericReply']['RequestStatus']
def _post_uas_zones_filter(test_client, test_user, filter_data) -> Tuple[Dict[str, Any], int]: if isinstance(filter_data, UASZonesFilter): filter_data = UASZonesFilterSchema().dumps(filter_data) else: filter_data = json.dumps(filter_data) response = test_client.post(URL_UAS_ZONES_FILTER, data=filter_data, content_type='application/json', headers=make_basic_auth_header(test_user.username, DEFAULT_LOGIN_PASS)) return json.loads(response.data), response.status_code
def test_create_uas_zone__invalid_identifier_length__returns_nok__400( test_client, test_user, uas_zone_input, invalid_identifier, expected_message ): uas_zone_input['identifier'] = invalid_identifier response = test_client.post(URL_UAS_ZONES, data=json.dumps(uas_zone_input), content_type='application/json', headers=make_basic_auth_header(test_user.username, DEFAULT_LOGIN_PASS)) response_data = json.loads(response.data) assert 400 == response.status_code assert "NOK" == response_data['genericReply']['RequestStatus'] assert expected_message == response_data['genericReply']['RequestExceptionDescription']
def test_get_subscription_to_uas_zones_updates__returns_subscription_data_200( test_client, test_user): uas_zones_subscription = make_uas_zones_subscription(user=test_user) uas_zones_subscription.save() response = test_client.get(URL + uas_zones_subscription.id, headers=make_basic_auth_header( test_user.username, DEFAULT_LOGIN_PASS)) assert 200 == response.status_code response_data = json.loads(response.data)['subscription'] assert response_data['subscriptionID'] == uas_zones_subscription.id assert response_data[ 'publicationLocation'] == uas_zones_subscription.sm_subscription.queue assert response_data[ 'active'] == uas_zones_subscription.sm_subscription.active assert 'UASZonesFilter' in response_data
def test_delete_subscription_to_uas_zones_updates__is_deleted__returns_ok_204( mock_sm_client, test_client, test_user): mock_sm_client.delete_subscription_by_id = Mock() uas_zones_subscription = make_uas_zones_subscription(user=test_user) uas_zones_subscription.save() response = test_client.delete(URL + uas_zones_subscription.id, headers=make_basic_auth_header( test_user.username, DEFAULT_LOGIN_PASS)) assert 204 == response.status_code with pytest.raises(DoesNotExist): UASZonesSubscription.objects.get(id=uas_zones_subscription.id) mock_sm_client.delete_subscription_by_id.assert_called_once_with( uas_zones_subscription.sm_subscription.id)
def test_create_uas_zone__invalid_airspace_volume__not_enough_points__returns_nok__400( test_client, test_user, uas_zone_input, horizontal_projection, expected_exception_description): uas_zone_input['geometry'][0]['horizontalProjection'] = horizontal_projection response = test_client.post(URL_UAS_ZONES, data=json.dumps(uas_zone_input), content_type='application/json', headers=make_basic_auth_header(test_user.username, DEFAULT_LOGIN_PASS)) response_data = json.loads(response.data) assert 400 == response.status_code assert "NOK" == response_data['genericReply']['RequestStatus'] assert expected_exception_description == \ response_data['genericReply']['RequestExceptionDescription']
def test_create_subscription_to_uas_zones_updates__valid_input__returns_ok_and_creates_subscription__200( test_client, test_user): data = { "airspaceVolume": { "lowerLimit": 0, "lowerVerticalReference": "AMSL", "horizontalProjection": { "type": "Polygon", "coordinates": [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0], [1.0, 2.0]]] }, "upperLimit": 0, "upperVerticalReference": "AMSL" }, "endDateTime": "2019-11-05T13:10:39.315Z", "regions": [0], "startDateTime": "2019-11-05T13:10:39.315Z" } context = UASZonesSubscriptionCreateContext( uas_zones_filter=UASZonesFilterSchema().load(data), user=test_user) context.uas_zones_subscription = make_uas_zones_subscription() with mock.patch( 'geofencing_service.events.events.create_uas_zones_subscription_event.handle', return_value=context): response = test_client.post(URL, data=json.dumps(data), content_type='application/json', headers=make_basic_auth_header( test_user.username, DEFAULT_LOGIN_PASS)) assert 201 == response.status_code response_data = json.loads(response.data) assert "OK" == response_data['genericReply']['RequestStatus'] assert context.uas_zones_subscription.id == response_data[ 'subscriptionID'] assert context.uas_zones_subscription.sm_subscription.queue == \ response_data['publicationLocation']
def test_create_uas_zone(test_client, test_user): uas_zone_input = """{ "geometry": [{ "uomDimensions": "M", "lowerLimit": 0, "lowerVerticalReference": "AMSL", "horizontalProjection": { "type": "Polygon", "coordinates": [[ [50.846889, 4.333428], [50.848857, 4.342644], [50.851817, 4.338588], [50.846889, 4.333428] ]] }, "upperLimit": 100, "upperVerticalReference": "AMSL" }], "applicability": { "schedule": [ { "day": "MON", "endTime": "18:00:00+00:00", "startTime": "09:00:00+00:00" } ], "endDateTime": "2020-02-14T10:16:33.532Z", "permanent": "YES", "startDateTime": "2020-01-14T10:16:33.532Z" }, "zoneAuthority": { "contactName": "string", "email": "*****@*****.**", "name": "string", "phone": "string", "service": "string", "siteURL": "https://www.authority.com", "purpose": "AUTHORIZATION", "intervalBefore": "P3Y" }, "country": "BEL", "regulationExemption": "YES", "extendedProperties": {}, "identifier": "4rf04r0", "message": "string", "name": "string", "reason": [ "AIR_TRAFFIC" ], "region": 1, "restriction": "PROHIBITED", "restrictionConditions": [ "string" ], "type": "COMMON", "uSpaceClass": "EUROCONTROL" }""" response = test_client.post(URL_UAS_ZONES, data=uas_zone_input, content_type='application/json', headers=make_basic_auth_header(test_user.username, DEFAULT_LOGIN_PASS)) response_data = json.loads(response.data) assert response.status_code == 201