def test_update_dataset_access_no_update(self):
        case_id = 999
        staff_id = 'cs999pb'

        # this is mocking the data that would come from calling verification_api.get_user_dataset_access()
        current_access = [{
            'name': 'nps',
            'licences': {
                'nps': {
                    'agreed': True
                },
                'nps_sample': {
                    'agreed': True
                }
            }
        }]

        # Updated access is flask's request.form which is an ImmutableMultiDict data structure with .getlist method
        updated_access = ImmutableMultiDict([('nps', 'nps'),
                                             ('nps', 'nps_sample')])

        verification_api = VerificationAPI()
        verification_api._request = MagicMock()

        result = verification_api.update_dataset_access(
            case_id, staff_id, current_access, updated_access)

        # If nothing to update should return empty dict() and don't call verification-api
        self.assertEqual(result, {})
        verification_api._request.assert_not_called()
    def test_update_dataset_access(self):
        case_id = 999
        staff_id = 'cs999pb'

        # this is mocking the data that would come from calling verification_api.get_user_dataset_access()
        current_access = [{
            'name': 'nps',
            'licences': {
                'nps': {
                    'agreed': True
                },
                'nps_sample': {
                    'agreed': False
                }
            }
        }]

        # Updated access is flask's request.form which is an ImmutableMultiDict data structure with .getlist method
        updated_access = ImmutableMultiDict([('nps', 'nps_sample')])

        verification_api = VerificationAPI()
        verification_api._request = MagicMock()

        verification_api.update_dataset_access(case_id, staff_id,
                                               current_access, updated_access)

        expected_data = {
            'staff_id':
            staff_id,
            'licences': [{
                'licence_id': 'nps',
                'agreed': False
            }, {
                'licence_id': 'nps_sample',
                'agreed': True
            }]
        }

        # There is logic in update_dataset_access to create an array of licences with true/false agreed states
        # Ensure that the HTTP _request method is being called with correct data based on this logic
        verification_api._request.assert_called_with(
            uri='case/999/update_dataset_access'.format(case_id),
            data=json.dumps(expected_data))