def test_country_choices(shipping_method): any_country_shipping_method = ShippingMethodCountry.objects.filter( country_code=ANY_COUNTRY) assert any_country_shipping_method.exists() assert country_choices() == COUNTRY_CODE_CHOICES any_country_shipping_method.delete() ShippingMethodCountry.objects.create(country_code='PL', price=10, shipping_method=shipping_method) assert country_choices() == [('PL', get_country_name_by_code('PL'))]
def test_payments_query( payment_txn_captured, permission_manage_orders, staff_api_client ): query = """ { payments(first: 20) { edges { node { id gateway capturedAmount { amount currency } total { amount currency } actions chargeStatus billingAddress { country { code country } firstName lastName cityArea countryArea city companyName streetAddress1 streetAddress2 postalCode } transactions { amount { currency amount } } creditCard { expMonth expYear brand firstDigits lastDigits } } } } } """ response = staff_api_client.post_graphql( query, permissions=[permission_manage_orders] ) content = get_graphql_content(response) data = content["data"]["payments"]["edges"][0]["node"] pay = payment_txn_captured assert data["gateway"] == pay.gateway amount = str(data["capturedAmount"]["amount"]) assert Decimal(amount) == pay.captured_amount assert data["capturedAmount"]["currency"] == pay.currency total = str(data["total"]["amount"]) assert Decimal(total) == pay.total assert data["total"]["currency"] == pay.currency assert data["chargeStatus"] == PaymentChargeStatusEnum.FULLY_CHARGED.name assert data["billingAddress"] == { "firstName": pay.billing_first_name, "lastName": pay.billing_last_name, "city": pay.billing_city, "cityArea": pay.billing_city_area, "countryArea": pay.billing_country_area, "companyName": pay.billing_company_name, "streetAddress1": pay.billing_address_1, "streetAddress2": pay.billing_address_2, "postalCode": pay.billing_postal_code, "country": { "code": pay.billing_country_code, "country": get_country_name_by_code(pay.billing_country_code), }, } assert data["actions"] == [OrderAction.REFUND.name] txn = pay.transactions.get() assert data["transactions"] == [ {"amount": {"currency": pay.currency, "amount": float(str(txn.amount))}} ] assert data["creditCard"] == { "expMonth": pay.cc_exp_month, "expYear": pay.cc_exp_year, "brand": pay.cc_brand, "firstDigits": pay.cc_first_digits, "lastDigits": pay.cc_last_digits, }
def test_payments_query(payment_txn_captured, permission_manage_orders, staff_api_client): query = """ { payments(first: 20) { edges { node { id gateway capturedAmount { amount currency } total { amount currency } actions chargeStatus billingAddress { country { code country } firstName lastName cityArea countryArea city companyName streetAddress1 streetAddress2 postalCode } transactions { amount { currency amount } } creditCard { expMonth expYear brand firstDigits lastDigits } } } } } """ response = staff_api_client.post_graphql( query, permissions=[permission_manage_orders]) content = get_graphql_content(response) data = content['data']['payments']['edges'][0]['node'] pay = payment_txn_captured assert data['gateway'] == pay.gateway assert data['capturedAmount'] == { 'amount': pay.captured_amount, 'currency': pay.currency } assert data['total'] == {'amount': pay.total, 'currency': pay.currency} assert data['chargeStatus'] == PaymentChargeStatusEnum.CHARGED.name assert data['billingAddress'] == { 'firstName': pay.billing_first_name, 'lastName': pay.billing_last_name, 'city': pay.billing_city, 'cityArea': pay.billing_city_area, 'countryArea': pay.billing_country_area, 'companyName': pay.billing_company_name, 'streetAddress1': pay.billing_address_1, 'streetAddress2': pay.billing_address_2, 'postalCode': pay.billing_postal_code, 'country': { 'code': pay.billing_country_code, 'country': get_country_name_by_code(pay.billing_country_code) } } assert data['actions'] == [OrderAction.REFUND.name] txn = pay.transactions.get() assert data['transactions'] == [{ 'amount': { 'currency': pay.currency, 'amount': float(str(txn.amount)) } }] assert data['creditCard'] == { 'expMonth': pay.cc_exp_month, 'expYear': pay.cc_exp_year, 'brand': pay.cc_brand, 'firstDigits': pay.cc_first_digits, 'lastDigits': pay.cc_last_digits }
def test_get_country_name_by_code(): country_name = get_country_name_by_code('PL') assert country_name == 'Poland'
def test_get_country_name_by_code(): country_name = get_country_name_by_code('PL') assert country_name == 'Poland'
def test_get_country_name_by_code(): country_name = get_country_name_by_code("PL") assert country_name == "Poland"
def test_get_country_name_by_code(): country_name = get_country_name_by_code("PL") assert country_name == "Poland"
def test_payments_query( payment_txn_captured, permission_manage_orders, staff_api_client): query = """ { payments(first: 20) { edges { node { id gateway capturedAmount { amount currency } total { amount currency } actions chargeStatus billingAddress { country { code country } firstName lastName cityArea countryArea city companyName streetAddress1 streetAddress2 postalCode } transactions { amount { currency amount } } creditCard { expMonth expYear brand firstDigits lastDigits } } } } } """ response = staff_api_client.post_graphql( query, permissions=[permission_manage_orders]) content = get_graphql_content(response) data = content['data']['payments']['edges'][0]['node'] pay = payment_txn_captured assert data['gateway'] == pay.gateway assert data['capturedAmount'] == { 'amount': pay.captured_amount, 'currency': pay.currency} assert data['total'] == {'amount': pay.total, 'currency': pay.currency} assert data['chargeStatus'] == PaymentChargeStatusEnum.FULLY_CHARGED.name assert data['billingAddress'] == { 'firstName': pay.billing_first_name, 'lastName': pay.billing_last_name, 'city': pay.billing_city, 'cityArea': pay.billing_city_area, 'countryArea': pay.billing_country_area, 'companyName': pay.billing_company_name, 'streetAddress1': pay.billing_address_1, 'streetAddress2': pay.billing_address_2, 'postalCode': pay.billing_postal_code, 'country': { 'code': pay.billing_country_code, 'country': get_country_name_by_code(pay.billing_country_code) } } assert data['actions'] == [OrderAction.REFUND.name] txn = pay.transactions.get() assert data['transactions'] == [{ 'amount': { 'currency': pay.currency, 'amount': float(str(txn.amount))}}] assert data['creditCard'] == { 'expMonth': pay.cc_exp_month, 'expYear': pay.cc_exp_year, 'brand': pay.cc_brand, 'firstDigits': pay.cc_first_digits, 'lastDigits': pay.cc_last_digits}
def test_payments_query( payment_txn_captured, permission_manage_orders, staff_api_client ): query = """ { payments(first: 20) { edges { node { id gateway capturedAmount { amount currency } total { amount currency } actions chargeStatus billingAddress { country { code country } firstName lastName cityArea countryArea city companyName streetAddress1 streetAddress2 postalCode } transactions { amount { currency amount } } creditCard { expMonth expYear brand firstDigits lastDigits } } } } } """ response = staff_api_client.post_graphql( query, permissions=[permission_manage_orders] ) content = get_graphql_content(response) data = content["data"]["payments"]["edges"][0]["node"] pay = payment_txn_captured assert data["gateway"] == pay.gateway assert data["capturedAmount"] == { "amount": pay.captured_amount, "currency": pay.currency, } assert data["total"] == {"amount": pay.total, "currency": pay.currency} assert data["chargeStatus"] == PaymentChargeStatusEnum.FULLY_CHARGED.name assert data["billingAddress"] == { "firstName": pay.billing_first_name, "lastName": pay.billing_last_name, "city": pay.billing_city, "cityArea": pay.billing_city_area, "countryArea": pay.billing_country_area, "companyName": pay.billing_company_name, "streetAddress1": pay.billing_address_1, "streetAddress2": pay.billing_address_2, "postalCode": pay.billing_postal_code, "country": { "code": pay.billing_country_code, "country": get_country_name_by_code(pay.billing_country_code), }, } assert data["actions"] == [OrderAction.REFUND.name] txn = pay.transactions.get() assert data["transactions"] == [ {"amount": {"currency": pay.currency, "amount": float(str(txn.amount))}} ] assert data["creditCard"] == { "expMonth": pay.cc_exp_month, "expYear": pay.cc_exp_year, "brand": pay.cc_brand, "firstDigits": pay.cc_first_digits, "lastDigits": pay.cc_last_digits, }