Subversion Repositories SmartDukaan

Rev

Rev 3008 | Rev 3365 | Go to most recent revision | 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
 
13
inventory_client.__start__()
14
 
15
client = inventory_client.get_client()
2207 ankur.sing 16
"""
1506 chandransh 17
#deals = client.getBestDeals()
18
#print deals
384 ashish 19
 
1506 chandransh 20
warehouse_id, items_in_inventory = client.getItemAvailabilityAtLocation(0, 132)
21
print warehouse_id
2065 ankur.sing 22
print items_in_inventory
23
"""
24
 
25
 
26
def test_validate():
27
    # Item prices should follow the following validations.
28
    # mrp > sellingPrice
29
    # mrp > mop
30
    # xferPrice < mop
31
 
32
    item = Item()
33
    item.id = 1
34
    item.productGroup = "Handsets"
35
    item.modelNumber = "MI-310"
36
    item.brand = "Spice"
37
    item.color = "Red"
38
 
39
    vip = VendorItemPricing()
40
    vip.vendorId = 1
41
 
42
    set_prices1(item, vip)
43
    set_prices2(item, vip)
44
    return
45
 
46
def set_prices1(item, vip):
47
    #Test Case 1 (mrp < sellingPrice)
48
    item.mrp = 220.50
49
    item.sellingPrice = 225.50
50
 
51
    vip.mop = 111
52
    vip.dealerPrice = 111
53
    vip.transferPrice = 111
54
    validate(item,vip)
55
    return
56
 
57
def set_prices2(item, vip):
58
    #Test Case 2 (mrp < mop)
59
    item.mrp = 230.50
60
    item.sellingPrice = 225.50
61
 
62
    vip.mop = 235.0
63
    vip.dealerPrice = 210.0
64
    vip.transferPrice = 200.5
65
    validate(item,vip)
66
    return
67
 
68
 
69
def validate(item, vip):
2222 chandransh 70
#    try:
71
#        #validate_prices(item, vip)
72
#    except Exception as ex:
73
#        print ex
74
#        return
75
#    print 'prices validated'
2065 ankur.sing 76
    return
77
 
2304 ankur.sing 78
def test_similar_item():
2207 ankur.sing 79
    print (client.checkSimilarItem('handset', 'spice', 'bldk', None))
80
    print (client.checkSimilarItem('handset', 'spice', 'bldk', ''))
81
    print (client.checkSimilarItem('handset', 'spice', 'bldk', 'Black'))
82
 
2304 ankur.sing 83
def test_change_item_status():
2251 ankur.sing 84
    #changeItemStatus method testing
85
    client.changeItemStatus(1, time, status.PAUSED)
86
    item = client.getItem(1)
87
    print 'item status = ' + str(item.itemStatus) + ", desc = " + item.status_description
88
 
89
    client.changeItemStatus(1, time, status.PHASED_OUT)
90
    item = client.getItem(1)
91
    print 'item status = ' + str(item.itemStatus) + ", desc = " + item.status_description
2304 ankur.sing 92
 
93
def test_check_risky_item():
2251 ankur.sing 94
    #mark_risky_item method testing. It is called from the following 3 methods.
2497 ankur.sing 95
    availability = {"battery|nokia|bl 4b|na":1}
2251 ankur.sing 96
    client.updateInventory(2, time, availability)
2497 ankur.sing 97
    #client.reserveItemInWarehouse(167, 1, 1)
98
    #client.reduceReservationCount(167, 2, 1)
2304 ankur.sing 99
 
2809 rajveer 100
def test_update_similarity_index():
101
 
102
 
3008 rajveer 103
    items=client.getSimilarItemsCatalogIds(3, 2, 1441)
2809 rajveer 104
    print items
105
 
2304 ankur.sing 106
def test_logging(item_id, risky):
107
    logfile = open(os.getenv("HOME")+'/'+'riskyNew.log', 'a')
108
    logfile.write(str(strftime("%Y-%m-%d %H:%M:%S")) + ', ItemId=' + str(item_id) + ', ' + str(risky) + '\n')
109
 
2963 chandransh 110
def test_get_best_deal_catalog_ids():
111
    print client.getBestDealsCatalogIds(0, 20, 'Nokia', -1);
112
 
2304 ankur.sing 113
if __name__ == '__main__':
114
    time = to_py_date(datetime.datetime.now())
115
    #test_validate()
116
    #test_similar_item()
117
    #test_change_item_status()
2809 rajveer 118
    #test_check_risky_item()
2304 ankur.sing 119
    #test_logging(5, True)
3008 rajveer 120
    test_update_similarity_index()
121
    #test_get_best_deal_catalog_ids()
2497 ankur.sing 122