Exemplo n.º 1
0
 def test_instance_from_dict_should_not_raise_error_for_unicode_id(self):
     indicator_dict = dict(
         service='service',
         id=u'indicator-id',
         description='Indicator description',
         categories=[]
     )
     Indicator.instance_from_dict(indicator_dict, context=None)
Exemplo n.º 2
0
 def test_instance_from_dict_no_id(self):
     indicator_dict = dict(
         service='service',
         description='Indicator description',
         categories=[],
     )
     with self.assertRaises(ValueError) as context:
         Indicator.instance_from_dict(indicator_dict, context=None)
     self.assertEqual(
         "No 'id' found in the dictionary", context.exception.message)
Exemplo n.º 3
0
 def test_instance_from_dict_invalid_type_id(self):
     indicator_dict = dict(
         service='service',
         id=1,
         description='Indicator description',
         categories=[]
     )
     with self.assertRaises(ValueError) as context:
         Indicator.instance_from_dict(indicator_dict, context=None)
     self.assertEqual(
         "'id' must be a string",
         context.exception.message)
Exemplo n.º 4
0
 def test_instance_from_dict_empty_id(self):
     indicator_dict = dict(
         service='service',
         id='',
         description='Indicator description',
         categories=[]
     )
     with self.assertRaises(ValueError) as context:
         Indicator.instance_from_dict(indicator_dict, context=None)
     self.assertEqual(
         "'id' cannot be empty",
         context.exception.message)
Exemplo n.º 5
0
    def test_instance_from_dict_valid(self):
        indicator_dict = dict(
            service='service',
            id='indicator-id',
            description='indicator-description',
            categories=[dict(id='category-id-1'), dict(id='category-id-2')]
        )

        def mock_instance_from_dict(category_dict, context):
            return Mock(id=category_dict['id'], context=context)
        with patch(
                'genweb.core.indicators.model.Category.instance_from_dict',
                side_effect=mock_instance_from_dict):
            indicator = Indicator.instance_from_dict(indicator_dict, "context")

        self.assertEqual('service', indicator.service)
        self.assertEqual('indicator-id', indicator.id)
        self.assertEqual('indicator-description', indicator.description)
        self.assertEqual(2, len(indicator.categories))
        self.assertEqual(
            "context", indicator.categories['category-id-1'].context)
        self.assertEqual(
            indicator, indicator.categories['category-id-1'].indicator)
        self.assertEqual(
            "context", indicator.categories['category-id-2'].context)
        self.assertEqual(
            indicator, indicator.categories['category-id-2'].indicator)
Exemplo n.º 6
0
 def test_report_should_not_raise_error_if_valid_type(self):
     reporter = WebServiceReporter("url", "api_key")
     with patch(
             'genweb.core.indicators.reporter.WebServiceReporter._report_registry',
             side_effect=(None,)):
         reporter.report(Registry('context'))
     with patch(
             'genweb.core.indicators.reporter.WebServiceReporter._report_indicator_dict',
             side_effect=(None,)):
         reporter.report({})
     with patch(
             'genweb.core.indicators.reporter.WebServiceReporter._report_indicator',
             side_effect=(None,)):
         reporter.report(Indicator('service', 'id', 'description'))
     with patch(
             'genweb.core.indicators.reporter.WebServiceReporter._report_category',
             side_effect=(None,)):
         reporter.report(Category(
             'id', 'description', 'type', 'frequency', 'calculator'))
Exemplo n.º 7
0
 def test_instance_from_dict_invalid_type(self):
     with self.assertRaises(TypeError):
         Indicator.instance_from_dict(None, context=None)