コード例 #1
0
ファイル: test_resources.py プロジェクト: salespreso/prospyr
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)
コード例 #2
0
ファイル: test_resources.py プロジェクト: salespreso/prospyr
def test_read():
    cn = connect(email='foo', token='bar')
    cn.session = MockSession(urls={
        cn.build_absolute_url('people/1/'): load_fixture_json('person.json')
    })
    jon = Person(id=1)
    jon.read()
    assert_is_jon(jon)
コード例 #3
0
ファイル: test_resources.py プロジェクト: polyglotdev/prospyr
def test_str_does_not_raise():
    people = (
        Person(),
        Person(id=12),
        Person(name='Gertrude T. Boondock'),
    )
    for person in people:
        print(str(person))
コード例 #4
0
ファイル: test_resources.py プロジェクト: polyglotdev/prospyr
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)
コード例 #5
0
ファイル: test_resources.py プロジェクト: polyglotdev/prospyr
def test_read():
    cn = connect(email='foo', token='bar')
    cn.session = MockSession(urls={
        cn.build_absolute_url('people/1/'):
        load_fixture_json('person.json')
    })
    jon = Person(id=1)
    jon.read()
    assert_is_jon(jon)
コード例 #6
0
ファイル: test_resources.py プロジェクト: polyglotdev/prospyr
def test_resource_validation():
    # valid albert
    albert = Person(name='Albert Cornswaddle', emails=[])
    albert.validate()

    # albert without email
    albert = Person(name='Albert Cornswaddle')
    with assert_raises(exceptions.ValidationError):
        albert.validate()
コード例 #7
0
ファイル: test_resources.py プロジェクト: polyglotdev/prospyr
def test_no_instance_access_to_manager():
    # accessing from class is OK
    Person.objects

    # but cannot access from class instance
    person = Person()
    with assert_raises(AttributeError):
        person.objects
コード例 #8
0
ファイル: test_mixins.py プロジェクト: Seedstars/prospyr
def test_delete():
    cn = make_cn_with_resp(method='delete', status_code=codes.ok, content=[])
    person = Person(id=1)
    person.delete(using=cn.name)
    expected_url = URLObject(_default_url + 'v1/people/1/')
    cn.delete.assert_called_with(expected_url)

    # can't delete without an id
    with assert_raises(ValueError):
        no_id_person = Person()
        no_id_person.delete(using=cn.name)
コード例 #9
0
ファイル: test_resources.py プロジェクト: salespreso/prospyr
def test_resource_validation():
    # valid albert
    albert = Person(name='Albert Cornswaddle', emails=[])
    albert.validate()

    # albert without email
    albert = Person(name='Albert Cornswaddle')
    with assert_raises(exceptions.ValidationError):
        albert.validate()
コード例 #10
0
ファイル: test_mixins.py プロジェクト: Seedstars/prospyr
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')
コード例 #11
0
ファイル: test_mixins.py プロジェクト: Seedstars/prospyr
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')