Ejemplo n.º 1
0
    def test_post_metric_technical_debt(self, request):
        """Test that accepting technical debt also sets the technical debt value."""
        self.database.measurements.find_one.return_value = dict(
            _id="id", metric_uuid=METRIC_ID, sources=[])

        def set_measurement_id(measurement):
            measurement["_id"] = "measurement_id"

        self.database.measurements.insert_one.side_effect = set_measurement_id
        request.json = dict(accept_debt=True)
        self.assertEqual(
            dict(end="2019-01-01",
                 sources=[],
                 start="2019-01-01",
                 metric_uuid=METRIC_ID,
                 count=dict(value=None,
                            status="debt_target_met",
                            target="0",
                            near_target="10",
                            debt_target=None,
                            direction="<")),
            post_metric_attribute(METRIC_ID, "accept_debt", self.database))
        self.assertEqual(
            dict(
                uuids=[REPORT_ID, SUBJECT_ID, METRIC_ID],
                email=JOHN["email"],
                description=
                "John changed the accept_debt of metric 'name' of subject 'Subject' in report 'Report' "
                "from '' to 'True'."), self.report["delta"])
Ejemplo n.º 2
0
    def test_post_metric_debt_end_date_with_measurements(self, request):
        """Test that changing the metric debt end date adds a new measurement if one or more exist."""
        self.database.measurements.find_one.return_value = dict(
            _id="id", metric_uuid=METRIC_ID, sources=[])

        def set_measurement_id(measurement):
            measurement["_id"] = "measurement_id"

        self.database.measurements.insert_one.side_effect = set_measurement_id
        request.json = dict(debt_end_date="2019-06-07")
        self.assertEqual(
            dict(end="2019-01-01",
                 sources=[],
                 start="2019-01-01",
                 metric_uuid=METRIC_ID,
                 count=dict(value=None,
                            status=None,
                            target="0",
                            near_target="10",
                            debt_target=None,
                            direction="<")),
            post_metric_attribute(METRIC_ID, "debt_end_date", self.database))
        self.assertEqual(
            dict(
                uuids=[REPORT_ID, SUBJECT_ID, METRIC_ID],
                email=JOHN["email"],
                description=
                "John changed the debt_end_date of metric 'name' of subject 'Subject' in report "
                "'Report' from '' to '2019-06-07'."), self.report["delta"])
Ejemplo n.º 3
0
 def test_post_metric_technical_debt_without_sources(self, request):
     """Test that accepting technical debt when the metric has no sources also sets the status to debt target met."""
     self.report["subjects"][SUBJECT_ID]["metrics"][METRIC_ID][
         "sources"] = {}
     self.database.measurements.find_one.return_value = dict(
         _id="id", metric_uuid=METRIC_ID, sources=[])
     self.database.measurements.insert_one.side_effect = self.set_measurement_id
     request.json = dict(accept_debt=True)
     self.assertEqual(
         dict(
             end="2019-01-01",
             sources=[],
             start="2019-01-01",
             metric_uuid=METRIC_ID,
             count=dict(
                 value=None,
                 status="debt_target_met",
                 status_start="2019-01-01",
                 target="0",
                 near_target="10",
                 debt_target=None,
                 direction="<",
             ),
         ),
         post_metric_attribute(METRIC_ID, "accept_debt", self.database),
     )
     self.assert_delta(
         "accept_debt of metric 'name' of subject 'Subject' in report 'Report' from '' to 'True'"
     )
Ejemplo n.º 4
0
 def test_post_comment_with_link(self, request):
     """Test that urls in comments are transformed into anchors."""
     request.json = dict(comment="Comment with url https://google.com")
     self.assertEqual(
         dict(ok=True),
         post_metric_attribute(METRIC_ID, "comment", self.database))
     self.database.reports.insert.assert_called_once_with(self.report)
     self.assert_delta(
         """comment of metric 'name' of subject 'Subject' in report 'Report' from '' to '<p>Comment with url """
         """<a href="https://google.com">https://google.com</a></p>'""")
Ejemplo n.º 5
0
 def test_post_position_last_next(self, request):
     """Test that moving the last metric down does nothing."""
     request.json = dict(position="next")
     self.assertEqual(
         dict(ok=True),
         post_metric_attribute(METRIC_ID2, "position", self.database))
     self.database.reports.insert.assert_not_called()
     self.assertEqual(
         [METRIC_ID, METRIC_ID2],
         list(self.report["subjects"][SUBJECT_ID]["metrics"].keys()))
