Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

class Image(BaseModel):
url: str
# TODO, add the missing `attribute` for this class to pass the unittest
etag: str = None # The etag is required to pass the unittest but it's optional


class Product(BaseModel):
uid: str # unique id to identify product
# TODO, add the rest of Product information like: gender, images, product url and etc
# images: List[Image]

gender: str
url: str
price: float
size: str
category: str
description: str
images: List[Image]
21 changes: 17 additions & 4 deletions parsing_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,29 @@ def __init__(self, filename):
raise NotImplementedError

def __len__(self):
#TODO, implement "how to get number of products"
pass
"""Returns the number of products"""
if self.tree is not None:
root = self.tree.getroot()
return len(root)
return 0

def __getitem__(self, idx):
#TODO, implement the parsing product at `idx`
# TODO, implement the parsing product at `idx`
# For instance, get the following information and others from the XML:
# category = 'Papyon'
# price = 329.00
# gender = "male"
pass
if self.tree is not None:
root = self.tree.getroot()
product_info = {element.tag: element.text for element in root[idx]}
return Product(uid=product_info.get('productid', ""),
gender=product_info.get('gender', ""),
url=product_info.get('url', ""),
price=float(product_info.get('price', 0)),
size=product_info.get('sizes', ""),
description=product_info.get('title', ""),
category=product_info.get('categories', ""),
images=[Image(url=product_info.get('image', ""))])

# auto generated doc from super class
__len__.__doc__ = ClientParser.__len__.__doc__
Expand Down
23 changes: 11 additions & 12 deletions test/test_parsing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from model import Image, Product, BaseModel
from model import Image, Product
from parsing_client import ClientAParser
import pytest
import unittest
Expand All @@ -12,22 +12,22 @@ def setUp(self):

@pytest.mark.order1
def test_image_type(self):
image_url = """https://images.asos-media.com/products/"""
"""vestido-largo-y-plisado-de-dama-de-honor-en-rosa-exclusivo-de-tfnc/"""
"""13955198-2?$XXL$&wid=513&fit=constrain"""
image_url = ("""https://images.asos-media.com/products/"""
"""vestido-largo-y-plisado-de-dama-de-honor-en-rosa-exclusivo-de-tfnc/"""
"""13955198-2?$XXL$&wid=513&fit=constrain""")
for etag in ["xx", None]:
image = Image(url=image_url, etag=etag)
self.assertTrue(hasattr(image, "etag"))
self.assertIsInstance(image.etag, (str, type(None)))

@pytest.mark.order2
def test_product_type(self):
image_url = """https://images.asos-media.com/products/"""
"""vestido-largo-y-plisado-de-dama-de-honor-en-rosa-exclusivo-de-tfnc/"""
"""13955198-2?$XXL$&wid=513&fit=constrain"""
product_url = """https://www.asos.com/es/tfnc/"""
"""vestido-largo-y-plisado-de-dama-de-honor-en-rosa-exclusivo-de-tfnc/"""
"""prd/13955198?clr=rosa&colourWayId=16579390&SearchQuery=&cid=17245"""
image_url = ("""https://images.asos-media.com/products/"""
"""vestido-largo-y-plisado-de-dama-de-honor-en-rosa-exclusivo-de-tfnc/"""
"""13955198-2?$XXL$&wid=513&fit=constrain""")
product_url = ("""https://www.asos.com/es/tfnc/"""
"""vestido-largo-y-plisado-de-dama-de-honor-en-rosa-exclusivo-de-tfnc/"""
"""prd/13955198?clr=rosa&colourWayId=16579390&SearchQuery=&cid=17245""")
description = "Vestido largo y plisado de dama de honor en rosa exclusivo de TFNC"
images = [Image(url=image_url) for x in range(5)] # 5 fake images
product = Product(uid="sku1000", images=images, gender="female",
Expand Down Expand Up @@ -73,12 +73,11 @@ def test_parser_getitem(self):
self.assertEqual(product.description, "Dsquared2 Siyah İpek Papyon")
self.assertEqual(product.url,
"https://www.beymen.com/p_dsquared2-siyah-ipek-papyon_303527")



def tearDown(self):
pass


if __name__ == '__main__':

unittest.main()