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


Python Api.send_request方法代码示例

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


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

示例1: TestIssue

# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import send_request [as 别名]
class TestIssue(TestCase):
  """ Test Issue class. """
  def setUp(self):
    super(TestIssue, self).setUp()
    self.api = Api()
    with factories.single_commit():
      audit = factories.AuditFactory()
      for status in all_models.Issue.VALID_STATES:
        factories.IssueFactory(audit=audit, status=status)

  def test_filter_by_status(self):
    """Test Issue filtering by status."""
    query_request_data = [{
        'fields': [],
        'filters': {
            'expression': {
                'left': {
                    'left': 'status',
                    'op': {'name': '='},
                    'right': 'Fixed'
                },
                'op': {'name': 'OR'},
                'right': {
                    'left': 'status',
                    'op': {'name': '='},
                    'right': 'Fixed and Verified'
                },
            },
        },
        'object_name': 'Issue',
        'permissions': 'read',
        'type': 'values',
    }]
    response = self.api.send_request(
        self.api.client.post,
        data=query_request_data,
        api_link="/query"
    )
    self.assertEqual(response.status_code, 200)

    statuses = {i["status"] for i in response.json[0]["Issue"]["values"]}
    self.assertEqual(statuses, {"Fixed", "Fixed and Verified"})
开发者ID:egorhm,项目名称:ggrc-core,代码行数:44,代码来源:test_issue.py

示例2: DocumentReferenceUrlRBACFactory

# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import send_request [as 别名]

#.........这里部分代码省略.........
    """Create parent based on Name"""
    try:
      parent = FACTORIES_MAPPING[parent_name]()
    except KeyError():
      raise ValueError("Unknown parent {}".format(parent_name))
    return parent

  def create(self):
    """Create new Document object."""
    result = self.api.post(all_models.Document, {
        "document": {
            "access_control_list": [{
                "ac_role_id": self.admin_acr_id,
                "person": {
                    "id": self.user_id,
                    "type": "Person",
                }
            }],
            "link": factories.random_str(),
            "title": factories.random_str(),
            "context": None,
        }
    })
    return result

  def read(self):
    """Read existing Document object."""
    res = self.api.get(all_models.Document, self.document_id)
    return res

  def update(self):
    """Update title of existing Document object."""
    document = all_models.Document.query.get(self.document_id)
    return self.api.put(document, {"title": factories.random_str()})

  def delete(self):
    """Delete Document object."""
    document = all_models.Document.query.get(self.document_id)
    return self.api.delete(document)

  def map(self, document=None):
    """Map Document to parent object."""
    parent = self.parent.__class__.query.get(self.parent_id)
    map_document = document if document \
        else factories.DocumentReferenceUrlFactory()

    return self.objgen.generate_relationship(
        source=parent,
        destination=map_document
    )[0]

  def create_and_map(self):
    """Create new Document and map it to parent."""
    response = self.create()
    document_id = None
    if response.json and response.json.get("document"):
      document_id = response.json.get("document", {}).get("id")
    if not document_id:
      return response

    document = all_models.Document.query.get(document_id)
    return self.map(document)

  def add_comment(self):
    """Map new comment to document."""
    document = all_models.Document.query.get(self.document_id)
    _, comment = self.objgen.generate_object(all_models.Comment, {
        "description": factories.random_str(),
        "context": None,
    })
    return self.objgen.generate_relationship(source=document,
                                             destination=comment)[0]

  def read_comments(self):
    """Read comments mapped to document"""
    document = all_models.Document.query.get(self.document_id)
    with factories.single_commit():
      comment = factories.CommentFactory(description=factories.random_str())
      factories.RelationshipFactory(source=document, destination=comment)

    query_request_data = [{
        "fields": [],
        "filters": {
            "expression": {
                "object_name": "Document",
                "op": {
                    "name": "relevant"
                },
                "ids": [document.id]
            }
        },
        "object_name": "Comment",
    }]

    response = self.api.send_request(
        self.api.client.post,
        data=query_request_data,
        api_link="/query"
    )
    return response
开发者ID:egorhm,项目名称:ggrc-core,代码行数:104,代码来源:document.py

