コード例 #1
0
def test_resolve_links_random_link(taxonomy_tree):
    """
    Test if random user data with link resolve taxonomy and keep user data.
    """
    random_user_data = {
        "created_at": "2014-08-11T05:26:03.869245",
        "email": "*****@*****.**",
        "name": "Ken",
        "links": {
            "self": "http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a/b"
        }
    }
    schema = TaxonomySchema()
    res = schema.load(random_user_data)
    # pprint(res)
    assert res == [{
        'is_ancestor': True,
        'level': 1,
        'links': {
            'self': 'http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a'
        },
        'test': 'extra_data'
    }, {
        'created_at': '2014-08-11T05:26:03.869245',
        'email': '*****@*****.**',
        'is_ancestor': False,
        'level': 2,
        'links': {
            'parent': 'http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a',
            'self': 'http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a/b'
        },
        'name': 'Ken',
        'test': 'extra_data'
    }]
コード例 #2
0
def test_resolve_links_random_string_2(app, db, taxonomy_tree):
    """
    Test if wrong url (string) does not pass.
    """
    random_user_data = "bla bla http://example.com/"
    schema = TaxonomySchema()
    with pytest.raises(ValueError):
        schema.load(random_user_data)
コード例 #3
0
def test_resolve_links_random_string_4(app, db, taxonomy_tree):
    """
    Test if random user data (string) are passed.
    """
    random_user_data = "bla bla http://example.com/a/b/z"
    schema = TaxonomySchema()
    with pytest.raises(ValueError):
        schema.load(random_user_data)
コード例 #4
0
def test_resolve_links_random_string_3(app, db, taxonomy_tree):
    """
    Test if wrong url (string) does not pass.
    """
    random_user_data = "bla bla http://example.com/taxonomies/a/b/z"
    schema = TaxonomySchema()
    with pytest.raises(ValidationError,
                       match="Taxonomy term 'a/b/z' has not been found"):
        schema.load(random_user_data)
コード例 #5
0
def test_resolve_links_random():
    """
    Test if random user data are passed.
    """
    random_user_data = {
        "created_at": "2014-08-11T05:26:03.869245",
        "email": "*****@*****.**",
        "name": "Ken",
        "test": "bla"
    }
    schema = TaxonomySchema()
    with pytest.raises(ValidationError):
        schema.load(random_user_data)
コード例 #6
0
def test_resolve_links_array(app, db, taxonomy_tree):
    """
    Test if random user data (string) are passed.
    """
    random_user_data = [{
        'links': {
            'self': 'http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a'
        },
    }, {
        'links': {
            'self': 'http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a/b'
        },
        'test': 'extra_data',
        'next': 'bla',
        'another': 'something'
    }]
    schema = TaxonomySchema(many=True)
    result = schema.load(random_user_data)
    # pprint(result)
    assert result == [{
        'is_ancestor': True,
        'level': 1,
        'links': {
            'self': 'http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a'
        },
        'test': 'extra_data'
    }, {
        'another': 'something',
        'is_ancestor': False,
        'level': 2,
        'links': {
            'parent': 'http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a',
            'self': 'http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a/b'
        },
        'next': 'bla',
        'test': 'extra_data'
    }]
コード例 #7
0
def test_resolve_links_random_string(app, db, taxonomy_tree):
    """
    Test if random user data (string) are passed.
    """
    random_user_data = "bla bla http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a/b"
    schema = TaxonomySchema()
    result = schema.load(random_user_data)
    # pprint(result)
    assert result == [{
        'is_ancestor': True,
        'level': 1,
        'links': {
            'self': 'http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a'
        },
        'test': 'extra_data'
    }, {
        'is_ancestor': False,
        'level': 2,
        'links': {
            'parent': 'http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a',
            'self': 'http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/a/b'
        },
        'test': 'extra_data'
    }]
コード例 #8
0
 class TestSchema(Schema):
     field = List(Nested(TaxonomySchema()))