Ejemplo n.º 6
0
 def test_post_metric_target_without_measurements(self, request):
     """Test that changing the metric target does not add a new measurement if none exist."""
     self.database.measurements.find_one.return_value = None
     request.json = dict(target="10")
     self.assertEqual(
         dict(ok=True),
         post_metric_attribute(METRIC_ID, "target", self.database))
     self.assert_delta(
         "target of metric 'name' of subject 'Subject' in report 'Report' from '0' to '10'"
     )
Ejemplo n.º 7
0
 def test_post_metric_type(self, request):
     """Test that the metric type can be changed."""
     request.json = dict(type="new_type")
     self.assertEqual(
         dict(ok=True),
         post_metric_attribute(METRIC_ID, "type", self.database))
     self.database.reports.insert.assert_called_once_with(self.report)
     self.assert_delta(
         "type of metric 'name' of subject 'Subject' in report 'Report' from 'old_type' to 'new_type'"
     )
Ejemplo n.º 8
0
 def test_post_unsafe_comment(self, request):
     """Test that comments are sanitized, since they are displayed as inner HTML in the frontend."""
     request.json = dict(
         comment=
         'Comment with script<script type="text/javascript">alert("Danger")</script>'
     )
     self.assertEqual(
         dict(ok=True),
         post_metric_attribute(METRIC_ID, "comment", self.database))
     self.database.reports.insert.assert_called_once_with(self.report)
     self.assert_delta(
         "comment of metric 'name' of subject 'Subject' in report 'Report' from '' to 'Comment with script'"
     )
Ejemplo n.º 9
0
 def test_post_position_next(self, request):
     """Test that a metric can be moved down."""
     request.json = dict(position="next")
     self.assertEqual(
         dict(ok=True),
         post_metric_attribute(METRIC_ID, "position", self.database))
     self.database.reports.insert.assert_called_once_with(self.report)
     self.assertEqual(
         [METRIC_ID2, METRIC_ID],
         list(self.report["subjects"][SUBJECT_ID]["metrics"].keys()))
     self.assert_delta(
         "position of metric 'name' of subject 'Subject' in report 'Report' from '0' to '1'"
     )
Ejemplo n.º 10
0
 def test_post_metric_target_without_measurements(self, request):
     """Test that changing the metric target doesnt't add a new measurement if none exist."""
     self.database.measurements.find_one.return_value = None
     request.json = dict(target="10")
     self.assertEqual(
         dict(ok=True),
         post_metric_attribute(METRIC_ID, "target", self.database))
     self.assertEqual(
         dict(
             uuids=[REPORT_ID, SUBJECT_ID, METRIC_ID],
             email=JOHN["email"],
             description=
             "John changed the target of metric 'name' of subject 'Subject' in report 'Report' "
             "from '0' to '10'."), self.report["delta"])
Ejemplo n.º 11
0
 def test_post_position_previous(self, request):
     """Test that a metric can be moved up."""
     request.json = dict(position="previous")
     self.assertEqual(
         dict(ok=True),
         post_metric_attribute(METRIC_ID2, "position", self.database))
     self.database.reports.insert.assert_called_once_with(self.report)
     self.assertEqual(
         [METRIC_ID2, METRIC_ID],
         list(self.report["subjects"][SUBJECT_ID]["metrics"].keys()))
     self.assert_delta(
         "position of metric 'name2' of subject 'Subject' in report 'Report' from '1' to '0'",
         uuids=[REPORT_ID, SUBJECT_ID, METRIC_ID2],
     )
Ejemplo n.º 12
0
 def test_post_metric_type(self, request):
     """Test that the metric type can be changed."""
     request.json = dict(type="new_type")
     self.assertEqual(
         dict(ok=True),
         post_metric_attribute(METRIC_ID, "type", self.database))
     self.database.reports.insert.assert_called_once_with(self.report)
     self.assertEqual(
         dict(
             uuids=[REPORT_ID, SUBJECT_ID, METRIC_ID],
             email=JOHN["email"],
             description=
             "John changed the type of metric 'name' of subject 'Subject' in report 'Report' "
             "from 'old_type' to 'new_type'."), self.report["delta"])
