def test_setup_template_variables(self, resource_format, url, auth_type,
                                      error, p, h):
        instance = plugin.NgsiView()
        data_dict = {
            "resource": {
                "auth_type": auth_type,
                "format": resource_format,
                "url": url,
            }
        }
        instance.proxy_is_enabled = error != "noproxy"
        instance.oauth2_is_enabled = error != "nooauth2"
        p.toolkit.c.user = error != "nologged"

        with patch.object(instance,
                          "get_proxified_ngsi_url",
                          return_value="proxied_url"):
            result = instance.setup_template_variables(None, data_dict)

        view_enable = json.loads(result['view_enable'])
        self.assertEqual(result['resource_json'],
                         json.dumps(data_dict['resource']))

        if error is None:
            self.assertEqual(view_enable, [True, 'OK'])
            self.assertEqual(result['resource_url'], '"proxied_url"')
        else:
            h.flash_error.assert_called_with(ANY, allow_html=False)
            self.assertFalse(view_enable[0])
            self.assertNotEqual(view_enable[1], 'OK')
Beispiel #2
0
 def test_can_view(self, resource_format, resource_url, same_domain, proxy_enabled, expected, datapreview, p):
     instance = plugin.NgsiView()
     datapreview.on_same_domain.return_value = same_domain
     instance.proxy_is_enabled = proxy_enabled
     self.assertEqual(
         instance.can_view({'resource': {'format': resource_format, 'url': resource_url}}),
         expected
     )
 def test_can_view(self, resource_format, resource_url, proxy_enabled,
                   expected, p):
     instance = plugin.NgsiView()
     instance.proxy_is_enabled = proxy_enabled
     self.assertEqual(
         instance.can_view(
             {'resource': {
                 'format': resource_format,
                 'url': resource_url
             }}), expected)
    def test_before_create_missing_entity(self):
        instance = plugin.NgsiView()

        with self.assertRaises(ValidationError):
            instance.before_create({}, {'format': 'fiware-ngsi-registry'})
    def test_before_create(self, resource, serialized):
        instance = plugin.NgsiView()

        result = instance.before_create({}, resource)
        self.assertEquals(serialized, result)
    def test_before_show(self, resource, deserialized):
        instance = plugin.NgsiView()

        instance.before_show(resource)
        self.assertEquals(deserialized, resource)