当前位置: 首页>>代码示例>>Python>>正文


Python User.external_typename方法代码示例

本文整理汇总了Python中assembl.models.User.external_typename方法的典型用法代码示例。如果您正苦于以下问题:Python User.external_typename方法的具体用法?Python User.external_typename怎么用?Python User.external_typename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在assembl.models.User的用法示例。


在下文中一共展示了User.external_typename方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_api_get_posts_from_idea

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import external_typename [as 别名]
def test_api_get_posts_from_idea(
        discussion, test_app, test_session, participant1_user, 
        root_idea, subidea_1, subidea_1_1, subidea_1_1_1,
        root_post_1, reply_post_1, reply_post_2):
    base_post_url = get_url(discussion, 'posts')
    base_idea_url = get_url(discussion, 'ideas')
    base_extract_url = get_url(discussion, 'extracts')
    
    #Check initial conditions from post api
    url = base_post_url
    res = test_app.get(url)
    assert res.status_code == 200
    res_data = json.loads(res.body)
    assert res_data['total'] == 3
    
    #Check initial conditions from idea api
    res = test_app.get(base_idea_url + "/" + str(root_idea.id))
    assert res.status_code == 200
    res_data = json.loads(res.body)
    assert res_data['num_posts'] == 3
    assert res_data['num_orphan_posts'] == 3
    
    def check_number_of_posts(idea, expected_num, fail_msg):
        #Check from idea API
        idea.db.flush()
        res = test_app.get(base_idea_url + "/" + str(idea.id))
        assert res.status_code == 200
        res_data = json.loads(res.body)
        assert res_data['num_posts'] == expected_num, "idea API returned %d but %s" % (res_data['num_posts'],fail_msg)

        url = base_post_url + "?" + urlencode({"root_idea_id": idea.uri()})
        res = test_app.get(url)
        assert res.status_code == 200
        res_data = json.loads(res.body)
        #print(repr(res_data))
        #TODO: BENOITG:  THERE IS A SESSION PROBLEM HERE
        assert res_data['total'] == expected_num, "post API returned %d but %s" % (res_data['total'],fail_msg)

    def check_total_and_orphans(expected_total, expected_orphans):
        #Check orphans from idea api
        res = test_app.get(base_idea_url + "/" + str(root_idea.id))
        assert res.status_code == 200
        res_data = json.loads(res.body)
        assert res_data['num_posts'] == expected_total
        # Known to fail. I get 0 on v6, ? on v7.
        assert res_data['num_orphan_posts'] == expected_orphans
    
    check_number_of_posts(subidea_1, 0, "Initially no posts are linked")
    check_number_of_posts(subidea_1_1, 0, "Initially no posts are linked")
    check_number_of_posts(subidea_1_1_1, 0, "Initially no posts are linked")
    
    user = participant1_user
    extract_user = {
        "@id": user.uri(),
        "name": user.name,
        "@type": User.external_typename()}
    base_extract_data = {
        "idIdea": None,
        "creator": extract_user,
        "owner": extract_user,
        "text": "Let's lower taxes to fav",
        "creationDate": 1376573216160,
        "target": {
            "@type": Email.external_typename(),
            "@id": None
        }
    }
    #Create extract
    extract_data = base_extract_data.copy()
    extract_data["idIdea"] = subidea_1_1.uri()
    extract_data["target"]['@id'] = reply_post_1.uri()
    res = test_app.post(base_extract_url, json.dumps(extract_data))
    assert res.status_code == 200
    res_data = json.loads(res.body)
    extract_post_1_to_subidea_1_1_id = res_data['@id']
    #test_session.flush()
    #test_session.expunge_all()
    
    check_number_of_posts(subidea_1_1,  2, "Num posts on idea (directly) should recurse to the two posts")
    #import transaction
    #transaction.commit()
    check_number_of_posts(subidea_1,  2, "Num posts on parent idea should be the same as the child")
    check_number_of_posts(subidea_1_1_1,  0, "Num posts on child of idea should still be zero")
    check_total_and_orphans(3, 1)
    
    #Create second extract to same post and idea
    extract_data = base_extract_data.copy()
    extract_data["idIdea"] = subidea_1_1.uri()
    extract_data["target"]['@id'] = reply_post_1.uri()
    extract_data["text"] = "Let's lower taxes to fav 2",
    res = test_app.post(base_extract_url, json.dumps(extract_data))
    assert res.status_code == 200
    res_data = json.loads(res.body)
    extract_post_1_to_subidea_1_1_bis_id = res_data['@id']

    check_number_of_posts(subidea_1_1,  2, "Num posts should not have changed with second identical extract")
    check_number_of_posts(subidea_1,  2, "Num posts on parent idea  should not have changed with second identical extract")
    check_total_and_orphans(3, 1)

    #Create extract from parent idea to leaf message
