def test_timestamp(self, client_alice, unsigned_telemetry_different_hardware, current_datetime): telemetry_copy = deepcopy(self.unsigned_telemetry) telemetry_copy['timestamp'] = (current_datetime + timedelta(days=1)).isoformat().replace('+00:00', 'Z') add_telemetry_data_to_model([telemetry_copy], self.shipment_alice_with_device) valid_timestamp = (current_datetime + timedelta(hours=12)).isoformat().replace('+00:00', 'Z') invalid_before_timestamp = (current_datetime + timedelta(hours=18)).isoformat().replace('+00:00', 'Z') invalid_after_timestamp = (current_datetime + timedelta(hours=6)).isoformat().replace('+00:00', 'Z') response = client_alice.get(f'{self.telemetry_url}?before=NOT A TIMESTAMP') AssertionHelper.HTTP_400(response) assert response.json()['before'] == ['Enter a valid date/time.'] response = client_alice.get(f'{self.telemetry_url}?before={valid_timestamp}') self.unsigned_telemetry.pop('version') AssertionHelper.HTTP_200(response, is_list=True, vnd=False, attributes=self.unsigned_telemetry, count=1) response = client_alice.get(f'{self.telemetry_url}?after={valid_timestamp}') telemetry_copy.pop('version') AssertionHelper.HTTP_200(response, is_list=True, vnd=False, attributes=telemetry_copy, count=1) response = client_alice.get(f'{self.telemetry_url}?before={valid_timestamp}&after={invalid_after_timestamp}') assert response.status_code == status.HTTP_400_BAD_REQUEST assert response.json()[0] == \ f'Invalid timemismatch applied. Before timestamp {valid_timestamp} is greater than after: {invalid_after_timestamp}' response = client_alice.get(f'{self.telemetry_url}?after={valid_timestamp}&before={invalid_before_timestamp}') assert response.status_code == status.HTTP_400_BAD_REQUEST assert response.json()[0] == \ f'Invalid timemismatch applied. Before timestamp {invalid_before_timestamp} is greater than after: {valid_timestamp}'
def test_wallet_owner_retrieval(client_bob, api_client, shipment_tracking_data, modified_http_pretty, profiles_ids, profiles_wallet_list_assertions): modified_http_pretty.register_uri(modified_http_pretty.GET, f"{settings.PROFILES_URL}/api/v1/wallet", body=json.dumps({'data': []}), status=status.HTTP_200_OK) url = reverse('shipment-overview', kwargs={'version': 'v1'}) response = client_bob.get(url) AssertionHelper.HTTP_200(response, vnd=True, is_list=True, count=1) modified_http_pretty.assert_calls(profiles_wallet_list_assertions) modified_http_pretty.register_uri( modified_http_pretty.GET, f"{settings.PROFILES_URL}/api/v1/wallet", body=json.dumps({ 'data': [ { 'id': profiles_ids['carrier_wallet_id'] }, { 'id': profiles_ids['shipper_wallet_id'] }, ] }), status=status.HTTP_200_OK) response = client_bob.get(url) AssertionHelper.HTTP_200(response, vnd=True, is_list=True, count=len(shipment_tracking_data)) assert len(response.json()['included']) == NUM_DEVICES - 1 modified_http_pretty.assert_calls(profiles_wallet_list_assertions)
def test_shipment_udate_customer_fields(self, client_alice): response = client_alice.patch(self.update_url, data={ 'customer_fields': { 'custom_field_1': 'value one', 'custom_field_2': 'value two' } }) AssertionHelper.HTTP_202(response) response = client_alice.get(self.history_url) AssertionHelper.HTTP_200(response, is_list=True, count=3) changed_fields = self.get_changed_fields( response.json()['data'][0]['fields'], 'field') assert 'customer_fields.custom_field_1' in changed_fields assert 'customer_fields.custom_field_2' in changed_fields response = client_alice.patch( self.update_url, data={'customer_fields': { 'custom_field_2': 'new value two' }}) AssertionHelper.HTTP_202(response) response = client_alice.get(self.history_url) AssertionHelper.HTTP_200(response, is_list=True, count=4) changed_fields = self.get_changed_fields( response.json()['data'][0]['fields'], 'field') assert 'customer_fields.custom_field_1' not in changed_fields assert 'customer_fields.custom_field_2' in changed_fields
def test_history_documents(self, client_alice): document = Document.objects.create(name='Test Historical', owner_id=self.shipment.owner_id, shipment=self.shipment) response = client_alice.get(self.history_url) AssertionHelper.HTTP_200(response, is_list=True, count=2) # A document in upload_status pending shouldn't be present in the shipment diff history assert response.json()['data'][0]['relationships'] is None # A document with upload_status complete should be present in the shipment history document.upload_status = 1 document.save() response = client_alice.get(self.history_url) AssertionHelper.HTTP_200(response, is_list=True, count=3) history_documents = response.json()['data'][0]['relationships'].get( 'documents') assert history_documents assert 'upload_status' in self.get_changed_fields( history_documents['fields'], 'field') # Any subsequent document object update should be present in the diff change document.description = 'Document updated with some description for example' document.save() response = client_alice.get(self.history_url) AssertionHelper.HTTP_200(response, is_list=True, count=4) history_documents = response.json()['data'][0]['relationships'].get( 'documents') assert history_documents assert 'description' in self.get_changed_fields( history_documents['fields'], 'field')
def test_aggregate_success(self, client_alice, unsigned_telemetry_different_sensor): response = client_alice.get( f'{self.telemetry_url}?aggregate={Aggregates.average.name}&per={TimeTrunc.minutes.name}') AssertionHelper.HTTP_200(response, is_list=True, vnd=False, attributes={ 'value': self.unsigned_telemetry['value'] }) assert len(response.json()) == 1 self.unsigned_telemetry['value'] = 20 add_telemetry_data_to_model([self.unsigned_telemetry], self.shipment_alice_with_device) response = client_alice.get( f'{self.telemetry_url}?aggregate={Aggregates.average.name}&per={TimeTrunc.minutes.name}') self.unsigned_telemetry['value'] = 15 AssertionHelper.HTTP_200(response, is_list=True, vnd=False, attributes={ 'value': self.unsigned_telemetry['value'] }) assert len(response.json()) == 1 response = client_alice.get( f'{self.telemetry_url}?aggregate={Aggregates.minimum.name}&per={TimeTrunc.minutes.name}') AssertionHelper.HTTP_200(response, is_list=True, vnd=False, attributes={ 'value': 10 }) assert len(response.json()) == 1 response = client_alice.get( f'{self.telemetry_url}?aggregate={Aggregates.maximum.name}&per={TimeTrunc.minutes.name}') self.unsigned_telemetry['value'] = 20 AssertionHelper.HTTP_200(response, is_list=True, vnd=False, attributes={ 'value': self.unsigned_telemetry['value'] }) assert len(response.json()) == 1
def test_shipment_not_included(self, client_bob, new_access_request_bob): response = client_bob.get(self.list_url) AssertionHelper.HTTP_200(response, is_list=True, count=1) assert 'included' not in response.json() response = client_bob.get(self.shipment_list_url) AssertionHelper.HTTP_200(response, is_list=True, count=1) assert 'included' not in response.json()
def test_per_shipment_return(self, client_alice, entity_ref_document_shipment_alice, entity_ref_document_shipment_alice_two, entity_ref_document_shipment_two_alice): response = client_alice.get(self.shipment_alice_url) AssertionHelper.HTTP_200(response, is_list=True, entity_refs=[entity_ref_document_shipment_alice, entity_ref_document_shipment_alice_two], count=2) response = client_alice.get(self.shipment_alice_two_url) AssertionHelper.HTTP_200(response, entity_refs=[entity_ref_document_shipment_two_alice], count=1, is_list=True)
def test_ordering(self, client_alice, entity_ref_document_shipment_alice, entity_ref_document_shipment_alice_two): response = client_alice.get(f'{self.shipment_alice_url}?ordering=-created_at') AssertionHelper.HTTP_200(response, is_list=True, entity_refs=[entity_ref_document_shipment_alice_two, entity_ref_document_shipment_alice], check_ordering=True) response = client_alice.get(f'{self.shipment_alice_url}?ordering=-modified_at') AssertionHelper.HTTP_200(response, is_list=True, entity_refs=[entity_ref_document_shipment_alice_two, entity_ref_document_shipment_alice], check_ordering=True)
def test_meta_field_list_and_overview(self, shipment_alice, client_bob, approved_access_request_bob, shipment_bob, devices, overview_tracking_data): response = client_bob.get(self.shipment_list) AssertionHelper.HTTP_200( response, is_list=True, entity_refs=[ AssertionHelper.EntityRef( resource='Shipment', pk=shipment_alice.id, meta={'permission_derivation': 'AccessRequest'}), AssertionHelper.EntityRef(resource='Shipment', pk=shipment_bob.id, meta={ 'permission_derivation': 'OwnerOrPartyOrPermissionLink' }) ]) # Add devices and tracking to shipments so they show up in the overview self.setup_devices_and_tracking(shipment_alice, devices[0], overview_tracking_data[0]) self.setup_devices_and_tracking(shipment_bob, devices[1], overview_tracking_data[0]) response = client_bob.get(self.shipment_overview) AssertionHelper.HTTP_200( response, is_list=True, entity_refs=[ AssertionHelper.EntityRef( resource='TrackingData', relationships=[{ 'shipment': AssertionHelper.EntityRef( resource='Shipment', pk=shipment_alice.id, meta={'permission_derivation': 'AccessRequest'}) }]), AssertionHelper.EntityRef( resource='TrackingData', relationships=[{ 'shipment': AssertionHelper.EntityRef( resource='Shipment', pk=shipment_bob.id, meta={ 'permission_derivation': 'OwnerOrPartyOrPermissionLink' }) }]) ])
def test_update_upload_status(self, client_alice, entity_ref_document_shipment_alice, mock_s3_buckets, mocker): response = client_alice.patch(self.document_alice_url, {'upload_status': UploadStatus.FAILED.name}) entity_ref_document_shipment_alice.attributes['upload_status'] = UploadStatus.FAILED.name AssertionHelper.HTTP_200(response, entity_ref_document_shipment_alice) assert isinstance(response.json()['data']['meta']['presigned_s3'], dict) mocker.patch('apps.documents.rpc.DocumentRPCClient.put_document_in_s3', return_value={'success': True}) response = client_alice.patch(self.document_alice_url, {'upload_status': UploadStatus.COMPLETE.name}) entity_ref_document_shipment_alice.attributes['description'] = UploadStatus.COMPLETE.name AssertionHelper.HTTP_200(response, entity_ref_document_shipment_alice) assert isinstance(response.json()['data']['meta']['presigned_s3'], str) assert isinstance(response.json()['data']['meta']['presigned_s3_thumbnail'], str)
def test_authenticated_can_update(self, client_alice, client_bob, client_carol, entity_ref_document_shipment_alice, mock_successful_wallet_owner_calls, successful_wallet_owner_calls_assertions): response = client_alice.patch(self.document_alice_url, {'description': 'New Description'}) entity_ref_document_shipment_alice.attributes['description'] = 'New Description' AssertionHelper.HTTP_200(response, entity_ref_document_shipment_alice) response = client_bob.patch(self.document_alice_url, {'description': 'Bob Description'}) entity_ref_document_shipment_alice.attributes['description'] = 'Bob Description' AssertionHelper.HTTP_200(response, entity_ref_document_shipment_alice) mock_successful_wallet_owner_calls.assert_calls(successful_wallet_owner_calls_assertions) response = client_carol.patch(self.document_alice_url, {'description': 'Carol Description'}) entity_ref_document_shipment_alice.attributes['description'] = 'Carol Description' AssertionHelper.HTTP_200(response, entity_ref_document_shipment_alice)
def test_filter(self, client_alice, entity_ref_document_shipment_alice, entity_ref_document_shipment_alice_two): response = client_alice.get(f'{self.shipment_alice_url}?file_type={entity_ref_document_shipment_alice.attributes["file_type"]}') AssertionHelper.HTTP_200(response, is_list=True, entity_refs=[entity_ref_document_shipment_alice], count=1) response = client_alice.get(f'{self.shipment_alice_url}?document_type={entity_ref_document_shipment_alice_two.attributes["document_type"]}') AssertionHelper.HTTP_200(response, is_list=True, entity_refs=[entity_ref_document_shipment_alice_two], count=1) response = client_alice.get(f'{self.shipment_alice_url}?upload_status={entity_ref_document_shipment_alice_two.attributes["upload_status"]}') AssertionHelper.HTTP_200(response, is_list=True, entity_refs=[entity_ref_document_shipment_alice_two], count=1)
def test_list_search_filter(client_alice, shipper_api_client, api_client, shipment, mocked_is_shipper, shipment_notes, successful_wallet_owner_calls_assertions, shipper_user): url = reverse('shipment-notes-list', kwargs={'version': 'v1', 'shipment_pk': shipment.id}) # An unauthenticated user cannot list a shipment notes response = api_client.get(url) AssertionHelper.HTTP_403(response) # A shipment owner can list all notes associated response = client_alice.get(url) AssertionHelper.HTTP_200(response, is_list=True, count=len(shipment_notes) - 1) # A shipper can list only the notes associated to the relative shipment response = shipper_api_client.get(url) AssertionHelper.HTTP_200(response, is_list=True, count=len(shipment_notes) - 1) mocked_is_shipper.assert_calls(successful_wallet_owner_calls_assertions) # There is only one note authored by the shipper response = client_alice.get(f'{url}?user_id={shipper_user.id}') AssertionHelper.HTTP_200(response, is_list=True, entity_refs=[AssertionHelper.EntityRef(resource='ShipmentNote', attributes={ 'message': shipment_notes[2].message, 'user_id': shipment_notes[2].user_id, 'username': shipment_notes[2].username}, relationships={ 'shipment': AssertionHelper.EntityRef( resource='Shipment', pk=shipment.id)})], count=1 ) # There is only one note containing the word "ShipChain" response = client_alice.get(f'{url}?search=shipchain') AssertionHelper.HTTP_200(response, is_list=True, entity_refs=[AssertionHelper.EntityRef(resource='ShipmentNote', attributes={ 'message': shipment_notes[1].message, 'user_id': shipment_notes[1].user_id, 'username': shipment_notes[1].username}, relationships={ 'shipment': AssertionHelper.EntityRef( resource='Shipment', pk=shipment.id)})], count=1 )
def test_pickup_with_gtx_required(client_alice, shipment): assert shipment.pickup_act is None shipment.gtx_required = True shipment.save() url = reverse('shipment-actions', kwargs={ 'version': 'v1', 'shipment_pk': shipment.id }) action = {'action_type': ActionType.PICK_UP.name} # If gtx_required, pickup requires an asset_physical_id response = client_alice.post(url, data=action) AssertionHelper.HTTP_403( response, error= 'In order to proceed with this shipment pick up, you need to provide a ' 'value for the field [Shipment.asset_physical_id]') action['asset_physical_id'] = 'nfc_tag' response = client_alice.post(url, data=action) AssertionHelper.HTTP_200( response, entity_refs=AssertionHelper.EntityRef( resource='Shipment', pk=shipment.id, attributes={'state': TransitState.IN_TRANSIT.name}))
def test_route_telemetry_retrieval(self, client_alice, route_with_device_alice, shipment_alice): route_with_device_alice.routeleg_set.create(shipment=shipment_alice) add_telemetry_data_to_model([self.unsigned_telemetry], route_with_device_alice) # Shipment awaiting pickup should show no telemetry response = client_alice.get(self.empty_telemetry_url) assert response.status_code == status.HTTP_200_OK assert len(response.json()) == 0 shipment_alice.pick_up(action_timestamp=(datetime.utcnow() - timedelta(days=3)).isoformat()) shipment_alice.save() cache.clear() # Shipment picked up prior to telemetry data should include that data response = client_alice.get(self.empty_telemetry_url) self.unsigned_telemetry.pop('version') AssertionHelper.HTTP_200(response, is_list=True, vnd=False, attributes=self.unsigned_telemetry, count=1) shipment_alice.arrival(action_timestamp=(datetime.utcnow() - timedelta(days=2)).isoformat()) shipment_alice.save() shipment_alice.drop_off(action_timestamp=(datetime.utcnow() - timedelta(days=1)).isoformat()) shipment_alice.save() cache.clear() # Shipment dropped off prior to telemetry data should not include that data response = client_alice.get(self.empty_telemetry_url) assert response.status_code == status.HTTP_200_OK assert len(response.json()) == 0
def test_with_device_available_on_route(self, client_alice, route_attributes, new_route_with_device): route_attributes['device_id'] = new_route_with_device.device.id with mock.patch('apps.shipments.models.Device.get_or_create_with_permission') as mock_device: mock_device.return_value = new_route_with_device.device response = client_alice.patch(self.url_route, route_attributes) AssertionHelper.HTTP_200( response, entity_refs=AssertionHelper.EntityRef( resource='Route', attributes={ 'name': route_attributes['name'], 'driver_id': route_attributes['driver_id'], }, relationships={ 'device': AssertionHelper.EntityRef( resource='Device', pk=route_attributes['device_id'] ), } ), included=AssertionHelper.EntityRef( resource='Device', pk=route_attributes['device_id'] ), )
def test_filter_hardware_id(self, client_alice, unsigned_telemetry_different_hardware): add_telemetry_data_to_model([unsigned_telemetry_different_hardware], self.shipment_alice_with_device) response = client_alice.get(f'{self.telemetry_url}?hardware_id={self.unsigned_telemetry["hardware_id"]}') self.unsigned_telemetry.pop('version') AssertionHelper.HTTP_200(response, is_list=True, vnd=False, attributes=self.unsigned_telemetry, count=1) assert self.unsigned_telemetry['hardware_id'] != unsigned_telemetry_different_hardware['hardware_id']
def test_owner_can_list(self, client_alice): response = client_alice.get(self.list_url) AssertionHelper.HTTP_200(response, entity_refs=self.entity_refs, is_list=True, count=PermissionLink.objects.filter( shipment=self.shipment_alice).count())
def test_pickup(client_alice, shipment): assert shipment.pickup_act is None url = reverse('shipment-actions', kwargs={ 'version': 'v1', 'shipment_pk': shipment.id }) action = {'action_type': ActionType.PICK_UP.name} response = client_alice.post(url, data=action) AssertionHelper.HTTP_200( response, entity_refs=AssertionHelper.EntityRef( resource='Shipment', pk=shipment.id, attributes={'state': TransitState.IN_TRANSIT.name})) updated_parameters = response.json()['data']['attributes'] assert datetimeAlmostEqual(dt_parse(updated_parameters['pickup_act'])) # Can't pickup when IN_TRANSIT response = client_alice.post(url, data=action) AssertionHelper.HTTP_400( response, error= 'Action PICK_UP not available while Shipment is in state IN_TRANSIT', pointer='action_type')
def test_includes_legs(self, client_alice, new_route, shipment_alice_with_device, shipment): leg1 = new_route.routeleg_set.create(shipment=shipment) leg2 = new_route.routeleg_set.create(shipment=shipment_alice_with_device) leg1_entity = AssertionHelper.EntityRef(resource='RouteLeg', pk=leg1.pk, attributes={'shipment_id': shipment.pk}) leg2_entity = AssertionHelper.EntityRef(resource='RouteLeg', pk=leg2.pk, attributes={'shipment_id': shipment_alice_with_device.pk}) response = client_alice.get(self.url_route) AssertionHelper.HTTP_200( response, entity_refs=AssertionHelper.EntityRef( resource='Route', pk=new_route.id, attributes={ 'name': new_route.name, 'driver_id': new_route.driver_id, }, relationships={ 'legs': [leg1_entity, leg2_entity] }, ), included=[leg1_entity, leg2_entity] )
def test_tags_hidden_from_overview(self, shipment_alice, client_bob, new_rw_access_request_bob, devices, overview_tracking_data): new_rw_access_request_bob.tags_permission = PermissionLevel.NONE new_rw_access_request_bob.approved = True new_rw_access_request_bob.save() self.setup_devices_and_tracking(shipment_alice, devices[0], overview_tracking_data[0]) response = client_bob.get(self.shipment_overview) AssertionHelper.HTTP_200(response, is_list=True, entity_refs=[ AssertionHelper.EntityRef( resource='TrackingData', relationships=[{ 'shipment': AssertionHelper.EntityRef( resource='Shipment', pk=shipment_alice.id) }]), ]) response_json = response.json() for included in response_json['included']: assert included['type'] != 'ShipmentTag'
def test_wallet_owner_access_expired_link( self, client_bob, mock_successful_wallet_owner_calls, profiles_ids): response = client_bob.get(self.url_expired_permission) AssertionHelper.HTTP_200(response, entity_refs=self.entity_ref_shipment_alice) mock_successful_wallet_owner_calls.assert_calls( self.successful_wallet_owner_calls_assertions)
def test_filter_sensor(self, client_alice, unsigned_telemetry_different_sensor): add_telemetry_data_to_model([unsigned_telemetry_different_sensor], self.shipment_alice_with_device) response = client_alice.get(f'{self.telemetry_url}?sensor_id={self.unsigned_telemetry["sensor_id"]}') self.unsigned_telemetry.pop('version') AssertionHelper.HTTP_200(response, is_list=True, vnd=False, attributes=self.unsigned_telemetry) assert len(response.json()) == 1 assert self.unsigned_telemetry['sensor_id'] != unsigned_telemetry_different_sensor['sensor_id']
def test_meta_field_presence(self, shipment_alice, client_bob, approved_access_request_bob): response = client_bob.get(self.shipment_detail) AssertionHelper.HTTP_200( response, entity_refs=AssertionHelper.EntityRef( resource='Shipment', pk=shipment_alice.id, meta={'permission_derivation': 'AccessRequest'}))
def test_list_depends_on_shipment(self, client_alice): response = client_alice.get(self.list_url_two) AssertionHelper.HTTP_200(response, entity_refs=[], is_list=True, count=PermissionLink.objects.filter( shipment=self.shipment_alice_two).count()) assert PermissionLink.objects.filter( shipment=self.shipment_alice).count() == 2
def test_get_requester_list(self, client_bob, client_lionel, entity_ref_access_request_bob): response = client_bob.get(self.list_url) AssertionHelper.HTTP_200(response, is_list=True, entity_refs=[entity_ref_access_request_bob], count=1) response = client_bob.get(self.shipment_list_url) AssertionHelper.HTTP_200(response, is_list=True, entity_refs=[entity_ref_access_request_bob], count=1) response = client_lionel.get(self.list_url) AssertionHelper.HTTP_200(response, is_list=True, count=0) response = client_lionel.get(self.shipment_list_url) AssertionHelper.HTTP_200(response, is_list=True, count=0)
def test_history_filtering(self, client_alice): initial_datetime = datetime.now() one_day_later = datetime.now() + timedelta(days=1) two_day_later = datetime.now() + timedelta(days=2) # We update the shipment 1 day in the future with freeze_time(one_day_later.isoformat()) as date_in_future: response = client_alice.patch(self.update_url, {'container_qty': '1'}) AssertionHelper.HTTP_202(response) # We set the clock to two days in the future date_in_future.move_to(two_day_later) response = client_alice.patch(self.update_url, {'package_qty': '10'}) AssertionHelper.HTTP_202(response) response = client_alice.get(self.history_url) AssertionHelper.HTTP_200(response, is_list=True, count=4) assert 'package_qty' in self.get_changed_fields( response.json()['data'][0]['fields'], 'field') response = client_alice.get( f'{self.history_url}?history_date__lte={initial_datetime.isoformat()}' ) AssertionHelper.HTTP_200(response, is_list=True, count=2) assert 'package_qty' not in self.get_changed_fields( response.json()['data'][0]['fields'], 'field') response = client_alice.get( f'{self.history_url}?history_date__gte={initial_datetime.isoformat()}' ) AssertionHelper.HTTP_200(response, is_list=True, count=2) assert 'package_qty' in self.get_changed_fields( response.json()['data'][0]['fields'], 'field') assert 'container_qty' in self.get_changed_fields( response.json()['data'][1]['fields'], 'field') response = client_alice.get(f'{self.history_url}?history_date__lte={one_day_later.isoformat()}' \ f'&history_date__gte={datetime.now().isoformat()}') AssertionHelper.HTTP_200(response, is_list=True, count=1) assert 'container_qty' in self.get_changed_fields( response.json()['data'][0]['fields'], 'field')
def test_shipment_udate_location(self, client_alice): location_attributes, content_type = create_form_content({ 'ship_from_location.name': "Location Name", 'ship_from_location.city': "City", 'ship_from_location.state': "State", 'ship_from_location.geometry': geojson.dumps(Point((42.0, 27.0))) }) response = client_alice.patch(self.update_url, data=location_attributes, content_type=content_type) AssertionHelper.HTTP_202(response) response = client_alice.get(self.history_url) AssertionHelper.HTTP_200(response, is_list=True, count=3) changed_fields = self.get_changed_fields( response.json()['data'][0]['fields'], 'field') assert 'ship_from_location' in changed_fields assert 'geometry' not in self.get_changed_fields( response.json()['data'][0]['relationships']['ship_from_location'], 'field') assert 'ship_from_location' in response.json( )['data'][0]['relationships'].keys() location_attributes, content_type = create_form_content( {'ship_from_location.phone_number': '555-555-5555'}) response = client_alice.patch(self.update_url, data=location_attributes, content_type=content_type) AssertionHelper.HTTP_202(response) response = client_alice.get(self.history_url) AssertionHelper.HTTP_200(response, is_list=True, count=4) ship_from_location_changes = response.json( )['data'][0]['relationships']['ship_from_location'] assert 'phone_number' in self.get_changed_fields( ship_from_location_changes, 'field')
def test_approval_log(self, client_alice, new_access_request_bob, access_request_ro_attributes, user_alice_id, frozen_time): response = client_alice.patch(self.detail_url, { 'approved': True, **access_request_ro_attributes }) AssertionHelper.HTTP_200(response, attributes={ 'approved_by': user_alice_id, 'approved_at': f'{frozen_time().isoformat()}Z' }) response = client_alice.patch(self.detail_url, {'approved': False}) AssertionHelper.HTTP_200(response, attributes={ 'approved_by': None, 'approved_at': None })
def test_wallet_owner_can_list(self, client_bob, mock_successful_wallet_owner_calls, successful_wallet_owner_calls_assertions): response = client_bob.get(self.list_url) AssertionHelper.HTTP_200(response, entity_refs=self.entity_refs, is_list=True, count=PermissionLink.objects.filter( shipment=self.shipment_alice).count()) mock_successful_wallet_owner_calls.assert_calls( successful_wallet_owner_calls_assertions)