Subversion Repositories SmartDukaan

Rev

Rev 4370 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2065 ankur.sing 1
from shop2020.thriftpy.model.v1.catalog.ttypes import Item, status, Warehouse,\
2
    VendorItemPricing
122 ashish 3
import datetime
2304 ankur.sing 4
import os
5
from time import strftime
3133 rajveer 6
from shop2020.clients.CatalogClient import CatalogClient
2251 ankur.sing 7
from shop2020.utils.Utils import to_java_date, to_py_date
2207 ankur.sing 8
from shop2020.model.v1.catalog.impl.DataAcessors import validate_item_prices, validate_vendor_prices
100 ashish 9
 
2207 ankur.sing 10
 
3133 rajveer 11
inventory_client = CatalogClient()
384 ashish 12
client = inventory_client.get_client()
2207 ankur.sing 13
"""
1506 chandransh 14
#deals = client.getBestDeals()
15
#print deals
384 ashish 16
 
1506 chandransh 17
warehouse_id, items_in_inventory = client.getItemAvailabilityAtLocation(0, 132)
18
print warehouse_id
2065 ankur.sing 19
print items_in_inventory
20
"""
21
 
22
 
23
def test_validate():
24
    # Item prices should follow the following validations.
25
    # mrp > sellingPrice
26
    # mrp > mop
27
    # xferPrice < mop
28
 
29
    item = Item()
30
    item.id = 1
31
    item.productGroup = "Handsets"
32
    item.modelNumber = "MI-310"
33
    item.brand = "Spice"
34
    item.color = "Red"
35
 
36
    vip = VendorItemPricing()
37
    vip.vendorId = 1
38
 
39
    set_prices1(item, vip)
40
    set_prices2(item, vip)
41
    return
42
 
43
def set_prices1(item, vip):
44
    #Test Case 1 (mrp < sellingPrice)
45
    item.mrp = 220.50
46
    item.sellingPrice = 225.50
47
 
48
    vip.mop = 111
49
    vip.dealerPrice = 111
50
    vip.transferPrice = 111
51
    validate(item,vip)
52
    return
53
 
54
def set_prices2(item, vip):
55
    #Test Case 2 (mrp < mop)
56
    item.mrp = 230.50
57
    item.sellingPrice = 225.50
58
 
59
    vip.mop = 235.0
60
    vip.dealerPrice = 210.0
61
    vip.transferPrice = 200.5
62
    validate(item,vip)
63
    return
64
 
65
 
66
def validate(item, vip):
2222 chandransh 67
#    try:
68
#        #validate_prices(item, vip)
69
#    except Exception as ex:
70
#        print ex
71
#        return
72
#    print 'prices validated'
2065 ankur.sing 73
    return
74
 
2304 ankur.sing 75
def test_similar_item():
2207 ankur.sing 76
    print (client.checkSimilarItem('handset', 'spice', 'bldk', None))
77
    print (client.checkSimilarItem('handset', 'spice', 'bldk', ''))
78
    print (client.checkSimilarItem('handset', 'spice', 'bldk', 'Black'))
79
 
2304 ankur.sing 80
def test_change_item_status():
2251 ankur.sing 81
    #changeItemStatus method testing
82
    client.changeItemStatus(1, time, status.PAUSED)
83
    item = client.getItem(1)
84
    print 'item status = ' + str(item.itemStatus) + ", desc = " + item.status_description
85
 
86
    client.changeItemStatus(1, time, status.PHASED_OUT)
87
    item = client.getItem(1)
88
    print 'item status = ' + str(item.itemStatus) + ", desc = " + item.status_description
2304 ankur.sing 89
 
90
def test_check_risky_item():
2251 ankur.sing 91
    #mark_risky_item method testing. It is called from the following 3 methods.
2497 ankur.sing 92
    availability = {"battery|nokia|bl 4b|na":1}
2251 ankur.sing 93
    client.updateInventory(2, time, availability)
2497 ankur.sing 94
    #client.reserveItemInWarehouse(167, 1, 1)
95
    #client.reduceReservationCount(167, 2, 1)
2304 ankur.sing 96
 
2809 rajveer 97
def test_update_similarity_index():
98
 
99
 
3008 rajveer 100
    items=client.getSimilarItemsCatalogIds(3, 2, 1441)
2809 rajveer 101
    print items
102
 
2304 ankur.sing 103
def test_logging(item_id, risky):
104
    logfile = open(os.getenv("HOME")+'/'+'riskyNew.log', 'a')
105
    logfile.write(str(strftime("%Y-%m-%d %H:%M:%S")) + ', ItemId=' + str(item_id) + ', ' + str(risky) + '\n')
106
 
2963 chandransh 107
def test_get_best_deal_catalog_ids():
108
    print client.getBestDealsCatalogIds(0, 20, 'Nokia', -1);
109
 
3365 chandransh 110
def test_get_all_items():
111
    items = client.getAllItemsByStatus(status.ACTIVE)
112
    for item in items:
113
        print item.itemInventory
3376 rajveer 114
 
115
def test_is_alive():
116
    print client.isAlive()
3503 chandransh 117
 
118
def test_get_availability_at_location():
119
    print client.getItemAvailabilityAtLocation(0, 1)
3365 chandransh 120
 
4024 chandransh 121
def test_get_pending_orders_inventory():
122
    print client.getPendingOrdersInventory()
4332 anupam.sin 123
 
124
def testGetVendorsForWarehouse(warehouseId):
125
    vendors = client.getVendorsForWarehouse(warehouseId)
126
    for vendor in vendors:
127
        print vendor
128
 
129
def testGetWarehousesForVendor(vendorId):
130
    warehouses =  client.getWarehousesForVendor(vendorId)
131
    for warehouse in warehouses:
132
        print warehouse
133
def testVendorItemPricing(itemId, vendorId):
134
    print client.getItemPricing(itemId, vendorId)
4406 anupam.sin 135
 
136
def testArgs(string, floatvar):
137
    print string
138
    print floatvar
139
 
2304 ankur.sing 140
if __name__ == '__main__':
141
    time = to_py_date(datetime.datetime.now())
142
    #test_validate()
143
    #test_similar_item()
144
    #test_change_item_status()
2809 rajveer 145
    #test_check_risky_item()
2304 ankur.sing 146
    #test_logging(5, True)
3365 chandransh 147
    #test_update_similarity_index()
3008 rajveer 148
    #test_get_best_deal_catalog_ids()
3376 rajveer 149
    #test_get_all_items()
3503 chandransh 150
    #test_is_alive()
4024 chandransh 151
    #test_get_availability_at_location()
4332 anupam.sin 152
    #test_get_pending_orders_inventory()
4406 anupam.sin 153
    print client.getItemAvailabilityAtLocation(0, 9999)
154
    print "hello"
155
    #testGetWarehousesForVendor(1)
156
    #testGetVendorsForWarehouse(7)
157
    #testVendorItemPricing(5,-1)
158
    #string = "hello"
159
    #floatvar = 5.5
160
    #testArgs(string, floatvar)
161
    #testArgs(string, None)