Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import time
- from tornado.httpclient import HTTPClient
- from po_lib.net import POClient
- #host = "http://apidev2.pinogy.net" #"http://localhost:6544"
- #access_key = "jS8ChX5cBb2FbpMXdJR8" #"5BdfRhBq35LsGX33nfPw"
- #secret_key = "T6HzCjCxHMB4L6FqpPL3" #"6dW84SpTHXmzVnH32nDx"
- host = "http://localhost:6544"
- access_key = "jS8ChX5cBb2FbpMXdJR8"
- secret_key = "T6HzCjCxHMB4L6FqpPL3"
- http = HTTPClient()
- client = POClient(host=host, access_key=access_key, secret_key=secret_key)
- request = client.POST("/apps/any/sessions", **{"password": "adminuser1"})
- result = http.fetch(request)
- print("!!!!!!!!!!")
- print(result.body)
- client.set(json.loads(result.body.decode()))
- # request = client.POST("/apps/any/webhooks", **{"qp_webh_app_id": 6, "qp_webh_event": "entity.update", "qp_webh_action": '{"action": "print"}'})
- # result = http.fetch(request)
- # print(result.body)
- #
- # request = client.GET("/apps/any/webhooks")
- # result = http.fetch(request)
- # print(result.body)
- # Customer name is a person name?
- # Employee name is a person name?
- # Check entity deletion
- # Check entity update (all behaviours)
- # Manage raw quippet calls
- # Write tests for raw quippet calls
- # Update sub-tables
- # pet_tracker.pet_transactions
- # purchasing_and_receiving.transactions
- def test(method, url, params=None):
- params = params or {}
- request = getattr(client, method)(url, **params)
- result = http.fetch(request)
- print(result.code)
- print(result.body)
- return json.loads(str(result.body, encoding="utf-8"))
- def unique():
- return str(time.time())
- # test("POST", "/apps/any/queries/read__tbl__roles", {"qp_role_group": "Entity", "qp_role_is_mfd": "False", "columns": "role_id, role_linked_id"})
- ####################
- # PRODUCT
- ####################
- PRODUCT_URL = "/apps/any/products"
- def create_product_1():
- """Create a product with a minimal set of fields
- """
- params = {
- "qp_prod_name": "product{}".format(unique()),
- }
- return test("POST", PRODUCT_URL, params)
- def create_product_2():
- """Create a product with a full set of fields
- """
- params = {
- "qp_prod_name": "product{}".format(unique()),
- "qp_ent_name": "manufacturer{}".format(unique()),
- "qp_prodbar_barcode": unique(),
- "qp_prdpr_cost": "1.0",
- "qp_prdpr_price": "2.0"
- }
- return test("POST", PRODUCT_URL, params)
- def delete_product():
- """Delete a product
- """
- resp = create_product_1()
- return test("DELETE", PRODUCT_URL + "/{}".format(resp["objects"]["product_id"]))
- def update_product():
- """Update a product
- """
- resp = create_product_1()
- params = {
- "qp_prod_name": "product{}".format(unique())
- }
- return test("PUT", PRODUCT_URL + "/{}".format(resp["objects"]["product_id"]), params)
- ####################
- # CUSTOMER
- ####################
- CUSTOMER_URL = "/apps/any/entities"
- def create_customer_1():
- """Create a customer with a minimal set of fields
- """
- params = {
- "qp_ent_name": "My new customer",
- "qp_erole_role_id": -3,
- }
- return test("POST", CUSTOMER_URL, params)
- def create_customer_2():
- """Create a customer with a full set of fields
- """
- params = {
- "qp_ent_name": "My new customer",
- "qp_erole_role_id": -3,
- "qp_eml_email": "test1+{0}@gmail.com, test2+{0}@gmail.com".format(unique()),
- "qp_eml_email_type_id": "-1, -2",
- "qp_cnum_contact_number_type_id": "-2, -1",
- "qp_cnum_number": "+2, +1",
- "qp_addr_address_type_id": "-2, -1",
- "qp_addr_country_id": "231, 231",
- "qp_addr_region_id": "4666, 4666",
- "qp_addr_address_1": "addr2_1, addr1_1",
- "qp_addr_address_2": "addr2_2, addr1_2",
- "qp_addr_city": "novosibirsk, new york",
- "qp_addr_postal_code": "20160, 20160"
- }
- return test("POST", CUSTOMER_URL, params)
- def update_customer():
- """Update a customer
- """
- resp = create_customer_1()
- params = {
- "qp_ent_name": "Customer{}".format(unique())
- }
- return test("PUT", CUSTOMER_URL + "/{}".format(resp["entity_id"]), params)
- def delete_customer():
- """Delete a customer
- """
- resp = create_customer_1()
- return test("DELETE", CUSTOMER_URL + "/{}".format(resp["entity_id"]))
- ####################
- # LOCATION
- ####################
- LOCATION_URL = "/apps/any/entities"
- def create_location_1():
- """Create a location with a minimal set of fields
- """
- params = {
- "qp_ent_name": "Location{}".format(unique()),
- "qp_erole_role_id": -2,
- }
- return test("POST", LOCATION_URL, params)
- def create_location_2():
- """Create a location with a full set of fields
- """
- params = {
- "qp_ent_name": "Location{}".format(unique()),
- "qp_erole_role_id": -2,
- "qp_eml_email": "good+{0}@gmail.com, bad+{0}@gmail.com".format(unique()),
- "qp_eml_email_type_id": "-1, -2",
- "qp_cnum_contact_number_type_id": "-2, -1",
- "qp_cnum_number": "+2, +1",
- "qp_addr_address_type_id": "-2, -1",
- "qp_addr_country_id": "231, 231",
- "qp_addr_region_id": "4666, 4666",
- "qp_addr_address_1": "addr2_1, addr1_1",
- "qp_addr_address_2": "addr2_2, addr1_2",
- "qp_addr_city": "novosibirsk, new york",
- "qp_addr_postal_code": "20160, 20160"
- }
- return test("POST", LOCATION_URL, params)
- def update_location():
- """Update a location
- """
- resp = create_location_1()
- params = {
- "qp_ent_name": "Location{}".format(unique())
- }
- return test("PUT", LOCATION_URL + "/{}".format(resp["entity_id"]), params)
- def delete_location():
- """Delete a location
- """
- resp = create_location_1()
- return test("DELETE", LOCATION_URL + "/{}".format(resp["entity_id"]))
- # create_location_1()
- ####################
- # USER
- ####################
- USER_URL = "/apps/any/entities"
- def create_user_1():
- """Create an user with a minimal set of fields
- """
- params = {
- "qp_ent_name": "User{}".format(unique()),
- "qp_erole_role_id": "-10",
- "qp_user_password": "{}".format(unique()),
- "qp_user_display_name": "User{}".format(unique())
- }
- return test("POST", USER_URL, params)
- def create_user_2():
- """Create an user with a full set of fields
- """
- params = {
- "qp_ent_name": "User{}".format(unique()),
- "qp_erole_role_id": "-10, -9, -8, -7",
- "qp_eml_email": "test1+{0}@gmail.com, test2+{0}@gmail.com".format(unique()),
- "qp_eml_email_type_id": "-1, -2",
- "qp_user_password": "{}".format(unique()),
- "qp_user_display_name": "User".format(unique())
- }
- return test("POST", USER_URL, params)
- def update_user_1():
- """Update an user
- """
- resp = create_user_1()
- id = resp["entity_id"]
- params = {
- "qp_user_entity_id": id,
- "qp_user_display_name": "User{}!".format(unique())
- }
- return test("PUT", USER_URL + "/{}".format(id), params)
- def update_user_2():
- """Update an user with different user sub-roles
- """
- resp = create_user_1()
- id = resp["entity_id"]
- params = {
- "qp_erole_role_id": "-10,-9"
- }
- test("PUT", USER_URL + "/{}".format(id), params)
- params = {
- "qp_erole_role_id": "-10,-8"
- }
- test("PUT", USER_URL + "/{}".format(id), params)
- params = {
- "qp_erole_role_id": "-10,-7"
- }
- return test("PUT", USER_URL + "/{}".format(id), params)
- def delete_user():
- """Delete an user
- """
- resp = create_user_1()
- return test("DELETE", USER_URL + "/{}".format(resp["entity_id"]))
- ####################
- # ENTITY MULTI-ROLE
- ####################
- ENTITY_URL = "/apps/any/entities"
- def create_entity():
- """Create an entity with all possible roles
- """
- params = {
- "qp_ent_name": "My new entity",
- "qp_erole_role_id": "-3, -2, -10, -8, -9, -7",
- "qp_eml_email": "test1+{0}@gmail.com, test2+{0}@gmail.com".format(unique()),
- "qp_eml_email_type_id": "-1, -2",
- "qp_cnum_contact_number_type_id": "-2, -1",
- "qp_cnum_number": "+2, +1",
- "qp_addr_address_type_id": "-2, -1",
- "qp_addr_country_id": "231, 231",
- "qp_addr_region_id": "4666, 4666",
- "qp_addr_address_1": "addr2_1, addr1_1",
- "qp_addr_address_2": "addr2_2, addr1_2",
- "qp_addr_city": "novosibirsk, new york",
- "qp_addr_postal_code": "20160, 20160",
- "qp_user_password": "{}".format(unique()),
- "qp_user_display_name": "User".format(unique())
- }
- return test("POST", ENTITY_URL, params)
- def delete_entity():
- """Delete an entity
- """
- resp = create_entity()
- return test("DELETE", ENTITY_URL + "/{}".format(resp["entity_id"]))
- def update_entity():
- """Update an entity with different roles
- """
- resp = create_entity()
- test("PUT", ENTITY_URL + "/{}".format(resp["entity_id"]), {"qp_erole_role_id": "-3, -2"})
- return test("PUT", ENTITY_URL + "/{}".format(resp["entity_id"]), {"qp_erole_role_id": "-3, -2, -10"})
- ####################
- # TRANSACTION
- ####################
- def create_transaction():
- location_id = create_location_1()["entity_id"]
- params = {
- "qp_txn_loc_entity_id": location_id,
- "qp_txn_opened_by_user_entity_id": 169,
- "qp_txn_type": "Sale",
- # "txn_type_number": 0,
- "qp_txn_status": "Opened",
- "qp_txn_opened_device_id": 8
- }
- resp = test("POST", "/apps/any/queries/create__tbl__transactions", params)
- transaction_id = resp["objects"][0]["transaction_id"]
- for i in range(10):
- params = {
- "qp_txnline_transaction_id": transaction_id,
- "qp_txnline_user_entity_id": 169,
- "qp_txnline_device_id": 8,
- "qp_txnline_product_id": 11700 + i,
- "qp_txnline_product_description": "",
- "qp_txnline_txn_type": "Sale"
- }
- resp = test("POST", "/apps/any/queries/create__tbl__transaction_lines", params)
- params = {
- "qp_transaction_id": transaction_id,
- "qp_txn_status": "Closed"
- }
- resp = test("POST", "/apps/any/queries/update__tbl__transactions", params)
- ####################
- # MAIN
- ####################
- if __name__ == "__main__":
- create_transaction()
- raise SystemExit(-1)
- # request = client.POST("/apps/purchasing_and_receiving/purchase_order_exports", **{"qp_transaction_id": 2251})
- # #/prt_purchase_order")
- #
- # request = client.POST("/apps/any/products", **{
- # 'qp_prdpr_price': '60',
- # 'qp_prod_name': 'Product 75005001',
- # 'qp_prodbar_barcode': '75005001',
- # 'qp_mfg_brand_id': 15,
- # 'qp_ent_name': 'Panama Hats inc',
- # 'qp_prdpr_cost': '50',
- # 'qp_mfgbr_brand_name': 'Panama Hat Model 5',
- # 'qp_prod_suppliers': 195,
- # 'qp_prdsplr_supplier_sku': '05005',
- # 'qp_prdsplr_min_order_qty': '1337',
- # 'qp_prdsplr_min_order_qty_multiple_required': False,
- # #"qp_transaction_id": 2251
- # })
- # request = client.PUT("/apps/any/entities/169", **{
- # 'qp_addr_country_id': 231,
- # 'qp_ent_notes': 'Alexandre Notes',
- # 'qp_cust_info': 'A Info',
- # 'qp_cust_loyalty_acct_code': '000002',
- # 'qp_eml_email_type_id': -1,
- # 'qp_cnum_contact_number_type_id': "-2, -1, -4, -5",
- # 'qp_ent_accessible_apps': "5",
- # 'qp_cnum_number': "33263436, 9876543120, 6546546544, 991933308",
- # 'qp_ent_accessible_locations': "165, 124, 104, 131, 136, 173",
- # 'qp_epn_names_before_key_names': 'Alexandre ',
- # 'qp_cnum_is_mfd': "False, False, False, False",
- # 'qp_user_username': 'Alex',
- # 'qp_pbreeder_usda_num': 'USDA 234',
- # 'qp_addr_address_type': '-1',
- # 'qp_addr_rank': '-2',
- # 'qp_pbreeder_state_num': 'STATE 234',
- # 'qp_erole_role_id': "-3, -4, -6, -10, -7",
- # 'qp_addr_postal_code': '33141',
- # 'qp_contact_number_id': "303, 304, 305, 306",
- # 'qp_usable_entity_id': 169,
- # 'qp_address_id': 25,
- # 'qp_ent_name': 'Alexandre Ramos (Cutomer, Breeder and Employee)',
- # 'qp_addr_city': 'A City',
- # 'qp_entity_id': 169,
- # 'qp_email_id': 149,
- # 'qp_addr_region_id': 4625,
- # 'qp_user_display_name': 'Alex',
- # 'qp_eml_email': 'alex@eml.com',
- # 'qp_cust_warning': 'A Warning',
- # 'qp_addr_address_1': 'A Address',
- # 'qp_epn_key_names': 'Ramos',
- # 'qp_addr_address_type_id': '-2',
- # 'qp_user_is_active': True
- # })
- # # #/prt_purchase_order")
- # result = http.fetch(request)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement