Esempio n. 1
0
    def test_migration_0040_no_process_state(self):
        """Check old ProcessNodes without a `process_state` can be migrated"""
        # data has one "new" entry, in the form of Node <PK=52>.
        # data also has one "old" entry, in form of Node <PK=42>.
        # It doesn't have a `process_state` attribute (nor a `sealed` or `_sealed`)
        data = {
            'node_attributes': {
                52: {
                    'process_state': 'finished',
                    'sealed': True
                },
                42: {}
            },
            'export_data': {
                'Node': {
                    42: {
                        'node_type':
                        'process.workflow.workfunction.WorkFunctionNode.'
                    },
                    52: {
                        'node_type': 'process.calculation.calcjob.CalcJobNode.'
                    }
                }
            }
        }

        migration_data_migration_legacy_process_attributes(data)

        self.assertDictEqual(data['node_attributes'][42], {'sealed': True})
Esempio n. 2
0
    def test_migration_0040_corrupt_archive(self):
        """Check CorruptArchive is raised for different cases during migration 0040"""
        from aiida.tools.importexport.common.exceptions import CorruptArchive

        # data has one "valid" entry, in the form of Node <PK=42>.
        # At least it has the needed key `node_type`.
        # data also has one "invalid" entry, in form of Node <PK=25>.
        # It is listed in `node_attributes`, but not in `export_data.Node`
        # Also Node <PK=25> is present in `export_data.Node`, but not in `node_attributes`.
        # This is not fine, but will not (and should not) be caught by this particular migration function
        data = {
            'node_attributes': {
                25: {},
                42: {}
            },
            'export_data': {
                'Node': {
                    42: {
                        'node_type': 'data.int.Int.'
                    },
                    52: {
                        'node_type': 'data.dict.Dict.'
                    }
                }
            }
        }

        with self.assertRaises(CorruptArchive) as exc:
            migration_data_migration_legacy_process_attributes(data)

        self.assertIn('Your export archive is corrupt! Org. exception:',
                      str(exc.exception))

        # data has one "valid" entry, in the form of Node <PK=52>.
        # data also has one "invalid" entry, in form of Node <PK=42>.
        # It is in an active process state ('waiting')
        data = {
            'node_attributes': {
                52: {
                    'process_state': 'finished',
                    '_sealed': True
                },
                42: {
                    'process_state': 'waiting'
                }
            },
            'export_data': {
                'Node': {
                    42: {
                        'node_type': 'process.calculation.calcjob.CalcJobNode.'
                    },
                    52: {
                        'node_type': 'process.calculation.calcjob.CalcJobNode.'
                    }
                }
            }
        }

        with self.assertRaises(CorruptArchive) as exc:
            migration_data_migration_legacy_process_attributes(data)

        self.assertIn(
            'Your export archive is corrupt! Please see the log-file',
            str(exc.exception))