Step 3: Implement a File Server Testing Component

Let’s dive in on how to implement a testing component for a server.

This component needs to test two things:

  • The /upload_file/ endpoint by creating a file and sending its content to it.

  • The / endpoint listing files, by validating the that previously uploaded file is present in the response.


class TestFileServer(LightningWork):
    def __init__(self, drive: Drive):
        super().__init__(cache_calls=True)
        self.drive = drive

    def run(self, file_server_url: str, first=True):
        if first:
            with open("test.txt", "w") as f:
                f.write("Some text.")

            response = requests.post(
                file_server_url + "/upload_file/",
                files={'file': open("test.txt", 'rb')}
            )
            assert response.status_code == 200
        else:
            response = requests.get(file_server_url)