Beispiel #1
0
    def test_query_external_comment(self):
        """Test query endpoint for ExternalComments collection."""
        with factories.single_commit():
            control = factories.ControlFactory()
            comment = factories.ExternalCommentFactory(
                description="test comment")
            factories.RelationshipFactory(source=control, destination=comment)

        request_data = [{
            "filters": {
                "expression": {
                    "object_name": "Control",
                    "op": {
                        "name": "relevant"
                    },
                    "ids": [control.id]
                },
            },
            "object_name": "ExternalComment",
            "order_by": [{
                "name": "created_at",
                "desc": "true"
            }]
        }]
        response = self.api.send_request(self.api.client.post,
                                         data=request_data,
                                         api_link="/query")
        self.assert200(response)
        response_data = response.json[0]["ExternalComment"]
        self.assertEqual(response_data["count"], 1)
        self.assertEqual(response_data["values"][0]["description"],
                         "test comment")
Beispiel #2
0
  def test_get_risk_external_comment(self):
    """Test query endpoint for risk ExternalComments."""
    with factories.single_commit():
      risk = factories.RiskFactory()
      comment = factories.ExternalCommentFactory(description="comment")
      factories.RelationshipFactory(source=risk, destination=comment)
    request_data = [{
        "filters": {
            "expression": {
                "object_name": "Risk",
                "op": {
                    "name": "relevant"
                },
                "ids": [risk.id]
            },
        },
        "object_name":"ExternalComment",
        "order_by": [{"name": "created_at", "desc": "true"}],
    }]

    response = self.api.post(
        all_models.Risk,
        data=request_data,
        url="/query",
    )

    self.assert200(response)
    response_data = response.json[0]["ExternalComment"]
    self.assertEqual(response_data["count"], 1)
    self.assertEqual(response_data["values"][0]["description"], "comment")
Beispiel #3
0
  def test_external_comments_order(self, order_by_attr):
    """Test order of ExternalComments returned by /query."""
    with factories.single_commit():
      control = factories.ControlFactory()
      for _ in range(5):
        comment = factories.ExternalCommentFactory(
            description=factories.random_str()
        )
        factories.RelationshipFactory(source=control, destination=comment)

    request_data = [{
        "filters": {
            "expression": {
                "object_name": "Control",
                "op": {
                    "name": "relevant"
                },
                "ids": [control.id]
            },
        },
        "object_name":"ExternalComment",
        "order_by": [{"name": order_by_attr, "desc": "true"}]
    }]
    response = self.api.send_request(
        self.api.client.post,
        data=request_data,
        api_link="/query"
    )
    self.assert200(response)
    response_data = response.json[0]["ExternalComment"]
    comments = [val["description"] for val in response_data["values"]]
    expected_comments = db.session.query(
        all_models.ExternalComment.description
    ).order_by(
        getattr(all_models.ExternalComment, order_by_attr).desc(),
        all_models.ExternalComment.id.desc()
    )
    self.assertEqual(comments, [i[0] for i in expected_comments])