Exemplo n.º 1
0
def test_get_invites_filter():
    """
    Test that get invites with filter does apply the right params
    """
    _test_email = '*****@*****.**'
    _test_note = 'test note'
    _test_team = 'team 1'

    class TestMockClient(BaseMockClass):
        def _plans_api_license_v1_test_invites_invites(self, params, headers):
            if params['email'] == _test_email and \
                params['note'] == _test_note and \
                    params['teamId'] == _test_team:
                return json.dumps({
                    'data': [{
                        "id": "bc30c000-dddd-11e6-80c5-46f6aaaaaaaa",
                        "email": _test_email,
                        "teamId": None,
                        "note": "Professional Services",
                        "sendDate": "2017-01-04T00:00:00+00:00",
                        "expiresOn": "2017-02-18T00:00:00+00:00"
                    }]
                })

    client = LicensingAPIClient(TEST_PLAN, TEST_API_KEY)

    with mock_session_with_class(client.session, TestMockClient,
                                 'https://app.pluralsight.com'):
        invites = client.invites.get_invites(email=_test_email,
                                             note=_test_note,
                                             team_id=_test_team)
        assert len(invites) == 1
Exemplo n.º 2
0
def test_delete_user():
    """
    Test that users can be deleted
    """
    client = LicensingAPIClient('test_user', TEST_API_KEY)
    special_adapter = Adapter('tests/fixtures')
    client.session.mount('https://app.pluralsight.com', special_adapter)
    client.users.delete_user("3d4a29f7-aedc-46b8-bada-f84d04f98679")
Exemplo n.º 3
0
def test_cancel_invite():
    """
    Test that invites can be updated
    """
    client = LicensingAPIClient('test_invite', TEST_API_KEY)
    special_adapter = Adapter('tests/fixtures')
    client.session.mount('https://app.pluralsight.com', special_adapter)
    client.invites.cancel_invite("bc30c000-eeee-11e6-8088-111111111111")
Exemplo n.º 4
0
def test_get_user():
    """
    Test that you can fetch a single user
    """
    client = LicensingAPIClient('test_user', TEST_API_KEY)

    special_adapter = Adapter('tests/fixtures')
    client.session.mount('https://app.pluralsight.com', special_adapter)
    user = client.users.get_user("3d4a29f7-aedc-46b8-bada-f84d04f98679")
    assert user.id == "3d4a29f7-aedc-46b8-bada-f84d04f98679"
Exemplo n.º 5
0
def test_get_team():
    """
    Test that you can fetch a single team
    """
    client = LicensingAPIClient('test_team', TEST_API_KEY)

    special_adapter = Adapter('tests/fixtures')
    client.session.mount('https://app.pluralsight.com', special_adapter)
    team = client.teams.get_team("2b947975-482a-4791-aa40-e199b3ca8738")
    assert team.id == "2b947975-482a-4791-aa40-e199b3ca8738"
    assert team.name == 'FED'
Exemplo n.º 6
0
def test_update_user():
    """
    Test that users can be updated
    """
    client = LicensingAPIClient('test_user', TEST_API_KEY)
    special_adapter = Adapter('tests/fixtures')
    client.session.mount('https://app.pluralsight.com', special_adapter)

    client.users.update_user(id="3d4a29f7-aedc-46b8-bada-f84d04f98679",
                             team_id="1234512-aedc-46b8-bada-f84d04f98679",
                             note="test note")
    assert True
Exemplo n.º 7
0
def test_get_all_teams():
    """
    Test that get all invites returns properly formatted models
    """
    client = LicensingAPIClient(TEST_PLAN, TEST_API_KEY)
    special_adapter = Adapter('tests/fixtures')
    client.session.mount('https://app.pluralsight.com', special_adapter)
    teams = client.teams.get_all_teams()
    assert len(teams) == 2
    assert teams[0].id == '2b947975-482a-4791-aa40-e199b3ca8738'
    assert teams[0].name == 'FED'
    assert str(teams[0]) == "Team 'FED' (2b947975-482a-4791-aa40-e199b3ca8738)"
Exemplo n.º 8
0
def test_create_invite():
    """
    Test that invites can be issued
    """
    client = LicensingAPIClient('test_create_invite', TEST_API_KEY)
    special_adapter = Adapter('tests/fixtures')
    client.session.mount('https://app.pluralsight.com', special_adapter)

    invite = client.invites.invite_user('*****@*****.**', None, "test note")
    assert invite.id == "bc30c000-eeee-11e6-8088-111111111111"
    assert invite.email == '*****@*****.**'
    assert invite.team_id is None
    assert invite.note == 'Services'
    assert invite.send_date.timestamp == 1483488000
    assert invite.expires_on.timestamp == 1487376000
Exemplo n.º 9
0
def test_get_invite():
    """
    Test that get all invites returns properly formatted models
    """
    client = LicensingAPIClient('test_invite', TEST_API_KEY)

    special_adapter = Adapter('tests/fixtures')
    client.session.mount('https://app.pluralsight.com', special_adapter)
    invite = client.invites.get_invite("bc30c000-eeee-11e6-8088-111111111111")
    assert invite.id == "bc30c000-eeee-11e6-8088-111111111111"
    assert invite.email == '*****@*****.**'
    assert invite.team_id is None
    assert invite.note == 'Services'
    assert invite.send_date.timestamp == 1483488000
    assert invite.expires_on.timestamp == 1487376000
