Example #1
0
    def test_copy_data_turns_off_and_on_services(self, copytree_mock,
                                                 rmtree_mock, move,
                                                 exists_mock, compact_mock,
                                                 describe_mock,
                                                 lightswitch_mock):
        describe_mock.side_effect = describe_side_effect
        exists_mock.return_value = True
        lightswitch_mock().ensure.return_value = (True, [])
        three = 'C:\\MapData\\three.gdb'
        two = 'C:\\MapData\\two.gdb'

        pallet_one = Pallet()
        pallet_one.copy_data = ['C:\\MapData\\one.gdb', two]
        pallet_one.arcgis_services = [('Pallet', 'MapServer')]
        pallet_one.requires_processing = Mock(return_value=True)

        pallet_two = Pallet()
        pallet_two.copy_data = ['C:\\MapData\\one.gdb', three]
        pallet_two.arcgis_services = [('Pallet', 'MapServer')]
        pallet_two.requires_processing = Mock(return_value=True)

        pallet_three = Pallet()
        pallet_three.copy_data = ['C:\\MapData\\four', three]

        lift.copy_data([pallet_one, pallet_two, pallet_three],
                       [pallet_one, pallet_two, pallet_three],
                       ['dest1', 'dest2'])

        self.assertEqual(copytree_mock.call_count, 6)
        self.assertEqual(rmtree_mock.call_count, 6)
        self.assertEqual(compact_mock.call_count, 3)
        lightswitch_mock().ensure.assert_has_calls([
            call('off', set([('Pallet', 'MapServer')])),
            call('on', set([('Pallet', 'MapServer')]))
        ])
Example #2
0
    def test_copy_data(self, copytree_mock, rmtree_mock, move, exists_mock,
                       compact_mock, describe_mock):
        describe_mock.side_effect = describe_side_effect
        exists_mock.return_value = True
        three = 'C:\\MapData\\three.gdb'
        two = 'C:\\MapData\\two.gdb'

        pallet_one = Pallet()
        pallet_one.copy_data = ['C:\\MapData\\one.gdb', two]
        pallet_one.requires_processing = Mock(return_value=True)

        pallet_two = Pallet()
        pallet_two.copy_data = ['C:\\MapData\\one.gdb', three]
        pallet_two.requires_processing = Mock(return_value=True)

        pallet_three = Pallet()
        pallet_three.copy_data = ['C:\\MapData\\four', three]

        lift.copy_data([pallet_one, pallet_two, pallet_three],
                       [pallet_one, pallet_two, pallet_three],
                       ['dest1', 'dest2'])

        self.assertEqual(copytree_mock.call_count, 6)
        self.assertEqual(rmtree_mock.call_count, 6)
        self.assertEqual(compact_mock.call_count, 3)
Example #3
0
    def test_copy_data_turns_off_and_on_services(self, copytree_mock, rmtree_mock, move, exists_mock, compact_mock,
                                                 describe_mock, lightswitch_mock):
        describe_mock.side_effect = describe_side_effect
        exists_mock.return_value = True
        lightswitch_mock().ensure.return_value = (True, [])
        three = 'C:\\MapData\\three.gdb'
        two = 'C:\\MapData\\two.gdb'

        pallet_one = Pallet()
        pallet_one.copy_data = ['C:\\MapData\\one.gdb', two]
        pallet_one.arcgis_services = [('Pallet', 'MapServer')]
        pallet_one.requires_processing = Mock(return_value=True)

        pallet_two = Pallet()
        pallet_two.copy_data = ['C:\\MapData\\one.gdb', three]
        pallet_two.arcgis_services = [('Pallet', 'MapServer')]
        pallet_two.requires_processing = Mock(return_value=True)

        pallet_three = Pallet()
        pallet_three.copy_data = ['C:\\MapData\\four', three]

        lift.copy_data([pallet_one, pallet_two, pallet_three], [pallet_one, pallet_two, pallet_three], ['dest1', 'dest2'])

        self.assertEqual(copytree_mock.call_count, 6)
        self.assertEqual(rmtree_mock.call_count, 6)
        self.assertEqual(compact_mock.call_count, 3)
        lightswitch_mock().ensure.assert_has_calls([call('off', set([('Pallet', 'MapServer')])), call('on', set([('Pallet', 'MapServer')]))])
