Ejemplo n.º 1
0
    def test_url_two_sources(self):
        """ Test that the metric has no default url. """
        mock_metric_source = MagicMock()
        mock_metric_source.metric_source_urls.return_value = ['http:/url1', 'http:/url2']
        mock_metric_source.metric_source_name = "Text"
        subject = MagicMock()
        subject.metric_source_id.return_value = "MsId"
        project = MagicMock()
        project.metric_sources.return_value = [mock_metric_source]
        test_metric = domain.Metric(subject=subject, project=project)

        self.assertEqual({"Text (1/2)": "http:/url1", "Text (2/2)": "http:/url2"}, test_metric.url())
Ejemplo n.º 2
0
    def test_extra_info(self, mock_extra_info_rows):
        """ Test that extra_info, as a base class function, returns None. """
        mock_extra_info_rows.return_value = [('VAL1', 'VAL2')]
        project = MagicMock()
        project.metric_sources.return_value = [MagicMock()]
        metric = domain.Metric(subject=MagicMock(), project=project)
        metric.extra_info_headers = {"col1": "Col 1", "col2": "Col 2"}

        result = metric.extra_info()

        self.assertEqual(domain.ExtraInfo(col1="Col 1", col2="Col 2").headers, result.headers)
        self.assertEqual([{"col1": "VAL1", "col2": "VAL2"}], result.data)
Ejemplo n.º 3
0
    def test_url_from_metric_source_urls(self):
        """ Test metric url when there is no source id. """
        mock_metric_source = MagicMock()
        mock_metric_source.metric_source_urls.return_value = ['http://url!']
        mock_metric_source.metric_source_name = "Text"
        subject = MagicMock()
        subject.metric_source_id.return_value = "MsId"
        project = MagicMock()
        project.metric_sources.return_value = [mock_metric_source]
        test_metric = domain.Metric(subject=subject, project=project)

        self.assertEqual({"Text": 'http://url!'}, test_metric.url())
Ejemplo n.º 4
0
    def test_format_text_with_links(self, mock_metric_source_urls):
        """ Test that comment formatting function is the same as the text formatting one."""
        mock_metric_source_urls.return_value = ['http://url1']
        mock_metric_source = MagicMock()
        mock_metric_source.metric_source_name = "Text"
        project = MagicMock()
        project.metric_sources.return_value = [mock_metric_source]
        test_metric = domain.Metric(subject=MagicMock(), project=project)

        self.assertEqual(
            "Some text... [{'href': 'http://url1', 'text': 'Text'}]",
            test_metric.format_text_with_links('Some text...'))
Ejemplo n.º 5
0
    def test_url_metric_source_different_metric_source_urls(self):
        """ Test metric url when there are metric source urls. """
        mock_metric_source = MagicMock()
        mock_metric_source.metric_source_urls.return_value = [
            "metric source url"
        ]
        mock_metric_source.metric_source_name = "Text"

        subject = MagicMock()
        subject.metric_source_id.return_value = "MsId"
        project = MagicMock()
        project.metric_sources.return_value = [mock_metric_source]
        test_metric = domain.Metric(subject=subject, project=project)

        self.assertEqual({"Text": "metric source url"}, test_metric.url())
        mock_metric_source.metric_source_urls.assert_called_once_with('MsId')
Ejemplo n.º 6
0
    def test_url_metric_source_different_display(self):
        """ Test metric url when there is a display link. """
        mock_metric_source = MagicMock()
        mock_metric_source.metric_source_urls.return_value = [
            "metric source url"
        ]
        mock_metric_source.metric_source_name = "Text"

        subject = MagicMock()
        subject.metric_source_id.return_value = {
            "source": 'http:\\link',
            "display": 'http:\\display.url'
        }
        project = MagicMock()
        project.metric_sources.return_value = [mock_metric_source]
        test_metric = domain.Metric(subject=subject, project=project)

        self.assertEqual({"Text": "metric source url"}, test_metric.url())
        mock_metric_source.metric_source_urls.assert_called_once_with(
            'http:\\display.url')
Ejemplo n.º 7
0
    def test_url_metric_source_different_display_two_links(self):
        """ Test metric url when there are two links - one with a display link and the other without. """
        mock_metric_source = MagicMock()
        mock_metric_source.metric_source_urls.return_value = [
            "metric source url"
        ]
        mock_metric_source.metric_source_name = "Text"

        subject = MagicMock()
        subject.metric_source_id.return_value = [{
            "source":
            'http:\\link',
            "display":
            'http:\\display.url'
        }, "simple"]
        project = MagicMock()
        project.metric_sources.return_value = [mock_metric_source]
        test_metric = domain.Metric(subject=subject, project=project)

        self.assertEqual({"Text": "metric source url"}, test_metric.url())
        mock_metric_source.metric_source_urls.assert_called_once_with(
            'http:\\display.url', "simple")
Ejemplo n.º 8
0
 def test_stable_id_mutable_subject(self):
     """ Test that the stable id doesn't include the subject if the subject is a list. """
     self.assertEqual('Metric', domain.Metric([], project=domain.Project()).stable_id())