Ejemplo n.º 1
0
def test_get_slack_users_no_users(monkeypatch):
    class SlackUsersMock:
        def __init__(*args, **kwargs):
            return

        def json(self):
            return {'ok': True, 'members': []}

    monkeypatch.setattr(requests, 'get', SlackUsersMock)
    assert isinstance(controller.get_slack_users(), HTTPResponse)
    assert controller.get_slack_users().status == 200
    data = json.loads(controller.get_slack_users().body)
    assert data == {'data': [], 'ok': True}
Ejemplo n.º 2
0
def test_get_slack_users_slack_api_error(monkeypatch):
    class SlackUsersMock:
        def __init__(*args, **kwargs):
            return

        def json(self):
            return {'ok': False, 'members': []}

    monkeypatch.setattr(requests, 'get', SlackUsersMock)
    assert isinstance(controller.get_slack_users(), HTTPResponse)
    assert controller.get_slack_users().status == 504
    data = json.loads(controller.get_slack_users().body)
    assert data == {'message': 'Slack API error', 'ok': False}
Ejemplo n.º 3
0
def test_get_slack_users_filters_deleted_and_blacklisted(monkeypatch):
    class SlackUsersMock:
        def __init__(*args, **kwargs):
            return

        def json(self):
            return {
                'ok':
                True,
                'members': [{
                    'deleted': True,
                    'name': 'snax',
                    'profile': {
                        'real_name_normalized': 'Hot Dog',
                        'image_192': 'https://fakeurl.coolbeans'
                    }
                }, {
                    'deleted': False,
                    'name': 'testuser',
                    'profile': {
                        'real_name_normalized': 'Will BeFiltered',
                        'image_192': 'https://fakeurl.coolbeans'
                    }
                }, {
                    'deleted': False,
                    'name': 'real_user',
                    'profile': {
                        'real_name_normalized': 'Bloop Bloop',
                        'image_192': 'https://fakeurl.coolbeans'
                    }
                }]
            }

    monkeypatch.setattr(requests, 'get', SlackUsersMock)
    assert isinstance(controller.get_slack_users(), HTTPResponse)
    assert controller.get_slack_users().status == 200
    data = json.loads(controller.get_slack_users().body)
    assert data == {
        'data': [{
            'username': '******',
            'realname': 'Bloop Bloop',
            'avatar': 'https://fakeurl.coolbeans',
        }],
        'ok':
        True
    }
Ejemplo n.º 4
0
def test_add_user(monkeypatch):
    class SlackUsersMock:
        def __init__(*args, **kwargs):
            return

        def json(self):
            return {
                'ok':
                True,
                'members': [{
                    'deleted': False,
                    'name': 'snax',
                    'profile': {
                        'real_name_normalized': 'Hot Dog',
                        'image_192': 'https://fakeurl.coolbeans'
                    }
                }, {
                    'deleted': False,
                    'name': 'fail',
                    'profile': {
                        'real_name_normalized': 'I should throw',
                        'image_192': 'https://fakeurl.coolbeans'
                    }
                }]
            }

    monkeypatch.setattr(requests, 'get', SlackUsersMock)
    response = controller.get_slack_users()
    assert isinstance(response, HTTPResponse)
    assert response.status == 200

    mockRequest = {"username": "******", "password": "******"}
    noSlackResult = json.loads(controller.add_user(mockRequest, None).body)
    assert noSlackResult["ok"] == False
    assert noSlackResult["message"] == "No Slack user four-o-four"

    mockRequest = {"username": "******", "password": "******"}
    someSlackResult = json.loads(
        controller.add_user(mockRequest, mocks.MockAdderDatabase()).body)
    assert someSlackResult["ok"]
    assert someSlackResult["data"] == "Successfully added User snax"

    mockRequest = {"username": "******", "password": "******"}
    failSlackResult = json.loads(
        controller.add_user(mockRequest, mocks.MockAdderDatabase()).body)
    assert failSlackResult["ok"] == False
Ejemplo n.º 5
0
async def slack_users(request):
    return controller.get_slack_users(request)