Ejemplo n.º 13
0
    def test_post_comment_with_link(self, request):
        """Test that urls in comments are transformed into anchors."""
        request.json = dict(comment='Comment with url https://google.com')
        self.assertEqual(
            dict(ok=True),
            post_metric_attribute(METRIC_ID, "comment", self.database))
        self.database.reports.insert.assert_called_once_with(self.report)
        self.assertEqual(
            dict(
                uuids=[REPORT_ID, SUBJECT_ID, METRIC_ID],
                email=JOHN["email"],
                description=
                """John changed the comment of metric 'name' of subject 'Subject' in report 'Report' \
from '' to '<p>Comment with url <a href="https://google.com">https://google.com</a></p>'."""
            ), self.report["delta"])
Ejemplo n.º 14
0
 def test_post_position_next(self, request):
     """Test that a metric can be moved down."""
     request.json = dict(position="next")
     self.assertEqual(
         dict(ok=True),
         post_metric_attribute(METRIC_ID, "position", self.database))
     self.database.reports.insert.assert_called_once_with(self.report)
     self.assertEqual(
         [METRIC_ID2, METRIC_ID],
         list(self.report["subjects"][SUBJECT_ID]["metrics"].keys()))
     self.assertEqual(
         dict(
             uuids=[REPORT_ID, SUBJECT_ID, METRIC_ID],
             email=JOHN["email"],
             description=
             "John changed the position of metric 'name' of subject 'Subject' in report "
             "'Report' from '0' to '1'."), self.report["delta"])
Ejemplo n.º 15
0
 def test_post_unsafe_comment(self, request):
     """Test that comments are sanitized, since they are displayed as inner HTML in the frontend."""
     request.json = dict(
         comment=
         'Comment with script<script type="text/javascript">alert("Danger")</script>'
     )
     self.assertEqual(
         dict(ok=True),
         post_metric_attribute(METRIC_ID, "comment", self.database))
     self.database.reports.insert.assert_called_once_with(self.report)
     self.assertEqual(
         dict(
             uuids=[REPORT_ID, SUBJECT_ID, METRIC_ID],
             email=JOHN["email"],
             description=
             "John changed the comment of metric 'name' of subject 'Subject' in report 'Report' "
             "from '' to 'Comment with script'."), self.report["delta"])
Ejemplo n.º 16
0
 def test_post_metric_debt_end_date_with_measurements(self, request):
     """Test that changing the metric debt end date adds a new measurement if one or more exist."""
     self.database.measurements.find_one.return_value = dict(
         _id="id", metric_uuid=METRIC_ID, sources=[])
     self.database.measurements.insert_one.side_effect = self.set_measurement_id
     request.json = dict(debt_end_date="2019-06-07")
     count = dict(value=None,
                  status=None,
                  target="0",
                  near_target="10",
                  debt_target=None,
                  direction="<")
     new_measurement = dict(end="2019-01-01",
                            sources=[],
                            start="2019-01-01",
                            metric_uuid=METRIC_ID,
                            count=count)
     self.assertEqual(
         new_measurement,
         post_metric_attribute(METRIC_ID, "debt_end_date", self.database))
     self.assert_delta(
         "debt_end_date of metric 'name' of subject 'Subject' in report 'Report' from '' to '2019-06-07'"
     )
Ejemplo n.º 17
0
 def test_post_metric_target_with_measurements(self, request):
     """Test that changing the metric target adds a new measurement if one or more exist."""
     self.database.measurements.find_one.return_value = dict(
         _id="id", metric_uuid=METRIC_ID, sources=[])
     self.database.measurements.insert_one.side_effect = self.set_measurement_id
     request.json = dict(target="10")
     self.assertEqual(
         dict(
             end="2019-01-01",
             sources=[],
             start="2019-01-01",
             metric_uuid=METRIC_ID,
             count=dict(status=None,
                        value=None,
                        target="10",
                        near_target="10",
                        debt_target=None,
                        direction="<"),
         ),
         post_metric_attribute(METRIC_ID, "target", self.database),
     )
     self.assert_delta(
         "target of metric 'name' of subject 'Subject' in report 'Report' from '0' to '10'"
     )