def test_total_count_with_ca(self, limit, expected_count): """Test total related assessments count for assessments with ca. The left outer join in our eager query on custom attribute values breaks the total count if on sa.func.count, but works if we use query.count() """ cad = factories.CustomAttributeDefinitionFactory cads = [cad(definition_type="assessment") for _ in range(3)] for cad in cads: factories.CustomAttributeValueFactory( attributable=self.assessment1, custom_attribute=cad, ) factories.CustomAttributeValueFactory( attributable=self.assessment2, custom_attribute=cad, ) with mock.patch("ggrc.views.start_compute_attributes"): views.do_full_reindex() response_json = self._get_related_assessments(self.control, **limit).json self.assertEqual(response_json["total"], expected_count)
def test_total_count_with_ca(self, limit, expected_count): """Test total related assessments count for assessments with ca. The left outer join in our eager query on custom attribute values breaks the total count if on sa.func.count, but works if we use query.count() """ cad = factories.CustomAttributeDefinitionFactory cads = [cad(definition_type="assessment") for _ in range(3)] for cad in cads: factories.CustomAttributeValueFactory( attributable=self.assessment1, custom_attribute=cad, ) factories.CustomAttributeValueFactory( attributable=self.assessment2, custom_attribute=cad, ) with mock.patch("ggrc.views.start_compute_attributes"): views.do_full_reindex() response = self._get_related_assessments(self.control, **limit).json self.assertEqual(response["total"], expected_count)