예제 #1
0
def test_delete_gathering_path():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.gatherings.remove_path(
            "3578d16a-381a-4041-a6bb-1b3957fc8e94",
            "9dbd1b62-2d6e-414a-9e4c-253d17693f09",
        )
        assert response is None
예제 #2
0
def test_add_gathering_content():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.gatherings.add_content(
            "3578d16a-381a-4041-a6bb-1b3957fc8e94",
            "9dbd1b62-2d6e-414a-9e4c-253d17693f09",
        )
        assert response["gathering_recommendations_count"] == 1
예제 #3
0
def test_get_gathering_paths():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.gatherings.paths(
            "3578d16a-381a-4041-a6bb-1b3957fc8e94")
        assert response[0].user.first_name == "Anthony"
        assert response[0].path.name == "Pathgather for L&D Managers"
        assert response[0].path.user_started_count == 16
예제 #4
0
def test_create_gathering():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.gatherings.create("Learn to Code")
        assert response.id == "3578d16a-381a-4041-a6bb-1b3957fc8e94"
        assert response.name == "Learn to Code"
        assert response.user.first_name == "Anthony"
        assert response.skills[0].name == "Python"
예제 #5
0
def test_add_gathering_content():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.gatherings.add_content(
            "3578d16a-381a-4041-a6bb-1b3957fc8e94",
            "9dbd1b62-2d6e-414a-9e4c-253d17693f09",
        )
        assert response['user']['job_title'] == "CTO"
예제 #6
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
예제 #7
0
def test_create_path_comment():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.paths.create_comment(TEST_PATH_ID,
                                               "<p>hello from robot</p>",
                                               TEST_USER_ID)
        assert response.message == "<p>hello from robot</p>"
        assert response.user.first_name == "Anthony"
        assert response.path.name == "Improving your public speaking skills"
예제 #8
0
def test_get_gathering_content():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.gatherings.content(
            "3578d16a-381a-4041-a6bb-1b3957fc8e94")
        assert response[0].user.first_name == "Anthony"
        assert response[0].course.name == "The Hour of Code is here"
        assert response[0].course.reviews_count == 0
        assert response[0].course.sharer.first_name == "Anthony"
예제 #9
0
def test_add_gathering_user():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.gatherings.invite_user(
            "3578d16a-381a-4041-a6bb-1b3957fc8e94",
            "9dbd1b62-2d6e-414a-9e4c-253d17693f09",
        )
        assert response.inviter.first_name == "Anthony"
        assert response.invitee.first_name == "Lee"
예제 #10
0
def test_get_gathering_users():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.gatherings.users(
            "3578d16a-381a-4041-a6bb-1b3957fc8e94")
        assert response[
            0].gathering.id == "3578d16a-381a-4041-a6bb-1b3957fc8e94"
        assert response[0].gathering.name == "Learn to Code"
        assert response[0].user.first_name == "Anthony"
예제 #11
0
def observer():
    session = requests.Session()
    with requests_staticmock.mock_session_with_class(session, MockNumericApi,
                                                     config.BASE_URL):
        try:
            os.remove(config.LOG_FILE)
        except:
            pass
        yield ParticularObserver(session=session, name="Pytest observer")
예제 #12
0
def test_get_bad_request():
    class TestMockClient(BaseMockClass):
        def _plans_api_reports_v1_users_test_plan(self, request, method):
            return StaticResponseFactory.BadResponse(request=request,
                                                     body=b('bad request'),
                                                     status_code=500)

    with mock_session_with_class(client.session, TestMockClient, TEST_URL):
        with pytest.raises(PluralsightApiException):
            client.download_user_report(TEST_PLAN, '')
def test_class_context_manager_404_response():
    class_session = Session()

    class TestMockClass(BaseMockClass):
        def _test_json(self, request):
            return 'never'

    with mock_session_with_class(class_session, TestMockClass,
                                 'http://test.com'):
        response1 = class_session.get('http://test.com/banana.json')
    assert response1.status_code == 404
예제 #14
0
def test_create_content_comment():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.content.create_comment(
            TEST_CONTENT_ID, "hello from bot", TEST_USER_ID
        )
        assert response.message == "hello from bot"
        assert response.user.first_name == "DDU"
        assert (
            response.content.name
            == "No serial number - how we log it in ITSM / BranchTrack"
        )
def test_class_context_manager():
    class_session = Session()

    class TestMockClass(BaseMockClass):
        def _test_json(self, request):
            return "hello alabama"

    with mock_session_with_class(class_session, TestMockClass,
                                 'http://test.com'):
        response = class_session.get('http://test.com/test.json')
    assert response.text == "hello alabama"
def test_class_context_manager_fixture_map():
    class_session = Session()

    class TestMockClass(BaseMockClass):
        def _test_txt(self, request):
            return self.adapter.response_from_fixture(
                request=request, fixture_path='tests/fixtures/test.txt')

    with mock_session_with_class(class_session, TestMockClass,
                                 'http://test.com'):
        response = class_session.get('http://test.com/test.txt')
    assert response.text == "Hello world!"
