Skip to content

Instantly share code, notes, and snippets.

@nietzscheson
Created May 1, 2023 17:20
Show Gist options
  • Save nietzscheson/d5a23534abb3832af834354af1143045 to your computer and use it in GitHub Desktop.
Save nietzscheson/d5a23534abb3832af834354af1143045 to your computer and use it in GitHub Desktop.
Easy Broker Properties Gist
import os
import json
import unittest
from unittest.mock import MagicMock
from urllib.request import urlopen, Request
class EasyBrokerPropertiesResponse:
def easy_broker_properties_response(self):
api_key = os.environ["API_KEY"]
url = "https://api.easybroker.com/v1/properties?page=1&limit=20"
headers = {"accept": "application/json", "X-Authorization": api_key}
request = Request(url, headers=headers)
response = urlopen(request)
return json.loads(response.read().decode(response.info().get_param('charset') or 'utf-8'))
class TestEasyBroker(unittest.TestCase):
def test_easy_broker_properties(self):
requestObject = EasyBrokerPropertiesResponse()
contents = [
{
"agent": f"agent_{x}",
"public_id": f"id_{x}",
"title": f"Property name {x}",
"title_image_full": "https://assets.easybroker.com/property_images/2973769/47323310/EB-KK3769.jpg?version=1652732411",
"title_image_thumb": "https://assets.easybroker.com/property_images/2973769/47323310/medium_EB-KK3769.jpg?version=1652732411",
"bedrooms": 4,
"bathrooms": 5,
"parking_spaces": 5,
"location": "Casa en Bosque de las Lomas, Miguel Hidalgo",
"property_type": "PLUS",
"updated_at": "2023-05-01 16:30:00.123456",
"show_prices": False,
"share_commission": False,
}
for x in range(1, 11)
]
returnObjectMock = {
"pagination": {
"limit": 20,
"page": 1,
"total": 10,
"next_page": 2
},
"content": contents
}
requestObject.easy_broker_properties_response = MagicMock(return_value=returnObjectMock)
responseObject = requestObject.easy_broker_properties_response()
pagination = responseObject["pagination"]
content = responseObject["content"]
self.assertEqual(20, pagination["limit"])
self.assertEqual(1, pagination["page"])
self.assertEqual(10, pagination["total"])
self.assertEqual(2, pagination["next_page"])
self.assertEqual(contents, content)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment