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 1bd455c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Empty file added test/github/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions test/github/github_importer_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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

FULL_SNAPSHOT_PATH = Path("/tmp/anki_full_snapshot_path/")
TEST_GIT_REPO = "https://github.com/Stvad/Software_Engineering__git"

GitImporter.get_repo_local_path = lambda self, x: FULL_SNAPSHOT_PATH

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(TEST_GIT_REPO)
subject.clone_repository_and_import(TEST_GIT_REPO)
subject.clone_repository_and_import(TEST_GIT_REPO)
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 1bd455c

Please sign in to comment.