示例#1
0
def test_get_person_by_email():
    cn = connect(email='foo', token='bar')
    cn.session = MockSession(urls={
        cn.build_absolute_url('people/fetch_by_email/'): load_fixture_json('person.json')  # noqa
    })
    person = Person.objects.get(email='*****@*****.**')
    assert_is_jon(person)
示例#2
0
def test_manager_get():
    cn = connect(email='foo', token='bar')
    cn.session = MockSession(urls={
        cn.build_absolute_url('people/1/'): load_fixture_json('person.json')
    })
    jon = Person.objects.get(id=1)
    assert_is_jon(jon)
示例#3
0
def test_create():
    # can create
    content = json.loads(load_fixture_json('person.json'))
    # no support for creation with custom fields
    del content['custom_fields']
    cn = make_cn_with_resp(
        method='post',
        status_code=codes.ok,
        content=content
    )
    person = Person(name='Slithey Tove')
    person.create(using=cn.name)
    expected_url = URLObject(_default_url + 'v1/people/')
    cn.post.assert_called_with(expected_url, json={'name': 'Slithey Tove'})

    # can't create with an ID
    with assert_raises(ValueError):
        id_person = Person(id=1)
        id_person.create(using=cn.name)

    # validation errors come back. note the `invalid` instance isn't really
    # invalid; we just simulate the invalid response.
    invalid = Person(name='Invalid')
    cn = make_cn_with_resp(
        method='post',
        status_code=codes.unprocessable_entity,
        content=dict(message='Something wrong')
    )
    try:
        invalid.create(using=cn.name)
    except ValueError as ex:
        assert 'Something wrong' in str(ex)
    else:
        raise AssertionError('Exception not thrown')
示例#4
0
def test_id_or_email_required_for_person():
    cn = connect(email='foo', token='bar')
    cn.session = MockSession(urls={
        cn.build_absolute_url('people/1/'): load_fixture_json('person.json')
    })
    with assert_raises(exceptions.ProspyrException):
        Person.objects.get()
示例#5
0
def test_update():
    content = json.loads(load_fixture_json('person.json'))
    cn = make_cn_with_resp(method='put', status_code=codes.ok, content=content)
    person = Person(id=1, name='Nantucket Terwilliger')
    person.update(using=cn.name)
    expected_url = URLObject(_default_url + 'v1/people/1/')
    cn.put.assert_called_with(
        expected_url,
        json={'name': 'Nantucket Terwilliger'}
    )

    # can't update without an id
    with assert_raises(ValueError):
        no_id_person = Person()
        no_id_person.update(using=cn.name)

    # validation errors come back. note the `invalid` instance isn't really
    # invalid; we just simulate the invalid response.
    invalid = Person(id=1, name='Invalid')
    cn = make_cn_with_resp(
        method='put',
        status_code=codes.unprocessable_entity,
        content=dict(message='Something wrong')
    )
    try:
        invalid.update(using=cn.name)
    except ValueError as ex:
        assert 'Something wrong' in str(ex)
    else:
        raise AssertionError('Exception not thrown')
示例#6
0
def test_construct_from_api_data():
    data = json.loads(load_fixture_json('person.json'))
    jon = Person.from_api_data(data)
    assert_is_jon(jon)

    data = {'invalid': 'data'}
    with assert_raises(exceptions.ValidationError):
        Person.from_api_data(data)
示例#7
0
def test_manager_get():
    cn = connect(email='foo', token='bar')
    cn.session = MockSession(urls={
        cn.build_absolute_url('people/1/'):
        load_fixture_json('person.json')
    })
    jon = Person.objects.get(id=1)
    assert_is_jon(jon)
示例#8
0
def test_id_or_email_required_for_person():
    cn = connect(email='foo', token='bar')
    cn.session = MockSession(urls={
        cn.build_absolute_url('people/1/'):
        load_fixture_json('person.json')
    })
    with assert_raises(exceptions.ProspyrException):
        Person.objects.get()
示例#9
0
def test_construct_from_api_data():
    data = json.loads(load_fixture_json('person.json'))
    jon = Person.from_api_data(data)
    assert_is_jon(jon)

    data = {'invalid': 'data'}
    with assert_raises(exceptions.ValidationError):
        Person.from_api_data(data)
示例#10
0
def test_get_person_by_email():
    cn = connect(email='foo', token='bar')
    cn.session = MockSession(
        urls={
            cn.build_absolute_url('people/fetch_by_email/'):
            load_fixture_json('person.json')  # noqa
        })
    person = Person.objects.get(email='*****@*****.**')
    assert_is_jon(person)
示例#11
0
def test_manager_connection_assignment():
    cn_without_jon = connect(email='foo', token='bar', name='without_jon')
    cn_with_jon = connect(email='foo', token='bar', name='with_jon')

    cn_without_jon.session = MockSession(urls={})
    cn_with_jon.session = MockSession(urls={
        cn_with_jon.build_absolute_url('people/1/'): load_fixture_json('person.json')  # noqa
    })

    jon = Person.objects.use('with_jon').get(id=1)
    assert_is_jon(jon)
    with assert_raises(exceptions.ApiError):
        jon = Person.objects.use('without_jon').get(id=1)
示例#12
0
def test_manager_connection_assignment():
    cn_without_jon = connect(email='foo', token='bar', name='without_jon')
    cn_with_jon = connect(email='foo', token='bar', name='with_jon')

    cn_without_jon.session = MockSession(urls={})
    cn_with_jon.session = MockSession(
        urls={
            cn_with_jon.build_absolute_url('people/1/'):
            load_fixture_json('person.json')  # noqa
        })

    jon = Person.objects.use('with_jon').get(id=1)
    assert_is_jon(jon)
    with assert_raises(exceptions.ApiError):
        jon = Person.objects.use('without_jon').get(id=1)
示例#13
0
def test_activitytype_listset():
    connect(email='foo', token='bar')
    atls = ActivityTypeListSet()
    resp = Response()
    resp._content = load_fixture_json('activity_types.json').encode('utf-8')
    resp.status_code = codes.ok
    with mock.patch('prospyr.connection.Connection.get') as get:
        get.return_value = resp
        actual = list(atls)

    actual_names = {a.name for a in actual}
    assert actual_names == {
        'Note', 'Phone Call', 'Meeting', 'Property Changed',
        'My Custom Activity Type', 'Pipeline Stage Changed'
    }
示例#14
0
def test_activitytype_listset():
    connect(email='foo', token='bar')
    atls = ActivityTypeListSet()
    resp = Response()
    resp._content = load_fixture_json('activity_types.json').encode('utf-8')
    resp.status_code = codes.ok
    with mock.patch('prospyr.connection.Connection.get') as get:
        get.return_value = resp
        actual = list(atls)

    actual_names = {a.name for a in actual}
    assert actual_names == {
        'Note', 'Phone Call', 'Meeting', 'Property Changed',
        'My Custom Activity Type', 'Pipeline Stage Changed'
    }