Skip to content
Snippets Groups Projects
Commit 5e851542 authored by Philipp Stadler's avatar Philipp Stadler
Browse files

tests: add coverage for static fields

parent 1e6a59e7
Branches
No related tags found
No related merge requests found
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: []
34573;Welches Tier hat den schönsten Rüssel?
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment