Example #1
0
 def tearDown(self):
     super().tearDown()
     data_file_path = get_datafile_filename(self)
     self.assertTrue(os.path.exists(data_file_path))
     # use just class and test name instead of full ID
     self.assertIn(".".join(self.id().split(".")[-2:]), data_file_path.name)
     self.assertIn("test_data", str(data_file_path))
     shutil.rmtree(os.path.dirname(get_datafile_filename(self)))
Example #2
0
def remove_storage_file_after(request):
    storage_file = get_datafile_filename(request.node)
    yield storage_file
    # TODO: found why this were necessary before change of singletons
    # PersistentObjectStorage().cassette.dump()
    if storage_file.is_file():
        storage_file.unlink()
Example #3
0
 def setUp(self):
     super().setUp()
     self.token = os.environ.get("GITHUB_TOKEN")
     if not Path(
             get_datafile_filename(obj=self)).exists() and not self.token:
         raise EnvironmentError(
             "You are in Requre write mode, please set proper GITHUB_TOKEN env variables"
         )
     self._service = None
     self._ogr_project = None
Example #4
0
    def setUp(self):
        self.github_app_id = os.environ.get("GITHUB_APP_ID")
        self.github_app_private_key_path = os.environ.get(
            "GITHUB_APP_PRIVATE_KEY_PATH")

        if not get_datafile_filename(obj=self) and (
                not self.github_app_id
                or not self.github_app_private_key_path):
            raise EnvironmentError(
                "You are in Requre write mode, please set "
                "GITHUB_APP_ID GITHUB_APP_PRIVATE_KEY_PATH env variables")
Example #5
0
    def setUp(self):
        super().setUp()
        self.token = os.environ.get("PAGURE_OGR_TEST_TOKEN", "")

        if not get_datafile_filename(obj=self) and (not self.token):
            raise EnvironmentError("please set PAGURE_OGR_TEST_TOKEN env variables")

        self._service = None
        self._user = None
        self._ogr_project = None
        self._ogr_fork = None
Example #6
0
def change_storage_file(cassette: Cassette,
                        func,
                        args,
                        storage_file: Optional[str] = None):
    """
    Internal function that try to construct persistent data file based on various
    possibilities.

    :param cassette: Cassette instance to pass inside object to work with
    """
    if storage_file:
        cassette.storage_file = storage_file
    else:
        if len(args):
            try:
                cassette.storage_file = get_datafile_filename(args[0])
            except NameError:
                cassette.storage_file = get_datafile_filename(func)
        else:
            cassette.storage_file = get_datafile_filename(func)
    original_storage_file = cassette.storage_file
    return original_storage_file
Example #7
0
def record_requests_fixture(request):
    storage_file = get_datafile_filename(request.node)
    with recording_requests(storage_file=storage_file) as cassette:
        mode_description = {
            StorageMode.read: "replaying",
            StorageMode.write: "recording",
            StorageMode.append: "appending",
            StorageMode.default: "in default mode",
        }[cassette.mode]
        logger.debug(
            f"Start requre {mode_description} with storage file: {storage_file}"
        )
        yield cassette
        cassette.dump()
        logger.debug(
            f"End requre {mode_description} with storage file: {storage_file}")
Example #8
0
 def setUp(self):
     self._github_service = None
     self._pagure_service = None
     self._gitlab_service = None
     self.github_token = os.environ.get("GITHUB_TOKEN")
     self.pagure_token = os.environ.get("PAGURE_TOKEN")
     self.gitlab_token = os.environ.get("GITLAB_TOKEN") or "some_token"
     if not Path(get_datafile_filename(obj=self)).exists():
         if (
             not self.github_token
             or not self.pagure_token
             or not os.environ.get("GITLAB_TOKEN")
         ):
             raise EnvironmentError(
                 "You are in requre write mode, please set GITHUB_TOKEN PAGURE_TOKEN"
                 " GITLAB_TOKEN env variables"
             )
Example #9
0
 def setUp(self) -> None:
     super().setUp()
     self.cassette.storage_file = get_datafile_filename(self.id)
     TempFile.set_cassette(self.cassette)
Example #10
0
def remove_storage_file(request):
    storage_file = get_datafile_filename(request.node)
    if storage_file.is_file():
        storage_file.unlink()
    return storage_file
Example #11
0
 def setUp(self):
     super().setUp()
     response_file = get_datafile_filename(self)
     os.makedirs(os.path.dirname(response_file), mode=0o777, exist_ok=True)
     self.cassette = PersistentObjectStorage().cassette
     self.cassette.storage_file = response_file