示例3: UniversalRBACFactory

# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import send_request [as 别名]

#.........这里部分代码省略.........
            factories.random_str(),
            "title":
            factories.random_str(),
            "context":
            None,
            "access_control_list": [
                {
                    "ac_role_id": admin_acr_id,
                    "person": {
                        "id": self.user_id,
                        "type": "Person",
                    }
                }
            ],
        }
    )
    parent = db.session.query(self.parent.__class__).get(self.parent_id)
    return self.objgen.generate_relationship(
        source=document, destination=parent
    )[0]

  def read_document(self):
    """Read existing Document object."""
    doc_id = self._setup_document()
    res = self.api.get(all_models.Document, doc_id)
    return res

  def update_document(self):
    """Update title of existing Document object."""
    doc_id = self._setup_document()
    document = all_models.Document.query.get(doc_id)
    return self.api.put(document, {"title": factories.random_str()})

  def delete_document(self):
    """Delete Document object."""
    doc_id = self._setup_document()
    document = all_models.Document.query.get(doc_id)
    return self.api.delete(document)

  def create_and_map_comment(self):
    """Create new Comment object and map to parent."""
    _, comment = self.objgen.generate_object(
        all_models.Comment, {
            "description": factories.random_str(),
            "context": None,
        }
    )
    parent = db.session.query(self.parent.__class__).get(self.parent_id)
    return self.objgen.generate_relationship(
        source=parent, destination=comment
    )[0]

  def read_comment(self):
    """Read existing Comment object."""
    comment_id = self._setup_comment()
    res = self.api.get(all_models.Comment, comment_id)
    return res

  def create_and_map_document_comment(self):
    """Map new comment to document."""
    doc_id = self._setup_document()
    _, comment = self.objgen.generate_object(
        all_models.Comment, {
            "description": factories.random_str(),
            "context": None,
        }
    )
    document = all_models.Document.query.get(doc_id)
    return self.objgen.generate_relationship(
        source=document, destination=comment
    )[0]

  def read_document_comment(self):
    """Read comments mapped to document"""
    doc_id = self._setup_document()
    document = all_models.Document.query.get(doc_id)
    with factories.single_commit():
      comment = factories.CommentFactory(description=factories.random_str())
      factories.RelationshipFactory(source=document, destination=comment)

    query_request_data = [
        {
            "fields": [],
            "filters": {
                "expression": {
                    "object_name": "Document",
                    "op": {
                        "name": "relevant"
                    },
                    "ids": [document.id]
                }
            },
            "object_name": "Comment",
        }
    ]

    response = self.api.send_request(
        self.api.client.post, data=query_request_data, api_link="/query"
    )
    return response
开发者ID:,项目名称:,代码行数:104,代码来源:

示例4: EvidenceRBACFactory

# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import send_request [as 别名]