#.........这里部分代码省略.........
开发者ID:iilab,项目名称:assembl,代码行数:103,代码来源:tests.py

示例2: test_extracts

# 需要导入模块: from assembl.models import User [as 别名]
# 或者: from assembl.models.User import external_typename [as 别名]
def test_extracts(
        discussion, participant1_user, reply_post_2, test_app, subidea_1_1, extract_post_1_to_subidea_1_1):
    from assembl.models import Extract
    user = participant1_user
    extract_user = {
        "@id": user.uri(),
        "name": user.name,
        "@type": User.external_typename()}
    extract_data = {
        "idIdea": None,
        "creator": extract_user,
        "owner": extract_user,
        "text": "Let's lower taxes to fav",
        "creationDate": 1376573216160,
        "target": {
            "@type": Email.external_typename(),
            "@id": reply_post_2.uri()
        }
    }

    base_url = get_url(discussion, 'extracts')
    #Load collection
    res = test_app.get(base_url)
    assert res.status_code == 200
    extracts = json.loads(res.body)
    assert len(extracts) == 1
    
    #Load extract directly
    res = test_app.get(base_url + "/" + quote_plus(extract_post_1_to_subidea_1_1.uri()))
    assert res.status_code == 200
    extract_json = json.loads(res.body)
    assert extract_json['@id'] == extract_post_1_to_subidea_1_1.uri()

    #Check the API returns a 404 for extracts that never existed
    res = test_app.get(base_url + "/" + quote_plus("id_that_does_not_exist"), expect_errors=True)
    assert res.status_code == 404
    
    #Create (Post)
    res = test_app.post(base_url, json.dumps(extract_data))
    assert res.status_code == 200
    res_data = json.loads(res.body)
    extract_id = res_data['@id']
    assert extract_id != None

    #Check collection
    res = test_app.get(base_url, json.dumps(extract_data))
    assert res.status_code == 200
    extracts = json.loads(res.body)
    assert len(extracts) == 2
    assert extract_id in [e['@id'] for e in extracts]
    
    #Update (PUT)
    #TODO:  We should test this field by field
    url = base_url + "/" + quote_plus(extract_id)
    modified_extract_data = extract_data.copy()
    modified_extract_data["idIdea"] = subidea_1_1.uri()
    res = test_app.put(url, json.dumps(modified_extract_data))
    assert res.status_code == 200
    Extract.db.flush()
    res = test_app.get(url)
    assert res.status_code == 200
    extract_json = json.loads(res.body)
    assert extract_json['idIdea'] == subidea_1_1.uri()

    #Delete
    res = test_app.delete(base_url + "/" + quote_plus(extract_id))
    assert res.status_code == 204
    #Check collection after delete
    res = test_app.get(base_url, json.dumps(extract_data))
    assert res.status_code == 200
    extracts = json.loads(res.body)
    assert len(extracts) == 1
    assert extract_id not in [e['@id'] for e in extracts]
    
    #FIXME:  This should actually return 410 gone now
    res = test_app.get(base_url + "/" + quote_plus(extract_id), expect_errors=True)
    assert res.status_code == 404
开发者ID:iilab,项目名称:assembl,代码行数:79,代码来源:tests.py


注:本文中的assembl.models.User.external_typename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。