def test_no_change(self, request): """Test that no new report is inserted when the attribute is unchanged.""" request.json = dict(name="Source") self.assertEqual( dict(ok=True), post_source_attribute(SOURCE_ID, "name", self.database)) self.database.reports.insert.assert_not_called()
def test_post_source_type(self, request): """Test that the source type can be changed.""" request.json = dict(type="new_source_type") self.assertEqual( dict(ok=True), post_source_attribute(SOURCE_ID, "type", self.database)) self.database.reports.insert.assert_called_once_with(self.report) self.assert_delta( "type of source 'Source' of metric 'Metric' of subject 'Subject' in report 'Report' from 'source_type' to " "'new_source_type'")
def test_post_position(self, request): """Test that a metric can be moved.""" request.json = dict(position="first") self.assertEqual( dict(ok=True), post_source_attribute(SOURCE_ID2, "position", self.database)) self.database.reports.insert.assert_called_once_with(self.report) self.assertEqual([SOURCE_ID2, SOURCE_ID], list(self.report["subjects"][SUBJECT_ID]["metrics"] [METRIC_ID]["sources"].keys())) self.assert_delta( "position of source 'Source 2' of metric 'Metric' of subject 'Subject' in report 'Report' from '1' to '0'", [SOURCE_ID2], )
def test_post_source_type(self, request): """Test that the source type can be changed.""" request.json = dict(type="new_source_type") self.assertEqual( dict(ok=True), post_source_attribute(SOURCE_ID, "type", self.database)) self.database.reports.insert.assert_called_once_with(self.report) self.assertEqual( dict( uuids=[REPORT_ID, SUBJECT_ID, METRIC_ID, SOURCE_ID], email=self.email, description= "Jenny changed the type of source 'Source' of metric 'Metric' of subject 'Subject' in " "report 'Report' from 'source_type' to 'new_source_type'."), self.report["delta"])
def test_post_position(self, request): """Test that a metric can be moved.""" request.json = dict(position="first") self.assertEqual( dict(ok=True), post_source_attribute(SOURCE_ID2, "position", self.database)) self.database.reports.insert.assert_called_once_with(self.report) self.assertEqual([SOURCE_ID2, SOURCE_ID], list(self.report["subjects"][SUBJECT_ID]["metrics"] [METRIC_ID]["sources"].keys())) self.assertEqual( dict( uuids=[REPORT_ID, SUBJECT_ID, METRIC_ID, SOURCE_ID2], email=self.email, description= "Jenny changed the position of source 'Source 2' of metric 'Metric' of subject 'Subject' " "in report 'Report' from '1' to '0'."), self.report["delta"])