Exemplo n.º 1
0
    def test_get_info(self):
        for url in self.urls_info:
            res = http.get(url, datacls=InfoResponse)
            data = res.attach()

            self.assertTrue(isinstance(data, InfoResponse))
            self.assertEqual(data.server_name, "Mocker")
Exemplo n.º 2
0
    def test_get_info(self):
        uri = "http://localhost:8000/mock/info"
        with http.get(uri, datacls=InfoResponse) as res:
            data = res.attach()

        self.assertTrue(isinstance(data, InfoResponse))
        self.assertEqual(data.server_name, NAME_SERVER)
Exemplo n.º 3
0
    def test_get_image(self):
        with open(PATH_IMAGE, "rb") as f:
            image_ideal = f.read()

        for url in self.urls_image:
            res = http.get(url)
            data = res.body
            self.assertEqual(image_ideal, data)
Exemplo n.º 4
0
    def test_get_inmage(self):
        with open(PATH_IMAGE, "rb") as f:
            image_ideal = f.read()

        uri = "http://localhost:8000/mock/image"
        with http.get(uri) as res:
            data = res.body
            self.assertEqual(uri, res.uri)

        self.assertEqual(image_ideal, data)
Exemplo n.º 5
0
Arquivo: app.py Projeto: jjj999/bamboo
def request_tweets_history(uris: Uris, email: str) -> None:
    with http.get(
            uris.tweet,
            json=TweetsGetInput(email=email),
            datacls=TweetsGetOutput,
    ) as res:
        if res.ok:
            data = res.attach()
            print_tweets(data.tweets)
        else:
            print(res.body.decode(), end="\n\n")
Exemplo n.º 6
0
    def test_info(self):
        names = [rand_string(10) for _ in range(100)]

        for name in names:
            uri = f"http://localhost:8000/{name}/info"
            with http.get(uri, datacls=InfoResponse) as res:
                if res.ok:
                    body = res.attach()
                    self.assertEqual(body.name, name)
                else:
                    print(f"Request failed. Status code: {res.status}")
Exemplo n.º 7
0
    def test_multiply(self):
        get_num = lambda: random.randint(10**9, 10**10 - 1)
        num_pairs = [(get_num(), get_num()) for _ in range(100)]

        for num_1, num_2 in num_pairs:
            uri = f"http://localhost:8000/{num_1}/{num_2}/multiply"
            with http.get(uri, datacls=CalculationResult) as res:
                if res.ok:
                    body = res.attach()
                    self.assertEqual(body.result, num_1 * num_2)
                else:
                    print(f"Request failed. Status code: {res.status}")
Exemplo n.º 8
0
def request_image(uri: str, path_save: str) -> None:
    with http.get(uri, datacls=MockResponse) as res:
        if res.ok:
            data = res.attach()
            print(f"Date time: {data.datetime}")
            print("Saving image in the response...")
            with open(path_save, "wb") as f:
                f.write(decode2binary(data.image))
        else:
            print("Request failed.", end="\n\n")
            print("headers")
            print("-------")
            for key, val in res.headers.items():
                print(f"{key} : {val}")
Exemplo n.º 9
0
def request(uri: str, token: str) -> None:
    with http.get(
            uri,
            json=UpsideDownRequest(token=token),
            datacls=UpsideDownResponse,
    ) as res:
        print("Headers")
        print("-------")
        for k, v in res.headers.items():
            print(f"{k} : {v}")
        print()

        body = res.attach()
        print("Bodies")
        print("------")
        print(body.result)
Exemplo n.º 10
0
    def measure_downloading(self, uri: str, fpath: str) -> None:
        filesize = os.path.getsize(fpath)
        time_init = time.time()
        bufsize = 8192

        with http.get(uri) as res:
            with open(fpath, "rb") as fsrc:
                total = 0
                while True:
                    chunk = res.read(bufsize)
                    chunksize = len(chunk)
                    if not chunk:
                        break

                    total += chunksize
                    chunk_src = fsrc.read(chunksize)
                    self.assertEqual(chunk, chunk_src)
                self.assertEqual(total, filesize)

        time_total = time.time() - time_init
        FILE_CLIENT_LOG.write(
            f"Time of downloading {fpath} : {time_total} sec\n")
Exemplo n.º 11
0
 def test_form(self) -> None:
     with http.get(URI_FORM) as res:
         self.assertTrue(res.ok)
         self.assertEqual(res.body, IDEAL_DATA_FORM.__extract__())
Exemplo n.º 12
0
 def test_hello(self):
     with http.get("http://localhost:8000/hello") as res:
         self.assertEqual(res.body, b"Hello, World!")
Exemplo n.º 13
0
 def test_hoge(self) -> None:
     with http.get("http://localhost:8000/hoge/hoge") as res:
         self.assertTrue(res.ok)
Exemplo n.º 14
0
 def test_world(self) -> None:
     with http.get("http://localhost:8000/world") as res:
         self.assertTrue(res.ok)
Exemplo n.º 15
0
 def test_wsgi(self) -> None:
     with http.get(self.uri_wsgi) as res:
         self.assertFalse(res.ok)
         self.assertIn("X-Bamboo-AAA", res.headers)
         self.assertIn("X-Bamboo-BBB", res.headers)
Exemplo n.º 16
0
 def client():
     for i, path in enumerate(paths):
         uri = f"http://localhost:{8000 + i}/{path}"
         with http.get(uri) as res:
             self.assertEqual(res.body, IDEAL_RESNPONSE)
Exemplo n.º 17
0
 def test_wsgi(self):
     with http.get(self.uri_wsgi, headers=dict(RANDOM_HEADERS)) as res:
         self.assertTrue(res.ok)
Exemplo n.º 18
0
 def test_wsgi_correct(self):
     with http.get(self.uri_wsgi) as res:
         self.assertTrue(res.ok)
Exemplo n.º 19
0
 def test_client(self) -> None:
     for i in range(1, 4):
         with http.get(f"http://localhost:8000/v{i}/client") as res:
             self.assertTrue(res.ok)
Exemplo n.º 20
0
 def test_binary(self) -> None:
     with http.get(URI_BINARY) as res:
         self.assertTrue(res.ok)
         self.assertEqual(res.body, IDEAL_DATA_BINARY.__extract__())
Exemplo n.º 21
0
 def test_wsgi_output(self):
     with http.get(self.uri_wsgi) as res:
         self.assertTrue(res.ok)
         api_data = res.attach(TestJsonApi)
         self.assertIsInstance(api_data, TestJsonApi)
Exemplo n.º 22
0
 def test_json(self) -> None:
     with http.get(URI_JSON) as res:
         self.assertTrue(res.ok)
         self.assertEqual(res.body, IDEAL_DATA_JSON.__extract__())
Exemplo n.º 23
0
 def test_attributes(self):
     with http.get("http://localhost:8000/attributes") as res:
         self.assertTrue(res.ok)
Exemplo n.º 24
0
 def test_callback(self):
     with http.get("http://localhost:8000/callback") as res:
         self.assertTrue(res.ok)