Exemplo n.º 1
0
def test_get_object_type():
    """Test get object type"""

    obj = Lugito()

    with open(FAKE_REQ_DATA, 'r') as f:
        obj.request_data = json.load(f)

    assert(obj.get_object_type() == 'DREV')
Exemplo n.º 2
0
def test_is_new_object_true():
    """Test is new task - true"""

    obj = Lugito()

    with open(FAKE_REQ_DATA, 'r') as f:
        obj.request_data = json.load(f)

    with open(FAKE_TRANSACTION_NEW_OBJECT, 'r') as f:
        obj.transaction = json.load(f)

    assert (obj.is_new_object())
Exemplo n.º 3
0
def test_is_new_object_false():
    """Test is new task - false"""

    obj = Lugito()

    with open(FAKE_REQ_DATA, 'r') as f:
        obj.request_data = json.load(f)

    with open(FAKE_TRANSACTION, 'r') as f:
        obj.transaction = json.load(f)

    assert (not obj.is_new_object())
Exemplo n.º 4
0
def test_is_edited_comment():
    """Test checking for edited comment"""

    obj = Lugito()

    with open(FAKE_REQ_EDITED_COMMENT, 'r') as f:
        obj.request_data = json.load(f)

    with open(FAKE_EDITED_COMMENT, 'r') as f:
        obj.transaction = json.load(f)

    new_comment, edited, _id = obj.is_comment()

    assert(not new_comment)
    assert(edited)
    assert(_id == 157)
Exemplo n.º 5
0
def test_is_new_comment():
    """Test checking for new  - using transaction search"""

    obj = Lugito()

    with open(FAKE_REQ_NEW_COMMENT, 'r') as f:
        obj.request_data = json.load(f)

    with open(FAKE_NEW_COMMENT, 'r') as f:
        obj.transaction = json.load(f)

    new_comment, edited, _id = obj.is_comment()

    assert(new_comment)
    assert(not edited)
    assert(_id == 133)
Exemplo n.º 6
0
def test_invalid_HMAC():
    """Test validating HMAC"""

    obj = Lugito()

    request_mock = MagicMock()

    with open(FAKE_REQ_DATA, 'r') as f:
        request_mock.data = f.read().encode()

    request_mock.headers = {
        "X-Phabricator-Webhook-Signature":
        "a8f6364464ddb398ea873ffab409d941f87396f28fa9d22bb58cfbedc9f"
    }

    assert(not obj.validate_request('diffhook', request_mock))
Exemplo n.º 7
0
def test_validate_request():
    """Test validating HMAC"""

    obj = Lugito()
    obj.phab = MagicMock()
    obj.phab.transaction.search = MagicMock()

    request_mock = MagicMock()

    with open(FAKE_REQ_DATA, 'r') as f:
        request_mock.data = f.read().encode()

    request_mock.headers = {
        "X-Phabricator-Webhook-Signature":
        "a8f636f03ed4464ddb398ea873ffab409d941f87396f28fa9d22bb58cfbedc9f"
    }

    assert(obj.validate_request('diffhook', request_mock))
    assert(obj.phab.transaction.search.is_called())
Exemplo n.º 8
0
def test_init():
    """Test initialise lugito"""

    obj = Lugito()

    assert('http://127.0.0.1:9091/api/' in obj.phab.host)
    assert('api-nojs2ip33hmp4zn6u6cf72w7d6yh' in obj.phab.token)
    assert(obj.HMAC['diffhook'] == bytes(u'vglzi6t4gsumnilv27r27no7rs3vgs75',
        'utf-8'))
    assert(obj.HMAC['commithook'] == bytes(u'znkyfflbcia5gviqx5ybad7s6uyfywxi',
        'utf-8'))
Exemplo n.º 9
0
def test_author_fullname_error():
    """Test unable to get the author name"""

    obj = Lugito()

    with open(FAKE_REQ_DATA, 'r') as f:
        obj.request_data = json.load(f)

    with open(FAKE_TRANSACTION, 'r') as f:
        obj.transaction = json.load(f)

    obj.phab = MagicMock()
    obj.phab.phid.query = MagicMock(side_effect=http.client.HTTPException)

    author_name = obj.get_author_fullname()
    assert(author_name is None)
Exemplo n.º 10
0
def test_author_fullname():
    """Test get the author name"""

    obj = Lugito()

    with open(FAKE_REQ_DATA, 'r') as f:
        obj.request_data = json.load(f)

    with open(FAKE_TRANSACTION, 'r') as f:
        obj.transaction = json.load(f)

    obj.phab = MagicMock()
    obj.phab.phid.query = MagicMock(return_value={
        'PHID-USER-5cmhaqtkggymhvbyqdcv':{
            'fullName': 'AuthorName',
            },
        }
    )

    author_name = obj.get_author_fullname()
    assert(author_name == 'AuthorName')
Exemplo n.º 11
0
.. currentmodule:: lugito.webhooks
"""

# Imports
import logging
import threading
from flask import Flask, request
from lugito import Lugito
from lugito.connectors import irc, launchpad

# Constants
GLOBAL_LOG_LEVEL = logging.DEBUG

# Instantiate Lugito and connectors
lugito = Lugito(GLOBAL_LOG_LEVEL)
WEBSITE = lugito.host.replace('/api/', '')

# Connectors
irc_con = irc()
launchpad_con = launchpad()

# Logging
logger = logging.getLogger('lugito.webhooks')

# Add log level
ch = logging.StreamHandler()

formatter = logging.Formatter(
    '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)