# Path: badwolf/utils.py
# def to_text(value, encoding='utf-8', errors='ignore'):
#     """Convert value to unicode, default encoding is utf-8
# 
#     :param value: Value to be converted
#     :param encoding: Desired encoding
#     """
#     if not value:
#         return ''
#     if isinstance(value, str):
#         return value
#     if isinstance(value, bytes):
#         return value.decode(encoding, errors)
#     return str(value)


import json
import unittest.mock as mock
from concurrent.futures import Future
from flask import url_for
from badwolf.utils import to_text
    payload = json.dumps({
        'repository': {
            'full_name': 'deepanalyzer/badwolf',
            'scm': 'git',
        },
        'pullrequest': {
            'title': 'Test PR',
            'description': '',
            'state': 'MERGED',
        },
        'source': {
            'repository': {'full_name': 'deepanalyzer/badwolf'},
            'branch': {'name': 'develop'},
            'commit': {'hash': 'abc'}
        },
        'target': {
            'repository': {'full_name': 'deepanalyzer/badwolf'},
            'branch': {'name': 'master'},
            'commit': {'hash': 'abc'}
        }
    })
    res = test_client.post(
        url_for('webhook.webhook_push'),
        data=payload,
        headers={
            'User-Agent': 'Bitbucket-Webhooks/2.0',
            'X-Event-Key': 'pullrequest:updated',
        }
    )
    assert res.status_code == 200

# Path: badwolf/utils.py
# def to_text(value, encoding='utf-8', errors='ignore'):
#     """Convert value to unicode, default encoding is utf-8
# 
#     :param value: Value to be converted
#     :param encoding: Desired encoding
#     """
#     if not value:
#         return ''
#     if isinstance(value, str):
#         return value
#     if isinstance(value, bytes):
#         return value.decode(encoding, errors)
#     return str(value)


# Path: tests/test_bitbucket_webhook_pr_created_updated.py
import json
import unittest.mock as mock
from concurrent.futures import Future
from flask import url_for
from badwolf.utils import to_text

    payload = json.dumps({
        'repository': {
            'full_name': 'deepanalyzer/badwolf',
            'scm': 'git',
        },
        'pullrequest': {
            'title': 'Test PR',
            'description': '',
            'state': 'MERGED',
        },
        'source': {
            'repository': {'full_name': 'deepanalyzer/badwolf'},
            'branch': {'name': 'develop'},
            'commit': {'hash': 'abc'}
        },
        'target': {
            'repository': {'full_name': 'deepanalyzer/badwolf'},
            'branch': {'name': 'master'},
            'commit': {'hash': 'abc'}
        }
    })
    res = test_client.post(
        url_for('webhook.webhook_push'),
        data=payload,
        headers={
            'User-Agent': 'Bitbucket-Webhooks/2.0',
            'X-Event-Key': 'pullrequest:updated',
        }
    )
    assert res.status_code == 200

    assert to_text(res.data) == ''