Exemplo n.º 1
0
    def test_update_resource_catalogue_cache_unsupported_resource(self):

        mac1, mac2 = self.build_mac_mocks()

        parser_mac1 = Mock()
        parser_mac1.get_resource_info.return_value = "mac1_json"

        orm = Mock()
        orm.CatalogueResource.objects.all.return_value = TestQueryResult(
            [mac1, mac2])
        with patch.multiple('wirecloud.catalogue.utils',
                            WgtFile=DEFAULT,
                            TemplateParser=DEFAULT,
                            autospec=True) as context:
            context['TemplateParser'].side_effect = (
                parser_mac1, TemplateParseException('test'))

            with self.settings(
                    WIRECLOUD_REMOVE_UNSUPPORTED_RESOURCES_MIGRATION=False):
                self.assertRaises(Exception, update_resource_catalogue_cache,
                                  orm)

        # It's not important if update_resource_catalogue_cache calls to the save method of mac1,
        # as it will be rolled back by the db engine
        self.assertFalse(mac1.delete.called)
        self.assertFalse(mac2.save.called)
        self.assertFalse(mac2.delete.called)
Exemplo n.º 2
0
    def test_update_resource_catalogue_cache_autoremove_unsupported_resource(
            self):

        mac1, mac2 = self.build_mac_mocks()

        parser_mac1 = Mock()
        parser_mac1.get_resource_info.return_value = "mac1_json"

        orm = Mock()
        orm.CatalogueResource.objects.all.return_value = TestQueryResult(
            [mac1, mac2])
        with patch.multiple('wirecloud.catalogue.utils',
                            WgtFile=DEFAULT,
                            TemplateParser=DEFAULT,
                            autospec=True) as context:
            context['TemplateParser'].side_effect = (
                parser_mac1, TemplateParseException('test'))

            with self.settings(
                    WIRECLOUD_REMOVE_UNSUPPORTED_RESOURCES_MIGRATION=True):
                update_resource_catalogue_cache(orm)

        self.assertTrue(mac1.save.called)
        self.assertFalse(mac1.delete.called)
        self.assertTrue(mac2.delete.called)
Exemplo n.º 3
0
 def test_wgt_upload_parse_exception(self, install_component):
     c = Client()
     c.login(username='******', password='******')
     install_component.side_effect = TemplateParseException('test')
     with open(
             os.path.join(os.path.dirname(__file__),
                          'test-data/basic_widget.wgt'), 'rb') as f:
         response = c.post(self.resource_collection_url, {'file': f},
                           HTTP_HOST='www.example.com')
     self.assertEqual(response.status_code, 400)