2017-09-10 17 views
0

Shopify Pythonライブラリを使用して、店舗の注文、割引などを処理しています。私は価格ルールと割引の作成と削除を含むいくつかのテストを行っています。Shopify API:割引と価格ルールの削除

def test_get_discount(self): 
    random_number_string = str(randint(0,10000)) 
    price_rule = shopify.PriceRule.create({ 
     'title': 'TEST-PRICERULE-' + random_number_string, 
     'target_type': 'line_item', 
     'target_selection': 'all', 
     'allocation_method': 'across', 
     'value_type': 'fixed_amount', 
     'value': -1000, 
     'once_per_customer': True, 
     'customer_selection': 'all', 
     'starts_at': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 
    }) 
    discount = shopify.DiscountCode.create({ 
     'price_rule_id': price_rule.id, 
     'code': 'TEST-DISCOUNT-' + random_number_string, 
     'usage_count': 1, 
     'value_type': 'fixed_amount', 
     'value': -1000 
    }) 
    fetched_price_rule = shopify_utils.get_discount_codes('TEST-PRICERULE-' + random_number_string) 
    self.assertIsNotNone(fetched_price_rule) 
    #deleted_discount = discount.destroy() 
    #self.assertIsNone(deleted_discount) 
    deleted_price_rule = price_rule.delete('discounts') 
    self.assertIsNone(deleted_price_rule) 

削除までのすべてが適切に機能します。そう、私はそれがネストされたリソース名のために私を求めていますことを信じ

deleted_price_rule = price_rule.delete() 
TypeError: _instance_delete() missing 1 required positional argument: 'method_name' 

:それは次のようでエラー出て、私はまた、問題はないとの割引を削除することができるよ、しかし、私は、価格ルールを削除しようとすると、私はdiscountsdiscount_codeなどのようなものを渡してみましたが、運はありません。私はpyactiveresouceがそのmethod_nameを使って関連するリソースを削除するためのURLを作成しているのを見ていますが、そのような場合にはあまりよく文書化されていないので、

私は(間違った)メソッド名を指定したとき、私はこのエラーを取得:

pyactiveresource.connection.ClientError: Response(code=406, body="b''", headers={'Server': 'nginx', 'Date': 'Sun, 10 Sep 2017 00:57:28 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'close', 'X-Sorting-Hat-PodId': '23', 'X-Sorting-Hat-PodId-Cached': '0', 'X-Sorting-Hat-ShopId': '13486411', 'X-Sorting-Hat-Section': 'pod', 'X-Sorting-Hat-ShopId-Cached': '0', 'Referrer-Policy': 'origin-when-cross-origin', 'X-Frame-Options': 'DENY', 'X-ShopId': '13486411', 'X-ShardId': '23', 'X-Shopify-Shop-Api-Call-Limit': '3/40', 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT': '3/40', 'X-Stats-UserId': '0', 'X-Stats-ApiClientId': '1807529', 'X-Stats-ApiPermissionId': '62125531', 'Strict-Transport-Security': 'max-age=7776000', 'Content-Security-Policy': "default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; script-src https://cdn.shopify.com https://checkout.shopifycs.com https://js-agent.newrelic.com https://bam.nr-data.net https://dme0ih8comzn4.cloudfront.net https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://maps.googleapis.com https://stats.g.doubleclick.net https://www.google-analytics.com https://visitors.shopify.com https://v.shopify.com https://widget.intercom.io https://js.intercomcdn.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=error_404&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Ferrors&source%5Bsection%5D=admin_api&source%5Buuid%5D=72550a71-d55b-4fb2-961f-f0447c1d04c6", 'X-Content-Type-Options': 'nosniff', 'X-Download-Options': 'noopen', 'X-Permitted-Cross-Domain-Policies': 'none', 'X-XSS-Protection': '1; mode=block; report=/xss-report?source%5Baction%5D=error_404&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Ferrors&source%5Bsection%5D=admin_api&source%5Buuid%5D=72550a71-d55b-4fb2-961f-f0447c1d04c6', 'X-Dc': 'ash,chi2', 'X-Request-ID': '72550a71-d55b-4fb2-961f-f0447c1d04c6'}, msg="Not Acceptable") 

すべてのアイデアは非常感謝!

+1

私はapiでピークを取った。そしてgithubのユニットテストを見た。あなたがidメソッドをdeleteメソッドに渡す必要があると思います(createがidをprice_ruleオブジェクトに追加する場合)か、代わりにdestroyメソッドを使用してください。 https://github.com/Shopify/shopify_python_api/blob/d8674a8cb10d2288568cdc38e0c39b9581ad5ee6/test/price_rules_test.py – Tim

+0

Thanks @Tim! idは動作しませんでしたが、破壊方法はありませんでした!私はそれを試して、誓ったことはありません:) – jordancooperman

答えて

0

@Timが彼の返答で述べたように、destroyメソッドは私のために働いて、すべての子インスタンスと親インスタンスを正常に削除しました。

関連する問題