# Path: crowd_anki/export/anki_exporter_wrapper.py
# class AnkiJsonExporterWrapper:
#     """
#     Wrapper designed to work with standard export dialog in anki.
#     """
# 
#     key = "CrowdAnki JSON representation"
#     ext = constants.ANKI_EXPORT_EXTENSION
#     hideTags = True
#     includeTags = True
#     directory_export = True
# 
#     def __init__(self, collection,
#                  deck_id: int = None,
#                  json_exporter: AnkiJsonExporter = None,
#                  notifier: Notifier = None):
#         self.includeMedia = True
#         self.did = deck_id
#         self.count = 0  # Todo?
#         self.collection = collection
#         self.anki_json_exporter = json_exporter or AnkiJsonExporter(collection, ConfigSettings.get_instance())
#         self.notifier = notifier or AnkiModalNotifier()
# 
#     # required by anki exporting interface with its non-PEP-8 names
#     # noinspection PyPep8Naming
#     def exportInto(self, directory_path):
#         if self.did is None:
#             self.notifier.warning(EXPORT_FAILED_TITLE, "CrowdAnki export works only for specific decks. "
#                                                        "Please use CrowdAnki snapshot if you want to export "
#                                                        "the whole collection.")
#             return
# 
#         deck = AnkiDeck(self.collection.decks.get(self.did, default=False))
#         if deck.is_dynamic:
#             self.notifier.warning(EXPORT_FAILED_TITLE, "CrowdAnki does not support export for dynamic decks.")
#             return
# 
#         # Clean up duplicate note models. See
#         # https://github.com/Stvad/CrowdAnki/wiki/Workarounds-%E2%80%94-Duplicate-note-model-uuids.
#         disambiguate_note_model_uuids(self.collection)
# 
#         # .parent because we receive name with random numbers at the end (hacking around internals of Anki) :(
#         export_path = Path(directory_path).parent
#         self.anki_json_exporter.export_to_directory(deck, export_path, self.includeMedia,
#                                                     create_deck_subdirectory=ConfigSettings.get_instance().export_create_deck_subdirectory)
# 
#         self.count = self.anki_json_exporter.last_exported_count


from unittest.mock import MagicMock
from mamba import describe, it, context
from crowd_anki.export.anki_exporter_wrapper import AnkiJsonExporterWrapper



DUMMY_EXPORT_DIRECTORY = "/tmp"

TEST_DECK_ID = 1

with describe(AnkiJsonExporterWrapper) as self:
    with context("user is trying to export dynamic deck"):
        with it("should warn and exit without initiating export"):
            exporter_mock = MagicMock()
            notifier_mock = MagicMock()

            collection_mock = MagicMock()
            collection_mock.decks.get.return_value = {'dyn': True}


# Path: crowd_anki/export/anki_exporter_wrapper.py
# class AnkiJsonExporterWrapper:
#     """
#     Wrapper designed to work with standard export dialog in anki.
#     """
# 
#     key = "CrowdAnki JSON representation"
#     ext = constants.ANKI_EXPORT_EXTENSION
#     hideTags = True
#     includeTags = True
#     directory_export = True
# 
#     def __init__(self, collection,
#                  deck_id: int = None,
#                  json_exporter: AnkiJsonExporter = None,
#                  notifier: Notifier = None):
#         self.includeMedia = True
#         self.did = deck_id
#         self.count = 0  # Todo?
#         self.collection = collection
#         self.anki_json_exporter = json_exporter or AnkiJsonExporter(collection, ConfigSettings.get_instance())
#         self.notifier = notifier or AnkiModalNotifier()
# 
#     # required by anki exporting interface with its non-PEP-8 names
#     # noinspection PyPep8Naming
#     def exportInto(self, directory_path):
#         if self.did is None:
#             self.notifier.warning(EXPORT_FAILED_TITLE, "CrowdAnki export works only for specific decks. "
#                                                        "Please use CrowdAnki snapshot if you want to export "
#                                                        "the whole collection.")
#             return
# 
#         deck = AnkiDeck(self.collection.decks.get(self.did, default=False))
#         if deck.is_dynamic:
#             self.notifier.warning(EXPORT_FAILED_TITLE, "CrowdAnki does not support export for dynamic decks.")
#             return
# 
#         # Clean up duplicate note models. See
#         # https://github.com/Stvad/CrowdAnki/wiki/Workarounds-%E2%80%94-Duplicate-note-model-uuids.
#         disambiguate_note_model_uuids(self.collection)
# 
#         # .parent because we receive name with random numbers at the end (hacking around internals of Anki) :(
#         export_path = Path(directory_path).parent
#         self.anki_json_exporter.export_to_directory(deck, export_path, self.includeMedia,
#                                                     create_deck_subdirectory=ConfigSettings.get_instance().export_create_deck_subdirectory)
# 
#         self.count = self.anki_json_exporter.last_exported_count


# Path: test/export/anki_exporter_wrapper_spec.py
from unittest.mock import MagicMock
from mamba import describe, it, context
from crowd_anki.export.anki_exporter_wrapper import AnkiJsonExporterWrapper




DUMMY_EXPORT_DIRECTORY = "/tmp"

TEST_DECK_ID = 1

with describe(AnkiJsonExporterWrapper) as self:
    with context("user is trying to export dynamic deck"):
        with it("should warn and exit without initiating export"):
            exporter_mock = MagicMock()
            notifier_mock = MagicMock()

            collection_mock = MagicMock()
            collection_mock.decks.get.return_value = {'dyn': True}


            subject = AnkiJsonExporterWrapper(collection_mock, TEST_DECK_ID, exporter_mock, notifier_mock)