def accept_licence(dataset_id):
    session = dps_session.get_state()
    try:
        ulapd_api = UlapdAPI()
        user_details = session['user']['user_details']

        send_metric(dataset_id, 'licence agreed', user_details['user_details_id'], user_details, None)

        data = {
            'user_details_id': user_details['user_details_id'],
            'licence_id': dataset_id
        }

        ulapd_api.create_licence_agreement(data)

    except Exception as e:
        raise ApplicationError('Error accepting licence: {}'.format(str(e)))
    def test_create_licence_agreement(self, mock_post):
        data = {"user_details_id": 1, "licence_id": "ccod"}
        mock_post.return_value.json.return_value = data
        mock_post.return_value.status_code = 201

        ulapd_api = UlapdAPI()
        response = ulapd_api.create_licence_agreement(data)

        self.assertEqual(response, data)
        args, kwargs = mock_post.call_args_list[0]
        self.assertEqual(kwargs['data'], json.dumps(data))