diff --git a/test/github/__init__.py b/test/github/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/github/github_importer_spec.py b/test/github/github_importer_spec.py new file mode 100644 index 0000000..6880def --- /dev/null +++ b/test/github/github_importer_spec.py @@ -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)!