diff --git a/test/fixtures/fields_static/.apkg-spec.yaml b/test/fixtures/fields_static/.apkg-spec.yaml new file mode 100644 index 0000000000000000000000000000000000000000..455ae6ead9a0cea526bb6c353842df6a16ef2045 --- /dev/null +++ b/test/fixtures/fields_static/.apkg-spec.yaml @@ -0,0 +1,21 @@ +content_version: 1.0.0 + +templates: +- q_a + +content: +- import_csv: + content_version: 2024-01-19 19:00:00+00:00 + note_type: Q/A Testnotetype + file_patterns: + - '*.csv' + # and to making one deck per card type + deck_name_pattern: '{{card_type}}' + fields_mapping: + - guid + - Question + fields_static: + Answer: Tapir + tags: [] + +resource_paths: [] diff --git a/test/fixtures/fields_static/data.csv b/test/fixtures/fields_static/data.csv new file mode 100644 index 0000000000000000000000000000000000000000..a225a9eaad6e1f0240bc57d8dc11c338ccd0c0f9 --- /dev/null +++ b/test/fixtures/fields_static/data.csv @@ -0,0 +1 @@ +34573;Welches Tier hat den schönsten Rüssel? diff --git a/test/test_export_apkgs.py b/test/test_export_apkgs.py index 03259b01a0edfffa8245cc4ad9cfd3335677170e..7ff7af3471cfa0b9d8f5c7943633d843fcfa15d7 100644 --- a/test/test_export_apkgs.py +++ b/test/test_export_apkgs.py @@ -16,6 +16,7 @@ class MockArgs: CONTENT_PATH_ANKI = 'test/fixtures/anki' CONTENT_PATH_CSV = 'test/fixtures/csv' CONTENT_PATH_CSV_UPDATED_CONTENT = 'test/fixtures/csv_updated_content' +CONTENT_PATH_FIELDS_STATIC = 'test/fixtures/fields_static' TEMPLATES_PATH = 'test/fixtures/templates' TEMPLATES_PATH_UPDATED = 'test/fixtures/templates_updated' @@ -325,6 +326,41 @@ class TestExportApkgs(unittest.TestCase): self.assertEqual( template['afmt'], 'Back: {{Answer}}') + + def test_static_fields(self): + """ + static_fields are set on the resulting card in Anki + """ + with TemporaryDirectory() as temp_collection_dir: + col = Collection(str(Path(temp_collection_dir) / "test.anki2")) + with TemporaryDirectory() as first_export_dir: + args_first = MockArgs( + content=CONTENT_PATH_FIELDS_STATIC, + templates_dir=TEMPLATES_PATH, + output_dir=first_export_dir, + dry_run=False) + package = export_package_from_spec( + Path(CONTENT_PATH_FIELDS_STATIC) / '.apkg-spec.yaml', + args_first) + + # import the first time, everything is new + result1 = col.import_anki_package(ImportAnkiPackageRequest( + package_path=str(package), + options=ImportAnkiPackageOptions( + merge_notetypes=True, + update_notes=ImportAnkiPackageUpdateCondition.IMPORT_ANKI_PACKAGE_UPDATE_CONDITION_IF_NEWER, + update_notetypes=ImportAnkiPackageUpdateCondition.IMPORT_ANKI_PACKAGE_UPDATE_CONDITION_IF_NEWER, + with_scheduling=False, + with_deck_configs=False, + ) + )) + self.assertEqual(len(result1.log.new), 1) + self.assertEqual( + result1.log.new[0].fields, + # the empty one is resources + [ 'Welches Tier hat den schönsten Rüssel?', 'Tapir', '' ] + ) + def find_template(col: Collection, name: str): template = None