예제 #17
0
def test_log_completion():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.content.log_completion(
            content_id="650a4eb1-eff8-4032-aef0-ee5a66ab61b1",
            user_email="*****@*****.**",
        )
        assert response.id == "650a4eb1-eff8-4032-aef0-ee5a66ab61b1"
        assert (
            response.content.name
            == "How to open and close presentations? - Presentation lesson from Mark Powell"
        )
        assert response.content.provider.name == "youtube.com"
        assert response.user.first_name == "Anthony"
def test_class_context_manager_query():
    class_session = Session()

    class TestMockClass(BaseMockClass):
        def _test_json(self, request):
            return 'always'

    with mock_session_with_class(class_session, TestMockClass,
                                 'http://test.com'):
        response1 = class_session.get('http://test.com/test.json',
                                      params={'test': 'param'})
    assert response1.status_code == 200
    assert response1.text == 'always'
예제 #19
0
def test_delete_skill():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.users.delete_skill(
            TEST_USER_ID, "f5bf30a8-412c-4cea-9a64-1d4aae5a40f9")
        assert response is None

        response = client.users.delete_skill(
            TEST_USER_ID,
            UserSkill(id=TEST_USER_SKILL_ID,
                      level=SkillLevel.BEGINNER,
                      skill=TEST_SKILL),
        )
        assert response is None
def test_class_context_manager_hyphens():
    """
    Check that hyphens are correctly mapped
    """
    class_session = Session()

    class TestMockClass(BaseMockClass):
        def _test_test_json(self, request):
            return 'always'

    with mock_session_with_class(class_session, TestMockClass,
                                 'http://test.com'):
        response1 = class_session.get('http://test.com/test-test.json',
                                      params={'test': 'param'})
    assert response1.status_code == 200
    assert response1.text == 'always'
def test_class_context_manager_with_params():
    class_session = Session()

    class TestMockClass(BaseMockClass):
        def _test_json(self, request):
            if request.method == 'GET':
                return 'detroit'
            else:
                return 'san diego'

    with mock_session_with_class(class_session, TestMockClass,
                                 'http://test.com'):
        response1 = class_session.get('http://test.com/test.json')
        response2 = class_session.post('http://test.com/test.json', data='123')
    assert response1.text == 'detroit'
    assert response2.text == 'san diego'
예제 #22
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
def test_class_context_manager_good_factory():
    class_session = Session()

    class TestMockClass(BaseMockClass):
        def _test_json(self, request):
            return StaticResponseFactory.GoodResponse(request=request,
                                                      body=b("it's my life"),
                                                      headers={'now': 'never'},
                                                      status_code=201)

    with mock_session_with_class(class_session, TestMockClass,
                                 'http://test.com'):
        response = class_session.get('http://test.com/test.json')
    assert response.text == "it's my life"
    assert 'now' in response.headers.keys()
    assert response.headers['now'] == 'never'
    assert response.status_code == 201
def test_class_context_manager_bad_factory():
    class_session = Session()

    class TestMockClass(BaseMockClass):
        def _test_json(self, request):
            return StaticResponseFactory.BadResponse(
                request=request,
                body=b("it's not over"),
                headers={'now': 'never'},
            )

    with mock_session_with_class(class_session, TestMockClass,
                                 'http://test.com'):
        response = class_session.get('http://test.com/test.json')
    assert response.text == "it's not over"
    assert 'now' in response.headers.keys()
    assert response.headers['now'] == 'never'
    assert response.status_code == DEFAULT_BAD_STATUS_CODE
예제 #25
0
def test_update_user():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.users.update(
            TEST_USER_ID,
            "Bobby no mates",
            "lord of all",
            "boss place",
            "*****@*****.**",
            saml_id=None,
            custom_id=None,
            hire_date=None,
            location="",
            avatar="",
            admin=False,
            deactivated=False,
            custom_fields=None,
        )
        assert response.id == TEST_USER_ID
예제 #26
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'
예제 #27
0
def test_create_content():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.content.create(
            "test",
            ContentType.WEBPAGE,
            "url://test.com/page",
            "Pluralsight",
            "topic",
            SkillLevel.ADVANCED,
            custom_id=None,
            description=None,
            image=None,
            tags=None,
            enabled=True,
            skills=None,
            duration=None,
        )
        assert response.id == TEST_CONTENT_ID
        assert response.name == "Networking Basics"
        assert response.provider.name == "Cisco Learning Labs"
def test_class_context_manager_unpacked():
    class_session = Session()

    class TestMockClass(BaseMockClass):
        def _test_json(self, method, params, headers):
            return "{0}{1}{2}".format(method.upper(), params['a'],
                                      headers['X-Special'])

        def _test2_json(self, url, body):
            return "{0}{1}".format(url, body)

    with mock_session_with_class(class_session, TestMockClass,
                                 'http://test.com'):
        response1 = class_session.get('http://test.com/test.json',
                                      params={'a': 'param'},
                                      headers={'X-Special': 'forces'})
        response2 = class_session.get('http://test.com/test2.json',
                                      data='hello')
    assert response1.status_code == 200
    assert response1.text == 'GETparamforces'
    assert response2.status_code == 200
    assert response2.text == 'http://test.com/test2.jsonhello'
예제 #29
0
def test_post_bad_request():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        with pytest.raises(PathgatherApiException):
            client.post("post/bad")
예제 #30
0
def test_post_request():
    with mock_session_with_class(client.session, MockClient, TEST_URL):
        response = client.post("post")
        assert response["good"]