Ejemplo n.º 1
0
 def setUp(self):
     self.workspace = WorkspaceEdit()
     self.workspace.save()
     workspace_item = WorkspaceEditItem(workspace=self.workspace)
     workspace_item.save()
     layer_arguments = {}
     self.adapter = WorkspaceItemAdapter(workspace_item, layer_arguments)
Ejemplo n.º 2
0
 def test_entry_point_lookup(self):
     """The string that identifies a method is looked up as a so-called
     entry point."""
     workspace_item = WorkspaceEditItem()
     workspace_item.adapter_class = 'adapter_dummy'
     workspace_item.adapter_layer_json = ("{}")
     self.assertTrue(isinstance(
             workspace_item.adapter,
             lizard_map.layers.AdapterDummy))
Ejemplo n.º 3
0
 def test_adapter_arguments(self):
     """The layer method probably needs arguments. You can store them as a
     json string."""
     workspace_item = WorkspaceEditItem()
     self.assertTrue(isinstance(workspace_item._adapter_layer_arguments,
                                dict))
     self.assertFalse(len(workspace_item._adapter_layer_arguments))
     workspace_item.adapter_layer_json = '{"bla": "yes"}'
     self.assertEquals(workspace_item._adapter_layer_arguments['bla'],
                       'yes')
Ejemplo n.º 4
0
 def insert_risk_layer(self):
     special_name = self.area.slug + ' risk layer'
     workspace = self.workspace()
     if workspace.workspace_items.filter(name=special_name).exists():
         return
     adapter_json = '{"slug": "%s"}' % self.area.slug
     workspace_item = WorkspaceEditItem(
         workspace=workspace,
         name=special_name,
         adapter_class='lizard_levee_risk_adapter',
         adapter_layer_json=adapter_json,
         index=200)
     workspace_item.save()
     logger.debug("Added special workspace item")
Ejemplo n.º 5
0
class AdapterTest(TestCase):
    def setUp(self):
        self.workspace = WorkspaceEdit()
        self.workspace.save()
        self.workspace_item = WorkspaceEditItem(workspace=self.workspace)
        self.workspace_item.save()

    def init_adapter(self, layer_arguments, project,
                     contractor, measurement_type):
        # Create adapter with given layer_arguments
        self.adapter = ProgressAdapter(workspace_item=self.workspace_item,
                                       layer_arguments=layer_arguments)

        # Check if project, contractor and measurement_type are as expected
        self.assertEquals(self.adapter.project, project)
        self.assertEquals(self.adapter.contractor, contractor)
        self.assertEquals(self.adapter.measurement_type, measurement_type)

    def test_empty_adapter(self):
        self.init_adapter({}, None, None, None)

    def test_unexisting_adapter(self):
        self.init_adapter({'project_slug': 'wheeeeeee'}, None, None, None)

    def test_weird_adapter_input(self):
        self.assertRaises(
            ValueError, self.init_adapter, None, None, None, None)

    def test_full_adapter(self):
        project = Project(
            slug='test', organization=Organization.objects.create(name="test"))
        project.save()
        contractor = Contractor(slug='contractor')
        contractor.project = project
        contractor.save()
        available_measurement_type = AvailableMeasurementType(slug='mtype')
        available_measurement_type.save()
        measurement_type = MeasurementType(mtype=available_measurement_type)
        measurement_type.project = project
        measurement_type.save()

        self.init_adapter({
                'project_slug': 'test',
                'contractor_slug': 'contractor',
                'measurement_type_slug': 'mtype',
                }, project, contractor, measurement_type)
Ejemplo n.º 6
0
    def test_item_edit_as_storage(self):
        """WorkspaceEditItem to WorkspaceStorageItem conversion."""
        workspace_item_edit = WorkspaceEditItem(
            workspace=self.workspace_edit)
        workspace_item_edit.save()

        workspace_storage_item = workspace_item_edit.as_storage(
            workspace=self.workspace_storage)
        workspace_storage_item.save()  # Do not crash.

        # This dict does not have _state, _workspace_cache, workspace_id
        edit_dict = workspace_item_edit.__dict__

        storage_dict = workspace_storage_item.__dict__

        # _workspace_cache does not appear in other code... strange?
        del storage_dict['id']
        del storage_dict['_state']
        del storage_dict['_workspace_cache']
        del storage_dict['workspace_id']

        self.assertEquals(edit_dict, storage_dict)
Ejemplo n.º 7
0
 def setUp(self):
     self.workspace = WorkspaceEdit()
     self.workspace.save()
     self.workspace_item = WorkspaceEditItem(workspace=self.workspace)
     self.workspace_item.save()