#.........这里部分代码省略.........

  def create(self):
    """Create new Evidence object."""
    result = self.api.post(all_models.Evidence, {
        "evidence": {
            "access_control_list": [{
                "ac_role_id": self.admin_acr_id,
                "person": {
                    "id": self.user_id,
                    "type": "Person",
                }
            }],
            "link": factories.random_str(),
            "title": factories.random_str(),
            "context": None,
        }
    })
    return result

  def read(self):
    """Read existing Evidence object."""
    res = self.api.get(all_models.Evidence, self.evidence_id)
    return res

  def update(self):
    """Update title of existing Evidence object."""
    evidence = all_models.Evidence.query.get(self.evidence_id)
    return self.api.put(evidence, {"title": factories.random_str()})

  def delete(self):
    """Delete Evidence object."""
    evidence = all_models.Evidence.query.get(self.evidence_id)
    return self.api.delete(evidence)

  def map(self, evidence=None):
    """Map Evidence to parent object."""
    if self.parent == "Audit":
      parent = all_models.Audit.query.get(self.audit_id)
    else:
      parent = all_models.Assessment.query.get(self.assessment_id)
    map_evidence = evidence if evidence else factories.EvidenceUrlFactory()

    return self.api.put(parent, {
        "actions": {
            "add_related": [{
                "id": map_evidence.id,
                "type": "Evidence",
            }]
        }
    })

  def create_and_map(self):
    """Create new Evidence and map it to parent."""
    response = self.create()
    evidence_id = None
    if response.json and response.json.get("evidence"):
      evidence_id = response.json.get("evidence", {}).get("id")
    if not evidence_id:
      return response

    evidence = all_models.Evidence.query.get(evidence_id)
    return self.map(evidence)

  def add_comment(self):
    """Map new comment to evidence."""
    evidence = all_models.Evidence.query.get(self.evidence_id)
    _, comment = self.objgen.generate_object(all_models.Comment, {
        "description": factories.random_str(),
        "context": None,
    })
    return self.objgen.generate_relationship(source=evidence,
                                             destination=comment)[0]

  def read_comments(self):
    """Read comments mapped to evidence"""
    evidence = all_models.Evidence.query.get(self.evidence_id)
    with factories.single_commit():
      comment = factories.CommentFactory(description=factories.random_str())
      factories.RelationshipFactory(source=evidence, destination=comment)

    query_request_data = [{
        "fields": [],
        "filters": {
            "expression": {
                "object_name": "Evidence",
                "op": {
                    "name": "relevant"
                },
                "ids": [evidence.id]
            }
        },
        "object_name": "Comment",
    }]

    response = self.api.send_request(
        self.api.client.post,
        data=query_request_data,
        api_link="/query"
    )
    return response
开发者ID:,项目名称:,代码行数:104,代码来源:

示例5: TestSnapshot

# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import send_request [as 别名]
class TestSnapshot(TestCase):
  """Basic tests snapshots"""

  def setUp(self):
    super(TestSnapshot, self).setUp()
    self.api = Api()

  def test_search_by_reference_url(self):
    """Test search audit related snapshots of control type by reference_url"""

    expected_ref_url = "xxx"
    with factories.single_commit():
      audit = factories.AuditFactory()
      audit_id = audit.id
      doc1 = factories.DocumentReferenceUrlFactory(link=expected_ref_url,
                                                   title=expected_ref_url)
      doc_id1 = doc1.id
      doc2 = factories.DocumentReferenceUrlFactory(link="yyy", title="yyy")
      doc_id2 = doc2.id
      control = factories.ControlFactory()
      control_id = control.id

    response = self.api.post(all_models.Relationship, {
        "relationship": {
            "source": {"id": control_id, "type": control.type},
            "destination": {"id": doc_id1, "type": doc1.type},
            "context": None
        },
    })
    self.assertStatus(response, 201)
    response = self.api.post(all_models.Relationship, {
        "relationship": {
            "source": {"id": control_id, "type": control.type},
            "destination": {"id": doc_id2, "type": doc2.type},
            "context": None
        },
    })
    self.assertStatus(response, 201)
    response = self.api.post(all_models.Relationship, {
        "relationship": {
            "source": {"id": control_id, "type": control.type},
            "destination": {"id": audit_id, "type": audit.type},
            "context": None
        },
    })
    self.assertStatus(response, 201)
    query_request_data = [{
        "object_name": "Snapshot",
        "filters": {
            "expression": {
                "left": {
                    "left": "child_type",
                    "op": {"name": "="},
                    "right": "Control"
                },
                "op": {"name": "AND"},
                "right": {
                    "left": {
                        "object_name": "Audit",
                        "op": {"name": "relevant"},
                        "ids": [audit_id]
                    },
                    "op": {"name": "AND"},
                    "right": {
                        "left": {
                            "left": "Reference URL",
                            "op": {"name": "~"},
                            "right": expected_ref_url
                        },
                        "op": {"name": "AND"},
                        "right": {
                            "left": "Status",
                            "op": {"name": "IN"},
                            "right": ["Active", "Draft", "Deprecated"]
                        }
                    }
                }
            }
        },
    }]
    response = self.api.send_request(
        self.api.client.post,
        data=query_request_data,
        api_link="/query"
    )
    self.assert200(response)
    self.assertEquals(1, response.json[0]["Snapshot"]["count"])
开发者ID:,项目名称:,代码行数:89,代码来源:


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