Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
APKG Builder
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kartenaale
Build
APKG Builder
Commits
5e851542
Commit
5e851542
authored
9 months ago
by
Philipp Stadler
Browse files
Options
Downloads
Patches
Plain Diff
tests: add coverage for static fields
parent
1e6a59e7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/fixtures/fields_static/.apkg-spec.yaml
+21
-0
21 additions, 0 deletions
test/fixtures/fields_static/.apkg-spec.yaml
test/fixtures/fields_static/data.csv
+1
-0
1 addition, 0 deletions
test/fixtures/fields_static/data.csv
test/test_export_apkgs.py
+36
-0
36 additions, 0 deletions
test/test_export_apkgs.py
with
58 additions
and
0 deletions
test/fixtures/fields_static/.apkg-spec.yaml
0 → 100644
+
21
−
0
View file @
5e851542
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
:
[]
This diff is collapsed.
Click to expand it.
test/fixtures/fields_static/data.csv
0 → 100644
+
1
−
0
View file @
5e851542
34573;Welches Tier hat den schönsten Rüssel?
This diff is collapsed.
Click to expand it.
test/test_export_apkgs.py
+
36
−
0
View file @
5e851542
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment