class DMLayersTest(TestCase):
    def setUp(self):
        self.dml = DMLayers()

    def test_get_404(self):
        self.assertIsNone(self.dml.get('namnam', 'cfr', 'verver/lablab'))

    def test_get_success(self):
        Layer(name='namnam', doc_type='cfr', doc_id='verver/lablab',
              layer={"some": "body"}).save()

        self.assertEqual({"some": 'body'},
                         self.dml.get('namnam', 'cfr', 'verver/lablab'))

    def test_bulk_put(self):
        """Writing multiple documents should save correctly. They can be
        modified"""
        layers = [{'111-22': [], '111-22-a': [], 'doc_id': 'verver/111-22'},
                  {'111-23': [], 'doc_id': 'verver/111-23'}]
        self.dml.bulk_put(layers, 'name', 'cfr', 'verver/111')

        self.assertEqual(Layer.objects.count(), 2)
        self.assertEqual(self.dml.get('name', 'cfr', 'verver/111-22'),
                         {'111-22': [], '111-22-a': []})
        self.assertEqual(self.dml.get('name', 'cfr', 'verver/111-23'),
                         {'111-23': []})

        layers[1] = {'111-23': [1], 'doc_id': 'verver/111-23'}
        self.dml.bulk_put(layers, 'name', 'cfr', 'verver/111')

        self.assertEqual(Layer.objects.count(), 2)
        self.assertEqual(self.dml.get('name', 'cfr', 'verver/111-23'),
                         {'111-23': [1]})
Ejemplo n.º 2
0
class SplitterLayers(object):
    """Implementation of Django+Elastic Search as layers backend"""
    def __init__(self):
        self.dm = DMLayers()
        self.es = ESLayers()

        self.get = self.dm.get

    def bulk_put(self, layers, version, layer_name, root_label):
        """Write to both"""
        self.dm.bulk_put(layers, version, layer_name, root_label)
        self.es.bulk_put(layers, version, layer_name, root_label)
def test_layer_bulk_insert():
    """Writing multiple documents should save correctly. They can be
    modified"""
    dml = DMLayers()
    layers = [{'111-22': [], '111-22-a': [], 'doc_id': 'verver/111-22'},
              {'111-23': [], 'doc_id': 'verver/111-23'}]
    dml.bulk_insert(layers, 'name', 'cfr')

    assert Layer.objects.count() == 2
    assert dml.get('name', 'cfr', 'verver/111-22') == {'111-22': [],
                                                       '111-22-a': []}
    assert dml.get('name', 'cfr', 'verver/111-23') == {'111-23': []}

    layers[1] = {'111-23': [1], 'doc_id': 'verver/111-23'}
    dml.bulk_delete('name', 'cfr', 'verver/111')
    dml.bulk_insert(layers, 'name', 'cfr')

    assert Layer.objects.count() == 2
    assert dml.get('name', 'cfr', 'verver/111-23') == {'111-23': [1]}
class DMLayersTest(TestCase, ReusableDMLayers):
    def setUp(self):
        Layer.objects.all().delete()
        self.dml = DMLayers()

    def test_bulk_put(self):
        layers = [
            {'111-22': [], '111-22-a': [], 'label': '111-22'},
            {'111-23': [], 'label': '111-23'}]
        self.dml.bulk_put(layers, 'verver', 'name', '111')

        layers = Layer.objects.all().order_by('label')
        self.assertEqual(2, len(layers))

        self.assertEqual('verver', layers[0].version)
        self.assertEqual('name', layers[0].name)
        self.assertEqual('111-22', layers[0].label)
        self.assertEqual({'111-22': [], '111-22-a': []}, layers[0].layer)

        self.assertEqual('verver', layers[1].version)
        self.assertEqual('name', layers[1].name)
        self.assertEqual('111-23', layers[1].label)
        self.assertEqual({'111-23': []}, layers[1].layer)

    def test_bulk_put_overwrite(self):
        layers = [{'111-23': [], 'label': '111-23'}]
        self.dml.bulk_put(layers, 'verver', 'name', '111-23')

        layers = Layer.objects.all()
        self.assertEqual(1, len(layers))
        self.assertEqual({'111-23': []}, layers[0].layer)

        layers = [{'111-23': [1], 'label': '111-23'}]
        self.dml.bulk_put(layers, 'verver', 'name', '111-23')

        layers = Layer.objects.all()
        self.assertEqual(1, len(layers))
        self.assertEqual({'111-23': [1]}, layers[0].layer)
Ejemplo n.º 5
0
    def __init__(self):
        self.dm = DMLayers()
        self.es = ESLayers()

        self.get = self.dm.get
def test_layer_get_success():
    Layer.objects.create(name='namnam',
                         doc_type='cfr',
                         doc_id='verver/lablab',
                         layer={"some": "body"})
    assert DMLayers().get('namnam', 'cfr', 'verver/lablab') == {'some': 'body'}
def test_layer_get_404():
    assert DMLayers().get('namnam', 'cfr', 'verver/lablab') is None
 def setUp(self):
     self.dml = DMLayers()
 def setUp(self):
     Layer.objects.all().delete()
     self.dml = DMLayers()
 def setUp(self):
     self.dml = DMLayers()
Ejemplo n.º 11
0
    def __init__(self):
        self.dm = DMLayers()
        self.es = ESLayers()

        self.get = self.dm.get