Skip to content

Commit

Permalink
Add test for succesful repeated "import" (clone and pull) from git
Browse files Browse the repository at this point in the history
Diagnose #138 which occurred on Windows.  (A lock for the git pack
file is often held by a previous clone/pull and not released, so the
next pull fails (`PermissionError`).)
  • Loading branch information
aplaice committed Nov 20, 2021
1 parent 72b6938 commit b1d1e47
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Empty file added test/github/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions test/github/github_importer_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from unittest.mock import MagicMock, patch

from mamba import describe, it, context
from expects import expect, equal

from pathlib import Path

from crowd_anki.github.github_importer import GitImporter

GitImporter.get_repo_local_path = lambda self, x: Path("/tmp/foo/bar/")

with describe(GitImporter) as self:
with context("user is trying to import a deck from a git repo multiple times"):
# See #138!
with it("should clone the git repo without crashing"):
collection_mock = MagicMock()
subject = GitImporter(collection_mock)
with patch("crowd_anki.github.github_importer.AnkiJsonImporter") as mock_json_importer:
subject.clone_repository_and_import("https://github.com/aplaice/colemak_keyboard_layout_dynamic")
subject.clone_repository_and_import("https://github.com/aplaice/colemak_keyboard_layout_dynamic")
subject.clone_repository_and_import("https://github.com/aplaice/colemak_keyboard_layout_dynamic")
expect(mock_json_importer.import_deck_from_path.call_count).to(equal(3))

# Note: the import itself isn't being tested (we're not,
# yet (as of 2021-11) testing import itself in any
# situation)!

0 comments on commit b1d1e47

Please sign in to comment.