Advertisement
Guest User

Untitled

a guest
Jul 16th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.56 KB | None | 0 0
  1. import json
  2. import time
  3. from tornado.httpclient import HTTPClient
  4. from po_lib.net import POClient
  5.  
  6. #host = "http://apidev2.pinogy.net" #"http://localhost:6544"
  7. #access_key = "jS8ChX5cBb2FbpMXdJR8" #"5BdfRhBq35LsGX33nfPw"
  8. #secret_key = "T6HzCjCxHMB4L6FqpPL3" #"6dW84SpTHXmzVnH32nDx"
  9.  
  10. host = "http://localhost:6544"
  11. access_key = "jS8ChX5cBb2FbpMXdJR8"
  12. secret_key = "T6HzCjCxHMB4L6FqpPL3"
  13.  
  14. http = HTTPClient()
  15. client = POClient(host=host, access_key=access_key, secret_key=secret_key)
  16.  
  17. request = client.POST("/apps/any/sessions", **{"password": "adminuser1"})
  18. result = http.fetch(request)
  19. print("!!!!!!!!!!")
  20. print(result.body)
  21. client.set(json.loads(result.body.decode()))
  22.  
  23.  
  24. # request = client.POST("/apps/any/webhooks", **{"qp_webh_app_id": 6, "qp_webh_event": "entity.update", "qp_webh_action": '{"action": "print"}'})
  25. # result = http.fetch(request)
  26. # print(result.body)
  27. #
  28. # request = client.GET("/apps/any/webhooks")
  29. # result = http.fetch(request)
  30. # print(result.body)
  31.  
  32. # Customer name is a person name?
  33. # Employee name is a person name?
  34. # Check entity deletion
  35. # Check entity update (all behaviours)
  36. # Manage raw quippet calls
  37. # Write tests for raw quippet calls
  38. # Update sub-tables
  39. # pet_tracker.pet_transactions
  40. # purchasing_and_receiving.transactions
  41.  
  42.  
  43. def test(method, url, params=None):
  44.     params = params or {}
  45.  
  46.     request = getattr(client, method)(url, **params)
  47.     result = http.fetch(request)
  48.     print(result.code)
  49.     print(result.body)
  50.  
  51.     return json.loads(str(result.body, encoding="utf-8"))
  52.  
  53.  
  54. def unique():
  55.     return str(time.time())
  56.  
  57. # test("POST", "/apps/any/queries/read__tbl__roles", {"qp_role_group": "Entity",  "qp_role_is_mfd": "False", "columns": "role_id, role_linked_id"})
  58.  
  59.  
  60. ####################
  61. # PRODUCT
  62. ####################
  63.  
  64.  
  65. PRODUCT_URL = "/apps/any/products"
  66.  
  67.  
  68. def create_product_1():
  69.     """Create a product with a minimal set of fields
  70.    """
  71.  
  72.     params = {
  73.         "qp_prod_name": "product{}".format(unique()),
  74.     }
  75.  
  76.     return test("POST", PRODUCT_URL, params)
  77.  
  78.  
  79. def create_product_2():
  80.     """Create a product with a full set of fields
  81.    """
  82.  
  83.     params = {
  84.         "qp_prod_name": "product{}".format(unique()),
  85.         "qp_ent_name": "manufacturer{}".format(unique()),
  86.         "qp_prodbar_barcode": unique(),
  87.         "qp_prdpr_cost": "1.0",
  88.         "qp_prdpr_price": "2.0"
  89.     }
  90.  
  91.     return test("POST", PRODUCT_URL, params)
  92.  
  93.  
  94. def delete_product():
  95.     """Delete a product
  96.    """
  97.  
  98.     resp = create_product_1()
  99.  
  100.     return test("DELETE", PRODUCT_URL + "/{}".format(resp["objects"]["product_id"]))
  101.  
  102.  
  103. def update_product():
  104.     """Update a product
  105.    """
  106.  
  107.     resp = create_product_1()
  108.  
  109.     params = {
  110.         "qp_prod_name": "product{}".format(unique())
  111.     }
  112.  
  113.     return test("PUT", PRODUCT_URL + "/{}".format(resp["objects"]["product_id"]), params)
  114.  
  115.  
  116. ####################
  117. # CUSTOMER
  118. ####################
  119.  
  120.  
  121. CUSTOMER_URL = "/apps/any/entities"
  122.  
  123.  
  124. def create_customer_1():
  125.     """Create a customer with a minimal set of fields
  126.    """
  127.  
  128.     params = {
  129.         "qp_ent_name": "My new customer",
  130.         "qp_erole_role_id": -3,
  131.     }
  132.  
  133.     return test("POST", CUSTOMER_URL, params)
  134.  
  135.  
  136. def create_customer_2():
  137.     """Create a customer with a full set of fields
  138.    """
  139.  
  140.     params = {
  141.         "qp_ent_name": "My new customer",
  142.         "qp_erole_role_id": -3,
  143.         "qp_eml_email": "test1+{0}@gmail.com, test2+{0}@gmail.com".format(unique()),
  144.         "qp_eml_email_type_id": "-1, -2",
  145.         "qp_cnum_contact_number_type_id": "-2, -1",
  146.         "qp_cnum_number": "+2, +1",
  147.         "qp_addr_address_type_id": "-2, -1",
  148.         "qp_addr_country_id": "231, 231",
  149.         "qp_addr_region_id": "4666, 4666",
  150.         "qp_addr_address_1": "addr2_1, addr1_1",
  151.         "qp_addr_address_2": "addr2_2, addr1_2",
  152.         "qp_addr_city": "novosibirsk, new york",
  153.         "qp_addr_postal_code": "20160, 20160"
  154.     }
  155.  
  156.     return test("POST", CUSTOMER_URL, params)
  157.  
  158.  
  159. def update_customer():
  160.     """Update a customer
  161.    """
  162.  
  163.     resp = create_customer_1()
  164.  
  165.     params = {
  166.         "qp_ent_name": "Customer{}".format(unique())
  167.     }
  168.  
  169.     return test("PUT", CUSTOMER_URL + "/{}".format(resp["entity_id"]), params)
  170.  
  171.  
  172. def delete_customer():
  173.     """Delete a customer
  174.    """
  175.  
  176.     resp = create_customer_1()
  177.  
  178.     return test("DELETE", CUSTOMER_URL + "/{}".format(resp["entity_id"]))
  179.  
  180.  
  181. ####################
  182. # LOCATION
  183. ####################
  184.  
  185.  
  186. LOCATION_URL = "/apps/any/entities"
  187.  
  188.  
  189. def create_location_1():
  190.     """Create a location with a minimal set of fields
  191.    """
  192.  
  193.     params = {
  194.         "qp_ent_name": "Location{}".format(unique()),
  195.         "qp_erole_role_id": -2,
  196.     }
  197.  
  198.     return test("POST", LOCATION_URL, params)
  199.  
  200.  
  201. def create_location_2():
  202.     """Create a location with a full set of fields
  203.    """
  204.  
  205.     params = {
  206.         "qp_ent_name": "Location{}".format(unique()),
  207.         "qp_erole_role_id": -2,
  208.         "qp_eml_email": "good+{0}@gmail.com, bad+{0}@gmail.com".format(unique()),
  209.         "qp_eml_email_type_id": "-1, -2",
  210.         "qp_cnum_contact_number_type_id": "-2, -1",
  211.         "qp_cnum_number": "+2, +1",
  212.         "qp_addr_address_type_id": "-2, -1",
  213.         "qp_addr_country_id": "231, 231",
  214.         "qp_addr_region_id": "4666, 4666",
  215.         "qp_addr_address_1": "addr2_1, addr1_1",
  216.         "qp_addr_address_2": "addr2_2, addr1_2",
  217.         "qp_addr_city": "novosibirsk, new york",
  218.         "qp_addr_postal_code": "20160, 20160"
  219.     }
  220.  
  221.     return test("POST", LOCATION_URL, params)
  222.  
  223.  
  224. def update_location():
  225.     """Update a location
  226.    """
  227.  
  228.     resp = create_location_1()
  229.  
  230.     params = {
  231.         "qp_ent_name": "Location{}".format(unique())
  232.     }
  233.  
  234.     return test("PUT", LOCATION_URL + "/{}".format(resp["entity_id"]), params)
  235.  
  236.  
  237. def delete_location():
  238.     """Delete a location
  239.    """
  240.  
  241.     resp = create_location_1()
  242.  
  243.     return test("DELETE", LOCATION_URL + "/{}".format(resp["entity_id"]))
  244.  
  245. # create_location_1()
  246. ####################
  247. # USER
  248. ####################
  249.  
  250.  
  251. USER_URL = "/apps/any/entities"
  252.  
  253.  
  254. def create_user_1():
  255.     """Create an user with a minimal set of fields
  256.    """
  257.  
  258.     params = {
  259.         "qp_ent_name": "User{}".format(unique()),
  260.         "qp_erole_role_id": "-10",
  261.         "qp_user_password": "{}".format(unique()),
  262.         "qp_user_display_name": "User{}".format(unique())
  263.     }
  264.  
  265.     return test("POST", USER_URL, params)
  266.  
  267.  
  268. def create_user_2():
  269.     """Create an user with a full set of fields
  270.    """
  271.     params = {
  272.         "qp_ent_name": "User{}".format(unique()),
  273.         "qp_erole_role_id": "-10, -9, -8, -7",
  274.         "qp_eml_email": "test1+{0}@gmail.com, test2+{0}@gmail.com".format(unique()),
  275.         "qp_eml_email_type_id": "-1, -2",
  276.         "qp_user_password": "{}".format(unique()),
  277.         "qp_user_display_name": "User".format(unique())
  278.     }
  279.  
  280.     return test("POST", USER_URL, params)
  281.  
  282.  
  283. def update_user_1():
  284.     """Update an user
  285.    """
  286.     resp = create_user_1()
  287.     id = resp["entity_id"]
  288.  
  289.     params = {
  290.         "qp_user_entity_id": id,
  291.         "qp_user_display_name": "User{}!".format(unique())
  292.     }
  293.  
  294.     return test("PUT", USER_URL + "/{}".format(id), params)
  295.  
  296.  
  297. def update_user_2():
  298.     """Update an user with different user sub-roles
  299.    """
  300.     resp = create_user_1()
  301.     id = resp["entity_id"]
  302.  
  303.     params = {
  304.         "qp_erole_role_id": "-10,-9"
  305.     }
  306.  
  307.     test("PUT", USER_URL + "/{}".format(id), params)
  308.  
  309.  
  310.     params = {
  311.         "qp_erole_role_id": "-10,-8"
  312.     }
  313.  
  314.     test("PUT", USER_URL + "/{}".format(id), params)
  315.  
  316.  
  317.     params = {
  318.         "qp_erole_role_id": "-10,-7"
  319.     }
  320.  
  321.     return test("PUT", USER_URL + "/{}".format(id), params)
  322.  
  323.  
  324. def delete_user():
  325.     """Delete an user
  326.    """
  327.     resp = create_user_1()
  328.  
  329.     return test("DELETE", USER_URL + "/{}".format(resp["entity_id"]))
  330.  
  331.  
  332. ####################
  333. # ENTITY MULTI-ROLE
  334. ####################
  335.  
  336.  
  337. ENTITY_URL = "/apps/any/entities"
  338.  
  339.  
  340. def create_entity():
  341.     """Create an entity with all possible roles
  342.    """
  343.     params = {
  344.         "qp_ent_name": "My new entity",
  345.         "qp_erole_role_id": "-3, -2, -10, -8, -9, -7",
  346.         "qp_eml_email": "test1+{0}@gmail.com, test2+{0}@gmail.com".format(unique()),
  347.         "qp_eml_email_type_id": "-1, -2",
  348.         "qp_cnum_contact_number_type_id": "-2, -1",
  349.         "qp_cnum_number": "+2, +1",
  350.         "qp_addr_address_type_id": "-2, -1",
  351.         "qp_addr_country_id": "231, 231",
  352.         "qp_addr_region_id": "4666, 4666",
  353.         "qp_addr_address_1": "addr2_1, addr1_1",
  354.         "qp_addr_address_2": "addr2_2, addr1_2",
  355.         "qp_addr_city": "novosibirsk, new york",
  356.         "qp_addr_postal_code": "20160, 20160",
  357.         "qp_user_password": "{}".format(unique()),
  358.         "qp_user_display_name": "User".format(unique())
  359.     }
  360.  
  361.     return test("POST", ENTITY_URL, params)
  362.  
  363.  
  364. def delete_entity():
  365.     """Delete an entity
  366.    """
  367.     resp = create_entity()
  368.  
  369.     return test("DELETE", ENTITY_URL + "/{}".format(resp["entity_id"]))
  370.  
  371.  
  372. def update_entity():
  373.     """Update an entity with different roles
  374.    """
  375.     resp = create_entity()
  376.  
  377.     test("PUT", ENTITY_URL + "/{}".format(resp["entity_id"]), {"qp_erole_role_id": "-3, -2"})
  378.  
  379.     return test("PUT", ENTITY_URL + "/{}".format(resp["entity_id"]), {"qp_erole_role_id": "-3, -2, -10"})
  380.  
  381.  
  382. ####################
  383. # TRANSACTION
  384. ####################
  385.  
  386.  
  387. def create_transaction():
  388.     location_id = create_location_1()["entity_id"]
  389.     params = {
  390.         "qp_txn_loc_entity_id": location_id,
  391.         "qp_txn_opened_by_user_entity_id": 169,
  392.         "qp_txn_type": "Sale",
  393.         # "txn_type_number": 0,
  394.         "qp_txn_status": "Opened",
  395.         "qp_txn_opened_device_id": 8
  396.     }
  397.  
  398.     resp = test("POST", "/apps/any/queries/create__tbl__transactions", params)
  399.     transaction_id = resp["objects"][0]["transaction_id"]
  400.  
  401.     for i in range(10):
  402.         params = {
  403.             "qp_txnline_transaction_id": transaction_id,
  404.             "qp_txnline_user_entity_id": 169,
  405.             "qp_txnline_device_id": 8,
  406.             "qp_txnline_product_id": 11700 + i,
  407.             "qp_txnline_product_description": "",
  408.             "qp_txnline_txn_type": "Sale"
  409.         }
  410.         resp = test("POST", "/apps/any/queries/create__tbl__transaction_lines", params)
  411.  
  412.     params = {
  413.         "qp_transaction_id": transaction_id,
  414.         "qp_txn_status": "Closed"
  415.     }
  416.     resp = test("POST", "/apps/any/queries/update__tbl__transactions", params)
  417.  
  418.  
  419.  
  420. ####################
  421. # MAIN
  422. ####################
  423.  
  424. if __name__ == "__main__":
  425.     create_transaction()
  426.     raise SystemExit(-1)
  427.  
  428.  
  429.  
  430. # request = client.POST("/apps/purchasing_and_receiving/purchase_order_exports", **{"qp_transaction_id": 2251})
  431. #    #/prt_purchase_order")
  432. #
  433. # request = client.POST("/apps/any/products", **{
  434. #     'qp_prdpr_price': '60',
  435. # 'qp_prod_name': 'Product 75005001',
  436. # 'qp_prodbar_barcode': '75005001',
  437. # 'qp_mfg_brand_id': 15,
  438. # 'qp_ent_name': 'Panama Hats inc',
  439. # 'qp_prdpr_cost': '50',
  440. # 'qp_mfgbr_brand_name': 'Panama Hat Model 5',
  441. # 'qp_prod_suppliers': 195,
  442. # 'qp_prdsplr_supplier_sku': '05005',
  443. # 'qp_prdsplr_min_order_qty': '1337',
  444. # 'qp_prdsplr_min_order_qty_multiple_required': False,
  445. #     #"qp_transaction_id": 2251
  446. # })
  447.  
  448. # request = client.PUT("/apps/any/entities/169", **{
  449. #     'qp_addr_country_id': 231,
  450. # 'qp_ent_notes': 'Alexandre Notes',
  451. # 'qp_cust_info': 'A Info',
  452. # 'qp_cust_loyalty_acct_code': '000002',
  453. # 'qp_eml_email_type_id': -1,
  454. # 'qp_cnum_contact_number_type_id': "-2, -1, -4, -5",
  455. # 'qp_ent_accessible_apps': "5",
  456. # 'qp_cnum_number': "33263436, 9876543120, 6546546544, 991933308",
  457. # 'qp_ent_accessible_locations': "165, 124, 104, 131, 136, 173",
  458. # 'qp_epn_names_before_key_names': 'Alexandre ',
  459. # 'qp_cnum_is_mfd': "False, False, False, False",
  460. # 'qp_user_username': 'Alex',
  461. # 'qp_pbreeder_usda_num': 'USDA 234',
  462. # 'qp_addr_address_type': '-1',
  463. # 'qp_addr_rank': '-2',
  464. # 'qp_pbreeder_state_num': 'STATE 234',
  465. # 'qp_erole_role_id': "-3, -4, -6, -10, -7",
  466. # 'qp_addr_postal_code': '33141',
  467. # 'qp_contact_number_id': "303, 304, 305, 306",
  468. # 'qp_usable_entity_id': 169,
  469. # 'qp_address_id': 25,
  470. # 'qp_ent_name': 'Alexandre Ramos (Cutomer, Breeder and Employee)',
  471. # 'qp_addr_city': 'A City',
  472. # 'qp_entity_id': 169,
  473. # 'qp_email_id': 149,
  474. # 'qp_addr_region_id': 4625,
  475. # 'qp_user_display_name': 'Alex',
  476. # 'qp_eml_email': 'alex@eml.com',
  477. # 'qp_cust_warning': 'A Warning',
  478. # 'qp_addr_address_1': 'A Address',
  479. # 'qp_epn_key_names': 'Ramos',
  480. # 'qp_addr_address_type_id': '-2',
  481. # 'qp_user_is_active': True
  482. # })
  483. # #    #/prt_purchase_order")
  484.  
  485.  
  486. # result = http.fetch(request)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement