def test_file(self): source_path = os.path.join(MIGRATIONS_DIR, 'backup') output = StringIO() call_command( 'import_models', file=source_path, plan='direct', natural=True, stdout=output, ) self.assertIn('Entries were successfully imported.', output.getvalue()) source_path = os.path.join(MIGRATIONS_DIR, 'author.json') with open(source_path, 'r') as source_file: source = source_file.read() migration = ModelMigration(Author) result = migration.export_data(None, JsonSerializer) self.assertEqual(source.splitlines(), result.splitlines()) source_path = os.path.join(MIGRATIONS_DIR, 'category.json') with open(source_path, 'r') as source_file: source = source_file.read() migration = ModelMigration(Category) result = migration.export_data(None, JsonSerializer) self.assertEqual(source.splitlines(), result.splitlines()) source_path = os.path.join(MIGRATIONS_DIR, 'post.json') with open(source_path, 'r') as source_file: source = source_file.read() migration = ModelMigration(Post) result = migration.export_data(None, JsonSerializer) self.assertEqual(source.splitlines(), result.splitlines())
def test_file(self): source_path = os.path.join(MIGRATIONS_DIR, 'backup') MultipleImportFacade.from_file_path( source_path, use_natural_keys=True, plan='direct', ) source_path = os.path.join(MIGRATIONS_DIR, 'author.json') with open(source_path, 'r') as source_file: source = source_file.read() migration = ModelMigration(Author) result = migration.export_data(None, JsonSerializer) self.assertEqual(source.splitlines(), result.splitlines()) source_path = os.path.join(MIGRATIONS_DIR, 'category.json') with open(source_path, 'r') as source_file: source = source_file.read() migration = ModelMigration(Category) result = migration.export_data(None, JsonSerializer) self.assertEqual(source.splitlines(), result.splitlines()) source_path = os.path.join(MIGRATIONS_DIR, 'tag.json') with open(source_path, 'r') as source_file: source = source_file.read() migration = ModelMigration(Tag) result = migration.export_data(None, JsonSerializer) self.assertEqual(source.splitlines(), result.splitlines()) source_path = os.path.join(MIGRATIONS_DIR, 'post.json') with open(source_path, 'r') as source_file: source = source_file.read() migration = ModelMigration(Post) result = migration.export_data(None, JsonSerializer) self.assertEqual(source.splitlines(), result.splitlines()) source_path = os.path.join(MIGRATIONS_DIR, 'post_tags.json') with open(source_path, 'r') as source_file: source = source_file.read() migration = ModelMigration(PostTags) result = migration.export_data(None, JsonSerializer) self.assertEqual(source.splitlines(), result.splitlines())
def to_directory(cls, dir, **options): if not os.path.exists(dir): os.makedirs(dir) migration_kwargs, export_kwargs = cls._clean_options(options) model_list = sort_dependencies(migration_kwargs.pop('models')) model_list.reverse() serializer = export_kwargs.pop('serializer') for model in model_list: migration = ModelMigration(model, **migration_kwargs) migration_serializer = migration.get_serializer(serializer) file_name = '{0}.{1}.{2}'.format(model._meta.app_label, model._meta.model_name, migration_serializer.name) file_path = os.path.join(dir, file_name) with migration_serializer.open_to_dump(file_path) as file: migration.export_data(file, migration_serializer, **export_kwargs)
def test_file(self): migration = ModelMigration(Alphabet) source_path = os.path.join(MIGRATIONS_DIR, 'alphabet.csv') with open(source_path, 'r') as source_file: source = source_file.read() SingleImportFacade.from_file_path( source_path, model='datamigrations_facades_tests.Alphabet', serializer='csv', ) result = migration.export_data(serializer=CsvSerializer) self.assertEqual(source.splitlines(), result.splitlines())
def test_file(self): migration = ModelMigration(Alphabet) source_path = os.path.join(MIGRATIONS_DIR, 'alphabet.csv') with open(source_path, 'r') as source_file: source = source_file.read() output = StringIO() call_command( 'import_model', 'datamigrations_commands_tests.Alphabet', file=source_path, format='csv', stdout=output, ) result = migration.export_data(serializer=CsvSerializer) self.assertEqual(source.splitlines(), result.splitlines()) self.assertIn('Entries were successfully imported.', output.getvalue())
def to_file(cls, file, **options): migration_kwargs, export_kwargs = cls._clean_options(options) migration = ModelMigration(**migration_kwargs) migration.export_data(file, **export_kwargs)