-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
56 lines (48 loc) · 1.9 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# coding=utf-8
import json
import unittest
from geopy.geocoders import Nominatim
from domain.product import Product
from services import distancesort
class SearchedProduct:
def __init__(self, lat, lon):
self.lat = lat
self.lon = lon
self.distance = 0
class BaseTest(unittest.TestCase):
def test_json(self):
j = '{"fruits": ["apple", "banana", "orange"]}'
data = json.loads(j)
self.assertEqual(data['fruits'][0], 'apple')
j1 = '{"fruits": {"1":"apple", "2":"banana", "3":"orange"}}'
dat2 = json.loads(j1)
self.assertEqual(dat2['fruits']['1'], 'apple')
j2 = '{"category_name": "Холодные напитки",' \
'"photo_origin": "/upload/pos_cdb_67169/menu/product_1540043162_6.jpg",' \
'"price": {"1": "7500"},' \
'"product_id": "6",' \
'"product_name": "Лимонад",' \
'"spots": [{"spot_id": "1","price": "7500","profit": "6500","visible": "1"}]' \
'}'
p = Product.deserialize(json.loads(j2))
self.assertEqual(p.product_name, u'Лимонад')
self.assertEqual(p.price, '7500')
def test_geo(self):
geolocator = Nominatim(user_agent="foodle")
location = geolocator.geocode("175 5th Avenue NYC")
self.assertEquals(location.longtitude, "10")
self.assertTrue(location.address.index('New York'))
def test_sortnig(self):
arr=[SearchedProduct(1,100),
SearchedProduct(2, 100),
SearchedProduct(4, 100),
SearchedProduct(5, 100),
SearchedProduct(6, 100),
SearchedProduct(3, 100),
SearchedProduct(7, 100),
SearchedProduct(9, 100),
SearchedProduct(8, 100),
SearchedProduct(10, 100)]
base = SearchedProduct(11,100)
new_arr = distancesort.sort_by_distance(arr, base)
self.assertEquals(new_arr[0], arr[9])