def test_search_measurement3(self): """ Should return one measurement that matches the rating, assessment combo. One measurement relates to an assessment that is not in the scope of the search. """ template1 = TemplateFactory() template2 = TemplateFactory() attribute1 = AttributeFactory(template=template1) attribute2 = AttributeFactory(template=template2) rating = RatingFactory(attribute=attribute1) assessment1 = AssessmentFactory(template=template1) assessment2 = AssessmentFactory(template=template2) measurement1 = MeasurementFactory(assessment=assessment1, attribute=attribute1, rating=rating) measurement2 = MeasurementFactory(assessment=assessment2, attribute=attribute2, rating=rating) url = "%s?assessment__id=%s&rating__attribute=%s" % ( reverse('measurement-list'), assessment1.id, attribute1.id) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data[0]['id'], measurement1.id) self.assertEqual(response.data[0]['rating'], rating.id) self.assertEqual(len(response.data), 1)
def test_creation_of_rating(self): template = TemplateFactory() attribute = AttributeFactory(template=template) rating = RatingFactory(attribute=attribute, rank=1) rating.clean() self.assertEqual( "%s - %s - %s" % (template.name, attribute.name, rating.name), str(rating))
def test_fail_measurement_with_rating_from_different_template(self): """ Don't create measurements referring to rating from a different template than the assessment """ template1 = TemplateFactory() attribute1 = AttributeFactory(template=template1) rating1 = RatingFactory(attribute=attribute1) assessment = AssessmentFactory(template=template1) template2 = TemplateFactory() attribute2 = AttributeFactory(template=template2) rating2 = RatingFactory(attribute=attribute2) measurement1 = MeasurementFactory(assessment=assessment, attribute=attribute1, rating=rating2) self.assertRaises(ValidationError, measurement1.clean) measurement2 = MeasurementFactory(assessment=assessment, attribute=attribute2, rating=rating1, target_rating=rating2) self.assertRaises(ValidationError, measurement2.clean)
def test_creation_of_measurement_no_target(self): """ Should be able to create a measurement without a target_rating """ template = TemplateFactory() attribute = AttributeFactory(template=template) assessment = AssessmentFactory(template=template) rating = RatingFactory(attribute=attribute) measurement = MeasurementFactory(assessment=assessment, attribute=attribute, rating=rating) measurement.clean() self.assertEqual(1, Measurement.objects.count()) self.assertEqual( "%s - %s - %s" % (str(assessment), attribute.name, rating.name), str(measurement))
def test_creation_of_measurement(self): """ Create a measurement with all fields specified """ template = TemplateFactory() attribute = AttributeFactory(template=template) rating = RatingFactory(attribute=attribute) target_rating = RatingFactory(attribute=attribute) assessment = AssessmentFactory(template=template) measurement = MeasurementFactory(assessment=assessment, attribute=attribute, rating=rating, target_rating=target_rating) measurement.clean() self.assertEqual(1, Measurement.objects.count()) self.assertEqual( "%s - %s - %s" % (str(assessment), attribute.name, rating.name), str(measurement))
def test_search_measurement2(self): """ Should return zero measurements as the api search is for a different assessment """ template = TemplateFactory() attribute = AttributeFactory(template=template) rating_in_scope1 = RatingFactory(attribute=attribute) rating_in_scope2 = RatingFactory(attribute=attribute) assessment1 = AssessmentFactory(template=template) assessment2 = AssessmentFactory(template=template) assessment3 = AssessmentFactory() measurement1 = MeasurementFactory(assessment=assessment1, attribute=attribute, rating=rating_in_scope1) measurement2 = MeasurementFactory(assessment=assessment2, attribute=attribute, rating=rating_in_scope2) url = "%s?assessment__id=%s&rating__attribute=%s" % ( reverse('measurement-list'), assessment3.id, attribute.id) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 0)
def test_creation_of_attribute(self): template = TemplateFactory() attribute = AttributeFactory(template=template) attribute.clean() self.assertEqual("%s - %s" % (template.name, attribute.name), str(attribute))