Example #4
0
    def test_copy_data_scrub_hash_field(self):
        copy_data_fgdb_name = 'CopyData.gdb'
        copied_data = path.join(current_folder, copy_data_fgdb_name)

        def cleanup():
            print('cleaning up')
            if arcpy.Exists(copied_data):
                arcpy.Delete_management(copied_data)

        cleanup()

        pallet = Pallet()
        pallet.copy_data = [
            path.join(current_folder, 'data', copy_data_fgdb_name)
        ]
        pallet.requires_processing = Mock(return_value=True)

        lift.copy_data([pallet], [pallet], [current_folder])

        feature_class_fields = [
            field.name for field in arcpy.Describe(
                path.join(copied_data, 'DNROilGasWells_adds')).fields
        ]
        table_fields = [
            field.name for field in arcpy.Describe(
                path.join(copied_data, 'Providers_adds')).fields
        ]

        self.assertNotIn(core.hash_field, feature_class_fields)
        self.assertNotIn(core.hash_field, table_fields)

        cleanup()
Example #5
0
    def test_copy_data_error(self, copytree_mock, rmtree_mock, move, compact_mock, describe_mock):
        describe_mock.side_effect = describe_side_effect
        error_message = 'there was an error'
        copytree_mock.side_effect = Exception(error_message)

        pallet = Pallet()
        pallet.copy_data = ['C:\\MapData\\one.gdb']
        pallet.requires_processing = Mock(return_value=True)

        lift.copy_data([pallet], [pallet], ['hello'])

        self.assertEqual(pallet.success, (False, error_message))
Example #6
0
    def test_copy_data_error(self, copytree_mock, rmtree_mock, move, compact_mock, describe_mock, listdir_mock):
        describe_mock.side_effect = describe_side_effect
        error_message = 'there was an error'
        copytree_mock.side_effect = Exception(error_message)

        pallet = Pallet()
        pallet.copy_data = ['C:\\MapData\\one.gdb']
        pallet.requires_processing = Mock(return_value=True)

        success, failed = lift.copy_data('from_location', 'to_location', engine.packing_slip_file)

        self.assertTrue(failed['testfile'].startswith(error_message))
Example #7
0
    def test_copy_data_error(self, copytree_mock, rmtree_mock, move,
                             compact_mock, describe_mock):
        describe_mock.side_effect = describe_side_effect
        error_message = 'there was an error'
        copytree_mock.side_effect = Exception(error_message)

        pallet = Pallet()
        pallet.copy_data = ['C:\\MapData\\one.gdb']
        pallet.requires_processing = Mock(return_value=True)

        lift.copy_data([pallet], [pallet], ['hello'])

        self.assertEqual(pallet.success, (False, error_message))
Example #8
0
    def test_copy_data(self, copytree_mock, rmtree_mock, move, exists_mock, compact_mock, describe_mock):
        describe_mock.side_effect = describe_side_effect
        exists_mock.return_value = True
        three = 'C:\\MapData\\three.gdb'
        two = 'C:\\MapData\\two.gdb'

        pallet_one = Pallet()
        pallet_one.copy_data = ['C:\\MapData\\one.gdb', two]
        pallet_one.requires_processing = Mock(return_value=True)

        pallet_two = Pallet()
        pallet_two.copy_data = ['C:\\MapData\\one.gdb', three]
        pallet_two.requires_processing = Mock(return_value=True)

        pallet_three = Pallet()
        pallet_three.copy_data = ['C:\\MapData\\four', three]

        lift.copy_data([pallet_one, pallet_two, pallet_three], [pallet_one, pallet_two, pallet_three], ['dest1', 'dest2'])

        self.assertEqual(copytree_mock.call_count, 6)
        self.assertEqual(rmtree_mock.call_count, 6)
        self.assertEqual(compact_mock.call_count, 3)
