Skip to content

Test Inventory

All test files in test/, grouped by category. Every test listed here requires AWS credentials at runtime unless explicitly noted as mocked.


Handler / End-to-End (3)

test/test_piping.py

Imports pipeThrough.calculatecost2Lambda, loads orderInput.yaml via Event.getInput, invokes the handler, and asserts statusCode == 200.

  • Fixture: test/testData/orderInput.yaml
  • AWS dependency: Yes (HTTP call through pipeThrough proxy)

test/test_conversions.py

Compares local calculatecost2Lambda output against the legacy HTTP API using orderInput1.yaml. Asserts equality of five financial fields:

Field Comparison
grandTotal local == remote
subTotal local == remote
cartDiscount local == remote
bogoDiscount local == remote
deliveryFee local == remote
  • Fixture: test/testData/orderInput1.yaml
  • AWS dependency: Yes (DynamoDB for prices, Lambda for coupons, HTTP API for comparison)

test/profiler/test_profiler.py

Same logic as test_conversions with cProfile instrumentation. Compares local vs remote output and produces a profiling report.

  • Fixture: test/testData/orderInput1.yaml
  • AWS dependency: Yes (same as conversions)

Order Model (3)

test/order/test_order_todict.py

Loads orderInput.yaml, constructs Order.fromDict, calls toDict(), and asserts computed fields:

Assertion Expected
deliveryFee 320
Schedule fee 115
  • Fixture: test/testData/orderInput.yaml
  • AWS dependency: Yes (DynamoDB for product prices)

test/order/test_order_no_shipping.py

Loads noShipping.yaml (order with no shipping object). Asserts:

Assertion Expected
deliveryFee 0
scheduleList empty
  • Fixture: test/testData/noShipping.yaml
  • AWS dependency: Yes (DynamoDB for product prices)

test/order/test_realorder.py

Loads realOrderInput.yaml (full production order snapshot). Asserts:

Assertion Expected
grandTotal 610
Shipping fee 0
  • Fixture: test/testData/realOrderInput.yaml
  • AWS dependency: Yes (DynamoDB for product prices)

Shipping (5)

test/shipping/test_shipping_price.py

Tests ShippingCalculator for three scenarios:

Scenario Expected price
Bangkok 90
Nationwide 130
Branch error 90
  • AWS dependency: Yes (HTTP call for Bangkok polygon, Lambda for nationwide)

test/shipping/test_shippingSchema.py

Parametrized test of CalculatedShipping model:

Parameter Expected
Express fee 50
Total fee 180
Shipping type DELIVERY
Postcode 10110
Bangkok price 90
  • AWS dependency: Yes (HTTP call for polygon, Lambda for nationwide)

test/shipping/test_order_shipping.py

Near-duplicate of test_shippingSchema.py. Tests the same shipping schema assertions through a slightly different code path.

  • AWS dependency: Yes (HTTP call for polygon, Lambda for nationwide)

test/shipping/test_nationwide.py

Tests NationwideCalculator directly:

Assertion Expected
Cost 115
Mode DRY
  • AWS dependency: Yes (Lambda invocation for nationwide rate lookup)

test/shipping/test_getbranch.py

Tests RegularPriceCalculator branch resolution:

Assertion Expected
Branch list length >= 26
Bangkok price 90
  • AWS dependency: Yes (HTTP call for branch polygon data)

Coupon (1)

test/coupon/test_coupon.py

Tests CouponCalculator using coupon.yaml fixture with a "testCoupon" override injected into the coupon code list.

Assertion Expected
discount 100
  • Fixture: test/testData/coupon.yaml
  • AWS dependency: Yes (Lambda invocation of coupon3-checker-dev)

Voucher (1)

test/voucher/test_getVoucher.py

Tests getVoucher across four voucher states:

State Expected behaviour
Active, unused Valid voucher returned
Inactive Rejected
Used Rejected
Unused Valid voucher returned
  • AWS dependency: Yes (Lambda invocation of get-voucher)

Product (3)

test/product/test_product.py

Tests Product field initialization and computed properties. Uses mocker.patch to mock price lookups, giving controlled values for price, originalPrice, weight, and isControlledProduct.

  • AWS dependency: Partially mocked (mocker.patch on price service)

test/product/test_productWeight.py

Tests weight calculation logic:

Scenario Expected behaviour
Normal product Correct weight * quantity
Invalid quantity Handled gracefully
Missing product Default weight applied
  • AWS dependency: Yes (DynamoDB for product weight data)

test/product/test_getProduct.py

Tests DynamoProduct query layer:

Test Description
Direct query DynamoProduct table query
GSI query Global secondary index lookup
getProduct High-level product fetch
  • AWS dependency: Yes (DynamoDB direct table access)

Pricing (2)

test/pricing/testGetPrice.py

Tests getPrice and getOriginalPrice for a known product:

Call Input Expected
getPrice cprcode=9, branch=1000 699.0
getOriginalPrice cprcode=9, branch=1000 699.0
  • AWS dependency: Yes (DynamoDB price table)

test/pricing/test_pynamodb_seperately.py

Raw PynamoDB query against the price table. Verifies the ORM layer works independently of the application code.

  • AWS dependency: Yes (DynamoDB direct access via PynamoDB)

Not Real Tests (2)

test/test_imports.py

Contains only import statements. No test functions defined. Useful for verifying that module imports succeed but produces no pytest output.

test/test_calculatecost.py

Contains only a __main__ block. Not a pytest-compatible module. Cannot be collected by pytest.


Utility

test/clear_cache.py

Clears the diskcache directory. Not a test file -- a maintenance utility.


YAML Fixtures

All fixture files live in test/testData/.

File Top-level keys Used by
orderInput.yaml branchId, couponCodeList, productList, shipping test_piping, test_order_todict
orderInput1.yaml branchId, couponCodeList (nil), productList, shipping test_conversions, test_profiler
noShipping.yaml branchId, couponCodeList, productList test_order_no_shipping
coupon.yaml branchId, couponCodeList, productList, shipping test_coupon
freeship.yaml branchId, couponCodeList, ownerId, productList, shipping, voucherId Commented tests only
branch3000.yaml branchId, couponCodeList, noPlasticBag, productList, ... Commented tests only
realOrderInput.yaml 35+ keys (full production order) test_realorder
realOrderInput2.yaml 14+ keys (production order, branch 1021) test_realorder2
freeship/shipdisc1.yaml Full production order Commented tests only
freeship/shipdisc2.yaml Same structure, different values Commented tests only
orderOutput.yaml Response snapshot (orphan) None

Commented-Out Tests

The following test functions exist in source but are commented out:

Function File Purpose
test_branch3000 test_shipping Branch 3000 shipping edge case
test_branch4000 test_shipping Branch 4000 shipping edge case
test_freeship_realdata test_shipping Shipping discount with real data
test_freeship test_coupon Free shipping coupon
test_freeship2 test_coupon Free shipping coupon variant

These reference fixtures branch3000.yaml, freeship.yaml, freeship/shipdisc1.yaml, and freeship/shipdisc2.yaml.


Summary

Category Files Need AWS Fully mocked
Handler / E2E 3 3 0
Order model 3 3 0
Shipping 5 5 0
Coupon 1 1 0
Voucher 1 1 0
Product 3 2 1 (partial)
Pricing 2 2 0
Not tests 2 -- --
Utility 1 -- --
Total 21 17 1