Skip to content

Commit

Permalink
Add httpx import and update test methods
Browse files Browse the repository at this point in the history
  • Loading branch information
apmnt committed Mar 4, 2024
1 parent 51ad98e commit e886b73
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions tests/baseservicetestclass.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import asyncio
import unittest

import httpx
import postalservice
import logging
from postalservice.utils import SearchResults, SearchParams
Expand All @@ -17,7 +19,6 @@ def setUpClass(cls):
logger.addHandler(handler)
cls.logger = logger


def test_fetch_code_200(self):

sparams = SearchParams("comme des garcons")
Expand All @@ -27,45 +28,34 @@ def test_fetch_code_200(self):
# Assert that the status code is 200
self.assertEqual(res.status_code, 200)

def test_parse_results_count_over_zero(self):
def test_parse_results(self):

sparams = SearchParams("comme des garcons")
res = self.service.fetch_data(sparams.get_dict())
items = self.service.parse_response(res)
res: httpx.Response = self.service.fetch_data(sparams.get_dict())
print(res)
items: str = self.service.parse_response(res)
searchresults = SearchResults(items)
self.logger.info(searchresults)
self.logger.info("Length of items: %s", searchresults.count())

# Assert that the count is greater than 0
self.assertTrue(searchresults.count() > 0)

def test_search_by_size(self):

size_to_search = "XL"
sparams = SearchParams("comme des garcons", sizes=[size_to_search])
res = self.service.fetch_data(sparams.get_dict())
items = self.service.parse_response(res)
searchresults = SearchResults(items)
sizes = "Listing sizes:\n"
for i in range(searchresults.count()):
sizes += "Size: " + searchresults.get(i)["size"] + "\n"
self.logger.info(sizes)
sparams = SearchParams("comme des garcons", size=size_to_search)
searchresults = self.service.get_search_results(sparams.get_dict())

# Loop through the items and assert the size is XL
for i in range(searchresults.count()):
print(searchresults.get(i)["size"])
self.assertTrue(size_to_search in searchresults.get(i)["size"])

def test_search_by_size_async(self):

size_to_search = "XL"
sparams = SearchParams("comme des garcons", sizes=[size_to_search])
res = asyncio.run(self.service.fetch_data_async(sparams.get_dict()))
items = asyncio.run(self.service.parse_response_async(res))
searchresults = SearchResults(items)
sizes = "Listing sizes:\n"
for i in range(searchresults.count()):
sizes += "Size: " + searchresults.get(i)["size"] + "\n"
self.logger.info(sizes)
sparams = SearchParams("comme des garcons", size=size_to_search)
searchresults = asyncio.run(self.service.get_search_results_async(sparams.get_dict()))

# Loop through the items and assert the size is XL
for i in range(searchresults.count()):
Expand Down

0 comments on commit e886b73

Please sign in to comment.