Example #9
0
class TestPallet(unittest.TestCase):
    def setUp(self):
        self.patient = Pallet()

    def test_can_use_logging(self):
        self.patient.log.info('this works')

    @patch('arcpy.Describe')
    def test_name_prop(self, describe):
        class NamePallet(Pallet):
            def __init__(self):
                super(NamePallet, self).__init__()
                self.add_crates(
                    [
                        'fc1', 'fc2', ('fc3', 'source', 'destination'),
                        ('fc4', 'source', 'destination', 'fc4_new')
                    ], {
                        'source_workspace': 'C:\\MapData\\UDNR.sde',
                        'destination_workspace': 'C:\\MapData\\UDNR.gdb'
                    })

        self.assertIn('test_pallet.py:NamePallet', NamePallet().name)

    def test_add_crates(self):
        source = 'C:\\MapData\\UDNR.sde'
        dest = 'C:\\MapData\\UDNR.gdb'
        self.patient.add_crates([
            'fc1', ('fc3', 'source'),
            ('fc4', 'source', 'destination', 'fc4_new')
        ], {
            'source_workspace': source,
            'destination_workspace': dest
        })

        self.assertEqual(len(self.patient.get_crates()), 3)

        #: single source_name with defaults
        self.assertEqual(self.patient.get_crates()[0].source_name, 'fc1')
        self.assertEqual(self.patient.get_crates()[0].source_workspace, source)
        self.assertEqual(self.patient.get_crates()[0].destination_workspace,
                         dest)
        self.assertEqual(self.patient.get_crates()[0].destination_name, 'fc1')

        self.assertEqual(self.patient.get_crates()[1].source_workspace,
                         'source')
        self.assertEqual(self.patient.get_crates()[1].destination_workspace,
                         dest)

        self.assertEqual(self.patient.get_crates()[2].destination_name,
                         'fc4_new')

    def test_add_crates_empty_defaults(self):
        self.patient.add_crates([('fc1', 'source1', 'destination1'),
                                 ('fc2', 'source2', 'destination2', 'fc2_new')
                                 ])

        self.assertEqual(len(self.patient.get_crates()), 2)

        #: single source_name with defaults
        self.assertEqual(self.patient.get_crates()[0].source_name, 'fc1')
        self.assertEqual(self.patient.get_crates()[0].source_workspace,
                         'source1')
        self.assertEqual(self.patient.get_crates()[0].destination_workspace,
                         'destination1')
        self.assertEqual(self.patient.get_crates()[0].destination_name, 'fc1')

        self.assertEqual(self.patient.get_crates()[1].source_workspace,
                         'source2')
        self.assertEqual(self.patient.get_crates()[1].destination_workspace,
                         'destination2')
        self.assertEqual(self.patient.get_crates()[1].destination_name,
                         'fc2_new')

    def test_add_crate_with_string(self):
        self.patient.add_crate('fc1', {
            'source_workspace': 'source1',
            'destination_workspace': 'destination1'
        })

        self.assertEqual(len(self.patient.get_crates()), 1)

        #: single source_name with defaults
        self.assertEqual(self.patient.get_crates()[0].source_name, 'fc1')
        self.assertEqual(self.patient.get_crates()[0].destination_name, 'fc1')
        self.assertEqual(self.patient.get_crates()[0].source_workspace,
                         'source1')
        self.assertEqual(self.patient.get_crates()[0].destination_workspace,
                         'destination1')

    def test_add_crate_with_tuple_one_value(self):
        self.patient.add_crate(('fc1'), {
            'source_workspace': 'source1',
            'destination_workspace': 'destination1'
        })

        self.assertEqual(len(self.patient.get_crates()), 1)

        #: single source_name with defaults
        self.assertEqual(self.patient.get_crates()[0].source_name, 'fc1')
        self.assertEqual(self.patient.get_crates()[0].destination_name, 'fc1')
        self.assertEqual(self.patient.get_crates()[0].source_workspace,
                         'source1')
        self.assertEqual(self.patient.get_crates()[0].destination_workspace,
                         'destination1')

    def test_add_crate_with_tuple_two_values(self):
        self.patient.add_crate(('fc1', 'source1'), {
            'source_workspace': 'source2',
            'destination_workspace': 'destination1'
        })

        self.assertEqual(len(self.patient.get_crates()), 1)

        #: single source_name with defaults
        self.assertEqual(self.patient.get_crates()[0].source_name, 'fc1')
        self.assertEqual(self.patient.get_crates()[0].destination_name, 'fc1')
        self.assertEqual(self.patient.get_crates()[0].source_workspace,
                         'source1')
        self.assertEqual(self.patient.get_crates()[0].destination_workspace,
                         'destination1')

    def test_add_crate_with_tuple_three_values(self):
        self.patient.add_crate(('fc1', 'source1', 'destination1'))

        self.assertEqual(len(self.patient.get_crates()), 1)

        #: single source_name with defaults
        self.assertEqual(self.patient.get_crates()[0].source_name, 'fc1')
        self.assertEqual(self.patient.get_crates()[0].destination_name, 'fc1')
        self.assertEqual(self.patient.get_crates()[0].source_workspace,
                         'source1')
        self.assertEqual(self.patient.get_crates()[0].destination_workspace,
                         'destination1')

    def test_add_crate_with_tuple_four_values(self):
        self.patient.add_crate(('fc1', 'source1', 'destination1', 'dest_name'))

        self.assertEqual(len(self.patient.get_crates()), 1)

        #: single source_name with defaults
        self.assertEqual(self.patient.get_crates()[0].source_name, 'fc1')
        self.assertEqual(self.patient.get_crates()[0].destination_name,
                         'dest_name')
        self.assertEqual(self.patient.get_crates()[0].source_workspace,
                         'source1')
        self.assertEqual(self.patient.get_crates()[0].destination_workspace,
                         'destination1')

    def test_add_crate_default_reproject(self):
        self.patient.add_crate(('fc1', 'source1', 'destination1', 'dest_name'))
        self.patient.add_crate(('fc1', 'source1', 'destination1', 'dest_name'),
                               {
                                   'source_workspace': 'hello',
                                   'destination_workspace': 'blah'
                               })

        self.assertEqual(
            self.patient.get_crates()
            [0].destination_coordinate_system.factoryCode, 3857)
        self.assertEqual(
            self.patient.get_crates()[0].geographic_transformation,
            'NAD_1983_To_WGS_1984_5')
        self.assertEqual(
            self.patient.get_crates()
            [1].destination_coordinate_system.factoryCode, 3857)

    def test_add_crate_alternative_reproject(self):
        class ReprojectPallet(Pallet):
            def __init__(self):
                super(ReprojectPallet, self).__init__()
                self.destination_coordinate_system = 26912

        pallet = ReprojectPallet()
        pallet.add_crate(('fc1', 'source1', 'destination1', 'dest_name'))

        self.assertEqual(
            pallet.get_crates()[0].destination_coordinate_system.factoryCode,
            26912)

    def test_is_ready_to_ship_no_crates_returns_true(self):
        self.assertTrue(self.patient.is_ready_to_ship())

    def test_is_ready_to_ship_crates_with_updates_returns_true(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        self.patient._crates = [updated, updated, updated]

        self.assertTrue(self.patient.is_ready_to_ship())

    def test_is_ready_to_ship_crates_with_no_changes_returns_true(self):
        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        self.patient._crates = [no_changes, no_changes, no_changes]

        self.assertTrue(self.patient.is_ready_to_ship())

    def test_is_ready_to_ship_crates_with_updates_and_no_changes_returns_true(
            self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        self.patient._crates = [no_changes, updated, no_changes]

        self.assertTrue(self.patient.is_ready_to_ship())

    def test_is_ready_to_ship_crates_with_any_schema_changed_returns_false(
            self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        schema_change = Crate('', '', '', '')
        schema_change.result = (Crate.INVALID_DATA, None)

        self.patient._crates = [updated, no_changes, schema_change]

        self.assertFalse(self.patient.is_ready_to_ship())

    def test_is_ready_to_ship_crates_with_any_exception_returns_false(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        unhandled_exception = Crate('', '', '', '')
        unhandled_exception.result = (Crate.UNHANDLED_EXCEPTION, None)

        self.patient._crates = [updated, no_changes, unhandled_exception]

        self.assertFalse(self.patient.is_ready_to_ship())

    def test_is_ready_to_ship_crates_with_all_returns_false(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        schema_change = Crate('', '', '', '')
        schema_change.result = (Crate.INVALID_DATA, None)

        unhandled_exception = Crate('', '', '', '')
        unhandled_exception.result = (Crate.UNHANDLED_EXCEPTION, None)

        self.patient._crates = [
            updated, no_changes, unhandled_exception, schema_change
        ]

        self.assertFalse(self.patient.is_ready_to_ship())

    def test_requires_processing_with_no_crates_returns_false(self):
        self.assertFalse(self.patient.requires_processing())

    def test_requires_processing_crates_with_updates_returns_true(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        self.patient._crates = [updated, updated]

        self.assertTrue(self.patient.requires_processing())

    def test_requires_processing_crates_with_updates_and_changes_returns_true(
            self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        self.patient._crates = [updated, no_changes, no_changes]

        self.assertTrue(self.patient.requires_processing())

    def test_requires_processing_crates_with_update_and_no_changes_returns_true(
            self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        self.patient._crates = [updated, updated, updated]

        self.assertTrue(self.patient.requires_processing())

    def test_requires_processing_crates_result_created_returns_true(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.CREATED, None)

        self.patient._crates = [updated]

        self.assertTrue(self.patient.requires_processing())

    def test_requires_processing_crates_with_schema_changes_returns_false(
            self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        schema_change = Crate('', '', '', '')
        schema_change.result = (Crate.INVALID_DATA, None)

        self.patient._crates = [schema_change, updated, updated]

        self.assertFalse(self.patient.requires_processing())

    def test_requires_processing_crates_with_unhandled_exception_returns_false(
            self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        unhandled_exception = Crate('', '', '', '')
        unhandled_exception.result = (Crate.UNHANDLED_EXCEPTION, None)

        self.patient._crates = [updated, updated, unhandled_exception]

        self.assertFalse(self.patient.requires_processing())

    def test_not_implemented(self):
        self.assertEqual(self.patient.process(), NotImplemented)
        self.assertEqual(self.patient.ship(), NotImplemented)
        self.assertEqual(self.patient.validate_crate(None), NotImplemented)
Example #10
0
class TestRequiresProcessing(unittest.TestCase):
    def setUp(self):
        self.patient = Pallet()

    def test_with_no_crates_returns_false(self):
        self.assertFalse(self.patient.requires_processing())

    def test_crates_with_updates_returns_true(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        self.patient._crates = [updated, updated]

        self.assertTrue(self.patient.requires_processing())

    def test_crates_with_updates_and_changes_returns_true(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        self.patient._crates = [updated, no_changes, no_changes]

        self.assertTrue(self.patient.requires_processing())

    def test_crates_with_update_and_no_changes_returns_true(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        self.patient._crates = [updated, updated, updated]

        self.assertTrue(self.patient.requires_processing())

    def test_crates_result_created_returns_true(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.CREATED, None)

        self.patient._crates = [updated]

        self.assertTrue(self.patient.requires_processing())

    def test_crates_with_schema_changes_returns_false(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        schema_change = Crate('', '', '', '')
        schema_change.result = (Crate.INVALID_DATA, None)

        self.patient._crates = [schema_change, updated, updated]

        self.assertFalse(self.patient.requires_processing())

    def test_crates_with_unhandled_exception_returns_false(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        unhandled_exception = Crate('', '', '', '')
        unhandled_exception.result = (Crate.UNHANDLED_EXCEPTION, None)

        self.patient._crates = [updated, updated, unhandled_exception]

        self.assertFalse(self.patient.requires_processing())

    def test_process_on_fail(self):
        updated = Crate('', '', '', '')
        updated.result = (Crate.UPDATED, None)

        no_changes = Crate('', '', '', '')
        no_changes.result = (Crate.NO_CHANGES, None)

        unhandled_exception = Crate('', '', '', '')
        unhandled_exception.result = (Crate.UNHANDLED_EXCEPTION, None)

        self.patient._crates = [updated, no_changes, unhandled_exception]
        self.patient.success = (False, None)

        self.patient.process_on_fail = True

        self.assertTrue(self.patient.requires_processing())