Exemplo n.º 10
0
def test_get_users_filter():
    """
    Test that get users with filter does apply the right params
    """
    _first_name = 'fred'
    _last_name = 'flintstone'
    _email = '*****@*****.**'
    _note = 'yabba dabba doo'
    _team_id = '2b947975-482a-4791-aa40-e199b3ca8738'

    class TestMockClient(BaseMockClass):
        def _plans_api_license_v1_test_users_users(self, params, headers):
            assert params['firstName'] == _first_name
            assert params['lastName'] == _last_name
            assert params['email'] == _email
            assert params['note'] == _note
            assert params['teamId'] == _team_id

            return json.dumps({
                'data': [{
                    "id": "0bbdccac-dad1-4488-a69d-2ea78bf43280",
                    "teamId": "2b947975-482a-4791-aa40-e199b3ca8738",
                    "firstName": "first-25",
                    "lastName": "last-25",
                    "email": "*****@*****.**",
                    "note": "test note",
                    "startDate": "2016-05-12T02:31:07.233+00:00"
                }]
            })

    client = LicensingAPIClient(TEST_PLAN, TEST_API_KEY)

    with mock_session_with_class(client.session, TestMockClient,
                                 'https://app.pluralsight.com'):
        users = client.users.get_all_users(first_name=_first_name,
                                           last_name=_last_name,
                                           email=_email,
                                           note=_note,
                                           team_id=_team_id)
        assert len(users) == 1
        assert users[0].id == "0bbdccac-dad1-4488-a69d-2ea78bf43280"
        assert users[0].team_id == "2b947975-482a-4791-aa40-e199b3ca8738"
        assert users[0].first_name == "first-25"
        assert users[0].last_name == "last-25"
        assert users[0].email == "*****@*****.**"
        assert users[0].note == 'test note'
        assert users[0].start_date.timestamp == 1463020267
Exemplo n.º 11
0
def test_get_all_users():
    """
    Test that get all users returns properly formatted models
    """
    client = LicensingAPIClient(TEST_PLAN, TEST_API_KEY)
    special_adapter = Adapter('tests/fixtures')
    client.session.mount('https://app.pluralsight.com', special_adapter)
    users = client.users.get_all_users()
    assert len(users) == 2
    assert users[0].id == "0bbdccac-dad1-4488-a69d-2ea78bf43280"
    assert users[0].team_id == "2b947975-482a-4791-aa40-e199b3ca8738"
    assert users[0].first_name == "first-25"
    assert users[0].last_name == "last-25"
    assert users[0].email == "*****@*****.**"
    assert users[0].note == 'test note'
    assert users[0].start_date.timestamp == 1463020267
    assert str(users[0]) == "User 'first-25 last-25' [email protected] " \
        "(0bbdccac-dad1-4488-a69d-2ea78bf43280)"
Exemplo n.º 12
0
def test_get_all_invites():
    """
    Test that get all invites returns properly formatted models
    """
    client = LicensingAPIClient(TEST_PLAN, TEST_API_KEY)
    special_adapter = Adapter('tests/fixtures')
    client.session.mount('https://app.pluralsight.com', special_adapter)
    invites = client.invites.get_all_invites()
    assert len(invites) == 2
    assert invites[0].id == "bc30c000-eeee-11e6-8088-111111111111"
    assert invites[0].email == '*****@*****.**'
    assert invites[0].team_id is None
    assert invites[0].note == 'Services'
    assert invites[0].send_date.timestamp == 1483488000
    assert invites[0].expires_on.timestamp == 1487376000
    assert str(invites[0]) == "Invite to [email protected] (Services) " \
        "with ID: bc30c000-eeee-11e6-8088-111111111111"
    assert 'https://app.pluralsight.com/' in invites[0].generate_url('test')
Exemplo n.º 13
0
def test_get_teams_filter():
    """
    Test that get invites with filter does apply the right params
    """

    class TestMockClient(BaseMockClass):
        def _plans_api_license_v1_test_teams_teams(self, params, headers):
            if params['name'] == 'test':
                return json.dumps({'data': [{
                    "id": '2b947975-482a-4791-aa40-e199b3ca8738',
                    "name": 'test'
                  }]})

    client = LicensingAPIClient(TEST_PLAN, TEST_API_KEY)

    with mock_session_with_class(client.session, TestMockClient,
                                 'https://app.pluralsight.com'):
        teams = client.teams.get_all_teams(name='test')
        assert len(teams) == 1
        assert teams[0].name == 'test'
                request=request,
                body=b('bad request'),
                status_code=500)

    def _plans_api_license_v1_plana_delete(self, method):
        return json.dumps({'good': method == 'DELETE'})

    def _plans_api_license_v1_plana_delete_bad(self, request, method):
        if method == 'DELETE':
            return StaticResponseFactory.BadResponse(
                request=request,
                body=b('bad request'),
                status_code=500)


client = LicensingAPIClient(TEST_PLAN, TEST_API_KEY)


def test_base_url():
    assert TEST_PLAN in client.base_url


def test_headers():
    with mock_session_with_class(client.session, TestMockClient, TEST_URL):
        response = client.get('headers')
        assert response['good']


def test_get_request():
    with mock_session_with_class(client.session, TestMockClient, TEST_URL):
        response = client.get('get')