Repository: CartoDB/cartoframes
Pull request #1172 (2019-11-07 10:17:03)

Fix viewport in published maps
Fixes https://github.com/CartoDB/cartoframes/issues/1128


Patch:
diff --git a/cartoframes/auth/defaults.py b/cartoframes/auth/defaults.py
index 91e21bb0..1009f987 100644
--- a/cartoframes/auth/defaults.py
+++ b/cartoframes/auth/defaults.py
@@ -151,9 +151,8 @@ def set_default_credentials(
     if isinstance(_credentials, Credentials):
         _default_credentials = _credentials
 
-    elif isinstance(_filepath, str):
-        if _is_json_filepath(_filepath):
-            _default_credentials = Credentials.from_file(_filepath)
+    elif isinstance(_filepath, str) and _is_json_filepath(_filepath):
+        _default_credentials = Credentials.from_file(_filepath)
 
     elif isinstance(_base_url or _username, str) and isinstance(_api_key, str):
         if _base_url and _is_url(_base_url):
diff --git a/cartoframes/viz/map.py b/cartoframes/viz/map.py
index 4dbf90a7..57025172 100644
--- a/cartoframes/viz/map.py
+++ b/cartoframes/viz/map.py
@@ -339,16 +339,17 @@ class Map(object):
             layers=_get_layer_defs(self._publisher.get_layers()),
             bounds=self.bounds,
             size=None,
+            camera=self.camera,
             basemap=self.basemap,
             default_legend=self.default_legend,
             show_info=False,
             theme=self.theme,
-            _carto_vl_path=self._carto_vl_path,
-            _airship_path=self._airship_path,
             title=name,
             description=self.description,
+            is_static=self.is_static,
             is_embed=True,
-            is_static=self.is_static)
+            _carto_vl_path=self._carto_vl_path,
+            _airship_path=self._airship_path)
 
         return html_map.html
 


Test patch:
diff --git a/tests/unit/viz/test_map.py b/tests/unit/viz/test_map.py
index 68ba4357..3c01f70e 100644
--- a/tests/unit/viz/test_map.py
+++ b/tests/unit/viz/test_map.py
@@ -238,8 +238,9 @@ class TestMapPublication(unittest.TestCase):
         assert kuviz_dict['name'] == name
         assert kuviz_dict['privacy'] == privacy
 
+    @patch('cartoframes.viz.html.html_map.HTMLMap.set_content')
     @patch('cartoframes.viz.map._get_publisher')
-    def test_map_publish_remote(self, _get_publisher):
+    def test_map_publish_remote_default(self, _get_publisher, mock_set_content):
         _get_publisher.return_value = KuvizPublisherMock()
 
         dataset = Dataset('fake_table', credentials=self.credentials)
@@ -248,6 +249,60 @@ class TestMapPublication(unittest.TestCase):
         name = 'cf_publish'
         kuviz_dict = vmap.publish(name)
         self.assert_kuviz_dict(kuviz_dict, name, PRIVACY_PUBLIC)
+        mock_set_content.assert_called_once_with(
+            _airship_path=None,
+            _carto_vl_path=None,
+            basemap='Positron',
+            bounds=[[-180, -90], [180, 90]],
+            camera=None,
+            default_legend=False,
+            description=None,
+            is_embed=True,
+            is_static=None,
+            layers=[],
+            show_info=False,
+            size=None,
+            theme=None,
+            title='cf_publish'
+        )
+
+    @patch('cartoframes.viz.html.html_map.HTMLMap.set_content')
+    @patch('cartoframes.viz.map._get_publisher')
+    def test_map_publish_remote_params(self, _get_publisher, mock_set_content):
+        _get_publisher.return_value = KuvizPublisherMock()
+
+        dataset = Dataset('fake_table', credentials=self.credentials)
+        vmap = Map(
+            Layer(dataset),
+            basemap='yellow',
+            bounds={'west': 1, 'east': 2, 'north': 3, 'south': 4},
+            viewport={'zoom': 5, 'lat': 50, 'lng': -10},
+            default_legend=True,
+            is_static=True,
+            theme='dark',
+            title='title',
+            description='description'
+        )
+
+        name = 'cf_publish'
+        kuviz_dict = vmap.publish(name)
+        self.assert_kuviz_dict(kuviz_dict, name, PRIVACY_PUBLIC)
+        mock_set_content.assert_called_once_with(
+            _airship_path=None,
+            _carto_vl_path=None,
+            basemap='yellow',
+            bounds=[[1, 2], [4, 3]],
+            camera={'bearing': None, 'center': [-10, 50], 'pitch': None, 'zoom': 5},
+            default_legend=True,
+            description='description',
+            is_embed=True,
+            is_static=True,
+            layers=[],
+            show_info=False,
+            size=None,
+            theme='dark',
+            title='cf_publish'
+        )
 
     @patch('cartoframes.viz.map._get_publisher')
     def test_map_publish_with_password(self, _get_publisher):