Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_one_layer(self):
"""Map layer should be able to initialize one layer"""
source = Source(build_geojson([-10, 0], [-10, 0]))
layer = Layer(source)
map = Map(layer)
self.assertEqual(map.layers, [layer])
self.assertEqual(len(map.sources), 1)
self.assertEqual(map.sources[0].get('interactivity'), [])
self.assertIsNotNone(map.sources[0].get('credentials'))
self.assertIsNone(map.sources[0].get('legend'))
self.assertIsNotNone(map.sources[0].get('query'))
self.assertEqual(map.sources[0].get('type'), 'GeoJSON')
self.assertIsNotNone(map.sources[0].get('viz'))
def test_custom_airship_path(self):
"""Map dev path should use custom paths"""
_airship_path = 'custom_airship_path'
map = Map(_airship_path=_airship_path)
map._repr_html_()
template = map._html_map.html
assert _airship_path + constants.AIRSHIP_COMPONENTS_DEV in template
assert _airship_path + constants.AIRSHIP_BRIDGE_DEV in template
assert _airship_path + constants.AIRSHIP_STYLES_DEV in template
assert _airship_path + constants.AIRSHIP_MODULE_DEV in template
assert _airship_path + constants.AIRSHIP_ICONS_DEV in template
def test_custom_carto_vl_path(self):
"""Map dev path should use custom paths"""
_carto_vl_path = 'custom_carto_vl_path'
map = Map(_carto_vl_path=_carto_vl_path)
map._repr_html_()
template = map._htmlMap.html
self.assertTrue(_carto_vl_path + constants.CARTO_VL_DEV in template)
def test_kuviz_publisher_create_remote(self):
dataset = DatasetMock('fake_table', credentials=self.credentials)
vmap = Map(Layer(Source(dataset)))
kp = KuvizPublisherMock(vmap.layers)
self.assertNotEqual(kp._layers, vmap.layers)
self.assertEqual(len(kp._layers), len(vmap.layers))
def test_kuviz_publisher_sync_layers(self):
dataset = DatasetMock(build_geojson([-10, 0], [-10, 0]))
vmap = Map(Layer(Source(dataset)))
kp = KuvizPublisherMock(vmap.layers)
kp.sync_layers(table_name='fake_table', credentials=self.credentials)
self.assertEqual(kp.is_sync(), True)
def test_kuviz_publisher_update(self, mocker):
setup_mocks(mocker, self.credentials)
kuviz = CartoKuvizMock('fake_kuviz')
mocker.patch('cartoframes.viz.kuviz._create_kuviz', return_value=kuviz)
vmap = Map(Layer('fake_table', credentials=self.credentials))
html = 'fake_html'
kuviz_name = 'fake_name'
kuviz_publisher = KuvizPublisher(None)
kuviz_publisher.set_layers(vmap.layers, kuviz_name, 'fake_table_name')
result_publish = kuviz_publisher.publish(html, kuviz_name, None)
kuviz.name = 'fake_name_2'
result_update = kuviz_publisher.update(html, kuviz_name, None)
assert kuviz_publisher.kuviz == kuviz
assert result_update == kuviz_to_dict(kuviz)
assert result_publish != kuviz_to_dict(kuviz)
def test_kuviz_publisher_has_layers_copy(self, mocker):
setup_mocks(mocker, self.credentials)
source_1 = Source('fake_table_2', credentials=self.credentials)
layer_1 = Layer(source_1)
vmap = Map([layer_1])
kuviz_publisher = KuvizPublisher(None)
kuviz_publisher.set_layers(vmap.layers, 'fake_name', 'fake_table_name')
assert len(kuviz_publisher._layers) == len(vmap.layers)
assert kuviz_publisher._layers == vmap.layers
vmap.layers = []
assert len(kuviz_publisher._layers) != len(vmap.layers)
assert len(kuviz_publisher._layers) > 0
def test_custom_airship_path(self):
"""Map dev path should use custom paths"""
_airship_path = 'custom_airship_path'
map = Map(_airship_path=_airship_path)
map._repr_html_()
template = map._htmlMap.html
self.assertTrue(_airship_path + constants.AIRSHIP_COMPONENTS_DEV in template)
self.assertTrue(_airship_path + constants.AIRSHIP_BRIDGE_DEV in template)
self.assertTrue(_airship_path + constants.AIRSHIP_STYLES_DEV in template)
self.assertTrue(_airship_path + constants.AIRSHIP_MODULE_DEV in template)
self.assertTrue(_airship_path + constants.AIRSHIP_ICONS_DEV in template)
def test_map_publish_update_password(self, mocker):
setup_mocks(mocker)
map = Map(Layer(Source('fake_table', credentials=self.credentials)))
name = 'cf_publish'
map.publish(name, None, credentials=self.credentials)
kuviz_dict = map.update_publication(name, '1234"')
self.assert_kuviz_dict(kuviz_dict, name, 'password')
def map(self, *args, ** kwargs):
"""Renders the data in a CARTO map.
Returns:
:py:class:`Map `
"""
from ..viz import Map, Layer
return Map(Layer(self, *args, **kwargs))