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__init_maps_valid(self):
"""Layout should raise an error if any element in the map list is not a Map"""
msg = 'All the elements in the Layout should be an instance of Map'
with pytest.raises(CartoException) as e:
Layout([Layer(Source(SOURCE))])
assert str(e.value) == msg
def test_initialization_objects(self):
"""Layer should initialize layer attributes"""
layer = Layer(Source('layer_source'))
self.assertFalse(layer.is_basemap)
self.assertEqual(layer.orig_query, 'SELECT * FROM "public"."layer_source"')
self.assertTrue(isinstance(layer.source, Source))
self.assertTrue(isinstance(layer.style, Style))
self.assertTrue(isinstance(layer.popup, Popup))
self.assertTrue(isinstance(layer.legend, Legend))
self.assertEqual(layer.interactivity, [])
def test_map_publish_unsync_sync_data_and_publish(self):
query = "SELECT 1"
dataset = DatasetMock.from_query(query=query, context=self.context)
dataset._is_saved_in_carto = False
map = MapMock(Layer(Source(dataset)))
map.sync_data(table_name='fake_table', context=self.context)
name = 'cf_publish'
kuviz = map.publish(name, context=self.context)
self.assertIsNotNone(kuviz.vid)
self.assertIsNotNone(kuviz.url)
self.assertEqual(kuviz.name, name)
self.assertEqual(kuviz.privacy, KuvizMock.PRIVACY_PUBLIC)
def test_kuviz_publisher_from_local_sync(self):
source_1 = Source(build_geojson([-10, 0], [-10, 0]))
layer_1 = Layer(source_1)
vmap = Map(layer_1)
kp = KuvizPublisherMock(vmap.layers)
self.assertEqual(kp.is_sync(), False)
def test_two_layers(self):
"""Map layer should be able to initialize two layers in the correct order"""
source_1 = Source(build_cartodataframe([-10, 0], [-10, 0]))
source_2 = Source(build_cartodataframe([0, 10], [10, 0]))
layer_1 = Layer(source_1)
layer_2 = Layer(source_2)
map = Map([layer_1, layer_2])
assert map.layers == [layer_1, layer_2]
assert len(map.layer_defs) == 2
def test_map_publish_remote(self):
dataset = DatasetMock.from_table(table_name='fake_table', context=self.context)
map = MapMock(Layer(Source(dataset)))
name = 'cf_publish'
kuviz = map.publish(name, context=self.context)
self.assertIsNotNone(kuviz.vid)
self.assertIsNotNone(kuviz.url)
self.assertEqual(kuviz.name, name)
self.assertEqual(kuviz.privacy, KuvizMock.PRIVACY_PUBLIC)
def test_kuviz_publisher_publish(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 = kuviz_publisher.publish(html, kuviz_name, None)
assert kuviz_publisher.kuviz == kuviz
assert result == kuviz_to_dict(kuviz)
def test_style_dict_valid_properties(self):
"""Layer style should set only the valid properties"""
with self.assertRaises(ValueError):
Layer(
'layer_source',
{
'invalid': 1
}
def test_kuviz_publisher_unsync(self):
dataset = DatasetMock(build_geojson([-10, 0], [-10, 0]))
vmap = Map(Layer(Source(dataset)))
kp = KuvizPublisherMock(vmap.layers)
self.assertEqual(kp.is_sync(), False)
def test_kuviz_publisher_use_only_base_url(self, mocker):
credentials = Credentials(base_url='https://fakeuser.carto.com')
setup_mocks(mocker, credentials)
vmap = Map(Layer('fake_table', credentials=credentials))
kuviz_publisher = KuvizPublisher(None)
kuviz_publisher.set_layers(vmap.layers, 'fake_name', 'fake_table_name')
layers = kuviz_publisher.get_layers()
assert layers[0].source.credentials == credentials
assert layers[0].credentials == ({
'username': 'user', # Default VL username
'api_key': DEFAULT_PUBLIC,
'base_url': 'https://fakeuser.carto.com'})