Files
dvc/tests/remotes/http.py
T
Batuhan Taskaya 9aec8f1926 dvc: get rid of path_info
Intermediate PR in removing path_info from our code base.

It is completely removed from the main codebase and is still
being used in tests, which will be migrated in the followups.

For fs-specific simple path manipulation, we've introduced
`fs.path` helper (similar to `os.path`).

Fixes #6774
2021-11-10 00:52:48 +02:00

45 lines
1.1 KiB
Python

# pylint:disable=abstract-method
import os
import uuid
import pytest
import requests
from .base import Base
from .path_info import HTTPURLInfo
class HTTP(Base, HTTPURLInfo):
@staticmethod
def get_url(port): # pylint: disable=arguments-differ
dname = str(uuid.uuid4())
return f"http://127.0.0.1:{port}/{dname}"
def mkdir(self, mode=0o777, parents=False, exist_ok=False):
assert mode == 0o777
assert parents
def write_bytes(self, contents):
assert isinstance(contents, bytes)
response = requests.post(self.url, data=contents)
assert response.status_code == 200
@property
def fs_path(self):
return self.url
@pytest.fixture(scope="session")
def http_server(test_config, tmp_path_factory):
from tests.utils.httpd import StaticFileServer
test_config.requires("http")
directory = os.fspath(tmp_path_factory.mktemp("http"))
with StaticFileServer(directory=directory) as httpd:
yield httpd
@pytest.fixture
def http(http_server):
yield HTTP(HTTP.get_url(http_server.server_port))