зеркало из https://github.com/mozilla/subhub.git
Resolve test coverage reporting
This commit is contained in:
Родитель
fb20ea620d
Коммит
4d9f512e27
|
@ -0,0 +1,34 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
[run]
|
||||
branch = True
|
||||
parallel = True
|
||||
# Store coverage at the location, reports/.coverage
|
||||
data_file = reports/.coverage
|
||||
# Collect coverage from the following sources
|
||||
source = src/shared, src/sub, src/hub
|
||||
|
||||
[report]
|
||||
# Ignore source errors that can't be found
|
||||
ignore_errors = True
|
||||
exclude_lines =
|
||||
pragma: no cover
|
||||
def __repr__
|
||||
if .debug:
|
||||
raise NotImplementedError
|
||||
if __name__ == .__main__.:
|
||||
omit =
|
||||
*/tests/*
|
||||
*/.venv/*
|
||||
|
||||
[html]
|
||||
# HTML report title
|
||||
title = Subhub Coverage
|
||||
# Write the HTML reports to the reports/html directory
|
||||
directory = reports/html
|
||||
|
||||
[xml]
|
||||
# Write the XML report to reports/coverage.xml
|
||||
output = reports/coverage.xml
|
|
@ -12,6 +12,7 @@ repos:
|
|||
- id: check-json
|
||||
- id: detect-private-key
|
||||
- id: end-of-file-fixer
|
||||
- id: requirements-txt-fixer
|
||||
- id: pretty-format-json
|
||||
args: [
|
||||
'--autofix',
|
||||
|
|
17
.travis.yml
17
.travis.yml
|
@ -30,18 +30,5 @@ jobs:
|
|||
include:
|
||||
- stage: Unit Tests
|
||||
script:
|
||||
# The below 2 TravisCI statements are a workaround for an issue in TravisCI which
|
||||
# is best described as "Large writes to stdout sometimes fail with "Resource temporarily unavailable".
|
||||
# More information about this can be found at:
|
||||
# https://github.com/travis-ci/travis-ci/issues/4704#issuecomment-348435959
|
||||
#
|
||||
# Turn off O_NONBLOCK:
|
||||
- python3.7 -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL);
|
||||
fcntl.fcntl(sys.stdout, fcntl.F_SETFL, flags&~os.O_NONBLOCK);'
|
||||
# Check whether O_NONBLOCK is set (should print "0"):
|
||||
- python3.7 -c 'import os,sys,fcntl; flags = fcntl.fcntl(sys.stdout, fcntl.F_GETFL);
|
||||
print(flags&os.O_NONBLOCK);'
|
||||
- doit test
|
||||
- cd /home/travis/build/mozilla/subhub/src/sub && bash <(curl -s https://codecov.io/bash) -cF python
|
||||
- cd /home/travis/build/mozilla/subhub/src/hub && bash <(curl -s https://codecov.io/bash) -cF python
|
||||
- cd /home/travis/build/mozilla/subhub/src/shared && bash <(curl -s https://codecov.io/bash) -cF python
|
||||
- tox
|
||||
- cd /home/travis/build/mozilla/subhub/reports && bash <(curl -s https://codecov.io/bash) -cF python
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
black==19.3b0
|
||||
codecov==2.0.15
|
||||
# requirements for getting doit commands to run
|
||||
# this is for automation of dev tasks, not required to run
|
||||
doit==0.31.1
|
||||
python-decouple==3.1
|
||||
flake8==3.7.8
|
||||
tox==3.13.2
|
||||
black==19.3b0
|
||||
ruamel.yaml==0.15.97
|
||||
locustio==0.11.0
|
||||
pyparsing==2.4.0
|
||||
codecov==2.0.15
|
||||
structlog==19.1.0
|
||||
pre-commit==1.20.0
|
||||
pyparsing==2.4.0
|
||||
python-decouple==3.1
|
||||
ruamel.yaml==0.15.97
|
||||
structlog==19.1.0
|
||||
tox==3.14.0
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
# coverage data file
|
||||
.coverage
|
||||
|
||||
# HTML reports
|
||||
html/*
|
||||
|
||||
# XML coverage report
|
||||
coverage.xml
|
|
@ -0,0 +1,7 @@
|
|||
# Reports
|
||||
|
||||
This directory contains the coverage reporting data from test runs.
|
||||
|
||||
## Author(s)
|
||||
|
||||
Stewart Henderson
|
|
@ -1,13 +0,0 @@
|
|||
[run]
|
||||
branch = True
|
||||
[report]
|
||||
exclude_lines =
|
||||
pragma: no cover
|
||||
def __repr__
|
||||
if .debug:
|
||||
raise NotImplementedError
|
||||
if __name__ == .__main__.:
|
||||
ignore_errors = True
|
||||
omit =
|
||||
*/tests/*
|
||||
*/.venv/*
|
|
@ -20,7 +20,7 @@ class RoutesPipeline:
|
|||
elif r == StaticRoutes.FIREFOX_ROUTE:
|
||||
FirefoxRoute(self.data).route()
|
||||
else:
|
||||
raise UnsupportedStaticRouteError(r, StaticRoutes)
|
||||
raise UnsupportedStaticRouteError(r, StaticRoutes) # type: ignore
|
||||
|
||||
|
||||
class AllRoutes:
|
||||
|
@ -34,4 +34,4 @@ class AllRoutes:
|
|||
elif m["type"] == "salesforce_route":
|
||||
SalesforceRoute(m["data"]).route()
|
||||
else:
|
||||
raise UnsupportedDataError(m, m["type"], StaticRoutes)
|
||||
raise UnsupportedDataError(m, m["type"], StaticRoutes) # type: ignore
|
||||
|
|
|
@ -24,11 +24,11 @@ from hub.shared.db import SubHubDeletedAccountModel
|
|||
|
||||
class StripeCustomerCreatedTest(TestCase):
|
||||
def setUp(self) -> None:
|
||||
with open("tests/unit/fixtures/stripe_cust_created_event.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_cust_created_event.json") as fh:
|
||||
self.customer_created_event = json.loads(fh.read())
|
||||
|
||||
with open(
|
||||
"tests/unit/fixtures/stripe_cust_created_event_missing_name.json"
|
||||
"src/hub/tests/unit/fixtures/stripe_cust_created_event_missing_name.json"
|
||||
) as fh:
|
||||
self.customer_created_event_missing_name = json.loads(fh.read())
|
||||
|
||||
|
@ -102,11 +102,13 @@ class StripeCustomerDeletedTest(TestCase):
|
|||
customer_status="deleted",
|
||||
)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_customer_deleted_event.json") as fh:
|
||||
with open(
|
||||
"src/hub/tests/unit/fixtures/stripe_customer_deleted_event.json"
|
||||
) as fh:
|
||||
self.customer_deleted_event = json.loads(fh.read())
|
||||
|
||||
with open(
|
||||
"tests/unit/fixtures/stripe_customer_deleted_event_no_metadata.json"
|
||||
"src/hub/tests/unit/fixtures/stripe_customer_deleted_event_no_metadata.json"
|
||||
) as fh:
|
||||
self.customer_deleted_event_no_meta = json.loads(fh.read())
|
||||
|
||||
|
@ -214,24 +216,26 @@ class StripeCustomerDeletedTest(TestCase):
|
|||
|
||||
class StripeCustomerSourceExpiringTest(TestCase):
|
||||
def setUp(self) -> None:
|
||||
with open("tests/unit/fixtures/stripe_cust_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_cust_test1.json") as fh:
|
||||
cust_test1 = json.loads(fh.read())
|
||||
self.customer = convert_to_stripe_object(cust_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_sub_test1.json") as fh:
|
||||
self.subscription = json.loads(fh.read())
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_test2.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_sub_test2.json") as fh:
|
||||
self.subscription2 = json.loads(fh.read())
|
||||
|
||||
with open("tests/unit/fixtures/stripe_plan_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_plan_test1.json") as fh:
|
||||
self.plan = json.loads(fh.read())
|
||||
|
||||
with open("tests/unit/fixtures/stripe_prod_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_prod_test1.json") as fh:
|
||||
prod_test1 = json.loads(fh.read())
|
||||
self.product = convert_to_stripe_object(prod_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_source_expiring_event.json") as fh:
|
||||
with open(
|
||||
"src/hub/tests/unit/fixtures/stripe_source_expiring_event.json"
|
||||
) as fh:
|
||||
self.source_expiring_event = json.loads(fh.read())
|
||||
|
||||
customer_patcher = patch("stripe.Customer.retrieve")
|
||||
|
@ -316,31 +320,31 @@ class StripeCustomerSourceExpiringTest(TestCase):
|
|||
|
||||
class StripeCustomerSubscriptionCreatedTest(TestCase):
|
||||
def setUp(self) -> None:
|
||||
with open("tests/unit/fixtures/stripe_cust_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_cust_test1.json") as fh:
|
||||
cust_test1 = json.loads(fh.read())
|
||||
self.customer = convert_to_stripe_object(cust_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_no_metadata.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_cust_no_metadata.json") as fh:
|
||||
cust_no_metadata = json.loads(fh.read())
|
||||
self.customer_missing_user = convert_to_stripe_object(cust_no_metadata)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_test1_deleted.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_cust_test1_deleted.json") as fh:
|
||||
cust_test1_deleted = json.loads(fh.read())
|
||||
self.deleted_customer = convert_to_stripe_object(cust_test1_deleted)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_prod_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_prod_test1.json") as fh:
|
||||
prod_test1 = json.loads(fh.read())
|
||||
self.product = convert_to_stripe_object(prod_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_in_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_in_test1.json") as fh:
|
||||
invoice_test1 = json.loads(fh.read())
|
||||
self.invoice = convert_to_stripe_object(invoice_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_ch_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_ch_test1.json") as fh:
|
||||
charge_test1 = json.loads(fh.read())
|
||||
self.charge = convert_to_stripe_object(charge_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_created_event.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_sub_created_event.json") as fh:
|
||||
self.subscription_created_event = json.loads(fh.read())
|
||||
|
||||
customer_patcher = patch("stripe.Customer.retrieve")
|
||||
|
@ -498,19 +502,19 @@ class StripeCustomerSubscriptionCreatedTest(TestCase):
|
|||
|
||||
class StripeCustomerSubscriptionDeletedTest(TestCase):
|
||||
def setUp(self) -> None:
|
||||
with open("tests/unit/fixtures/stripe_cust_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_cust_test1.json") as fh:
|
||||
cust_test1 = json.loads(fh.read())
|
||||
self.customer = convert_to_stripe_object(cust_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_no_metadata.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_cust_no_metadata.json") as fh:
|
||||
cust_no_metadata = json.loads(fh.read())
|
||||
self.customer_missing_user = convert_to_stripe_object(cust_no_metadata)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_test1_deleted.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_cust_test1_deleted.json") as fh:
|
||||
cust_test1_deleted = json.loads(fh.read())
|
||||
self.deleted_customer = convert_to_stripe_object(cust_test1_deleted)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_deleted_event.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_sub_deleted_event.json") as fh:
|
||||
self.subscription_deleted_event = json.loads(fh.read())
|
||||
|
||||
customer_patcher = patch("stripe.Customer.retrieve")
|
||||
|
@ -596,48 +600,56 @@ class StripeCustomerSubscriptionDeletedTest(TestCase):
|
|||
|
||||
class StripeCustomerSubscriptionUpdatedTest(TestCase):
|
||||
def setUp(self) -> None:
|
||||
with open("tests/unit/fixtures/stripe_cust_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_cust_test1.json") as fh:
|
||||
cust_test1 = json.loads(fh.read())
|
||||
self.customer = convert_to_stripe_object(cust_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_no_metadata.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_cust_no_metadata.json") as fh:
|
||||
cust_no_metadata = json.loads(fh.read())
|
||||
self.customer_missing_user = convert_to_stripe_object(cust_no_metadata)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_test1_deleted.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_cust_test1_deleted.json") as fh:
|
||||
cust_test1_deleted = json.loads(fh.read())
|
||||
self.deleted_customer = convert_to_stripe_object(cust_test1_deleted)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_prod_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_prod_test1.json") as fh:
|
||||
prod_test1 = json.loads(fh.read())
|
||||
self.product = convert_to_stripe_object(prod_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_in_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_in_test1.json") as fh:
|
||||
invoice_test1 = json.loads(fh.read())
|
||||
self.invoice = convert_to_stripe_object(invoice_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_in_test2.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_in_test2.json") as fh:
|
||||
invoice_test2 = json.loads(fh.read())
|
||||
self.incomplete_invoice = convert_to_stripe_object(invoice_test2)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_ch_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_ch_test1.json") as fh:
|
||||
charge_test1 = json.loads(fh.read())
|
||||
self.charge = convert_to_stripe_object(charge_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_ch_test2.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_ch_test2.json") as fh:
|
||||
charge_test2 = json.loads(fh.read())
|
||||
self.incomplete_charge = convert_to_stripe_object(charge_test2)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_updated_event_cancel.json") as fh:
|
||||
with open(
|
||||
"src/hub/tests/unit/fixtures/stripe_sub_updated_event_cancel.json"
|
||||
) as fh:
|
||||
self.subscription_cancelled_event = json.loads(fh.read())
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_updated_event_charge.json") as fh:
|
||||
with open(
|
||||
"src/hub/tests/unit/fixtures/stripe_sub_updated_event_charge.json"
|
||||
) as fh:
|
||||
self.subscription_charge_event = json.loads(fh.read())
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_updated_event_reactivate.json") as fh:
|
||||
with open(
|
||||
"src/hub/tests/unit/fixtures/stripe_sub_updated_event_reactivate.json"
|
||||
) as fh:
|
||||
self.subscription_reactivate_event = json.loads(fh.read())
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_updated_event_no_trigger.json") as fh:
|
||||
with open(
|
||||
"src/hub/tests/unit/fixtures/stripe_sub_updated_event_no_trigger.json"
|
||||
) as fh:
|
||||
self.subscription_updated_event_no_match = json.loads(fh.read())
|
||||
|
||||
customer_patcher = patch("stripe.Customer.retrieve")
|
||||
|
|
|
@ -14,15 +14,17 @@ from hub.vendor.invoices import StripeInvoicePaymentFailed
|
|||
|
||||
class StripeInvoicePaymentFailedTest(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
with open("tests/unit/fixtures/stripe_prod_test1.json") as fh:
|
||||
with open("src/hub/tests/unit/fixtures/stripe_prod_test1.json") as fh:
|
||||
prod_test1 = json.loads(fh.read())
|
||||
self.product = convert_to_stripe_object(prod_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_in_payment_failed_event.json") as fh:
|
||||
with open(
|
||||
"src/hub/tests/unit/fixtures/stripe_in_payment_failed_event.json"
|
||||
) as fh:
|
||||
self.payment_failed_event = json.loads(fh.read())
|
||||
|
||||
with open(
|
||||
"tests/unit/fixtures/stripe_in_payment_failed_event_sub_create.json"
|
||||
"src/hub/tests/unit/fixtures/stripe_in_payment_failed_event_sub_create.json"
|
||||
) as fh:
|
||||
self.payment_failed_event_sub_create = json.loads(fh.read())
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class AbstractStripeHubEvent(ABC):
|
|||
RoutesPipeline(report_routes, message_to_route).run()
|
||||
|
||||
@staticmethod
|
||||
def send_to_all_routes(messages_to_routes):
|
||||
def send_to_all_routes(messages_to_routes) -> None:
|
||||
logger.info("send to all routes", messages_to_routes=messages_to_routes)
|
||||
AllRoutes(messages_to_routes).run()
|
||||
|
||||
|
@ -48,13 +48,13 @@ class AbstractStripeHubEvent(ABC):
|
|||
logger.info("Event not handled", payload=payload)
|
||||
|
||||
@abstractmethod
|
||||
def run(self) -> None:
|
||||
def run(self) -> bool:
|
||||
raise NotImplementedError
|
||||
|
||||
def create_data(self, **kwargs) -> Dict[str, str]:
|
||||
return dict(event_id=self.payload.id, event_type=self.payload.type, **kwargs)
|
||||
|
||||
def customer_event_to_all_routes(self, data_projection, data):
|
||||
def customer_event_to_all_routes(self, data_projection, data) -> None:
|
||||
subsets = []
|
||||
for route in data_projection:
|
||||
try:
|
||||
|
|
|
@ -200,12 +200,12 @@ class StripeCustomerSubscriptionCreated(AbstractStripeHubEvent):
|
|||
customer_id = self.payload.data.object.customer
|
||||
user_id = self.get_user_id(customer_id)
|
||||
|
||||
data = self.create_payload(user_id)
|
||||
data: Dict[str, Any] = self.create_payload(user_id)
|
||||
|
||||
# NOTE:
|
||||
# Firefox's route has a particular casing requirement
|
||||
# Salesforce's route doesn't care.
|
||||
data_projection_by_route = {
|
||||
data_projection_by_route: Dict[str, Any] = {
|
||||
StaticRoutes.FIREFOX_ROUTE: [
|
||||
"uid",
|
||||
"active",
|
||||
|
@ -259,11 +259,11 @@ class StripeCustomerSubscriptionCreated(AbstractStripeHubEvent):
|
|||
try:
|
||||
invoice_id = self.payload.data.object.latest_invoice
|
||||
latest_invoice = vendor.retrieve_stripe_invoice(invoice_id)
|
||||
invoice_number = latest_invoice.number # type: ignore
|
||||
charge_id = latest_invoice.charge # type: ignore
|
||||
invoice_number = latest_invoice.number
|
||||
charge_id = latest_invoice.charge
|
||||
latest_charge = vendor.retrieve_stripe_charge(charge_id)
|
||||
last4 = latest_charge.payment_method_details.card.last4 # type: ignore
|
||||
brand = latest_charge.payment_method_details.card.brand # type: ignore
|
||||
last4 = latest_charge.payment_method_details.card.last4
|
||||
brand = latest_charge.payment_method_details.card.brand
|
||||
|
||||
logger.info("latest invoice", latest_invoice=latest_invoice)
|
||||
logger.info("latest charge", latest_charge=latest_charge)
|
||||
|
@ -511,11 +511,11 @@ class StripeCustomerSubscriptionUpdated(AbstractStripeHubEvent):
|
|||
"""
|
||||
invoice_id = self.payload.data.object.latest_invoice
|
||||
latest_invoice = vendor.retrieve_stripe_invoice(invoice_id)
|
||||
invoice_number = latest_invoice.number # type: ignore
|
||||
charge_id = latest_invoice.charge # type: ignore
|
||||
invoice_number = latest_invoice.number
|
||||
charge_id = latest_invoice.charge
|
||||
latest_charge = vendor.retrieve_stripe_charge(charge_id)
|
||||
last4 = latest_charge.payment_method_details.card.last4 # type: ignore
|
||||
brand = latest_charge.payment_method_details.card.brand # type: ignore
|
||||
last4 = latest_charge.payment_method_details.card.last4
|
||||
brand = latest_charge.payment_method_details.card.brand
|
||||
|
||||
logger.info("latest invoice", latest_invoice=latest_invoice)
|
||||
logger.info("latest charge", latest_charge=latest_charge)
|
||||
|
@ -549,8 +549,8 @@ class StripeCustomerSubscriptionUpdated(AbstractStripeHubEvent):
|
|||
invoice_id = self.payload.data.object.latest_invoice
|
||||
latest_invoice = vendor.retrieve_stripe_invoice(invoice_id)
|
||||
latest_charge = vendor.retrieve_stripe_charge(latest_invoice.charge)
|
||||
last4 = latest_charge.payment_method_details.card.last4 # type: ignore
|
||||
brand = latest_charge.payment_method_details.card.brand # type: ignore
|
||||
last4 = latest_charge.payment_method_details.card.last4
|
||||
brand = latest_charge.payment_method_details.card.brand
|
||||
|
||||
return dict(
|
||||
close_date=self.payload.created,
|
||||
|
|
|
@ -26,27 +26,29 @@ from sub.shared.exceptions import IntermittentError, ServerError
|
|||
class CustomerTest(TestCase):
|
||||
def setUp(self) -> None:
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_test1.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_cust_test1.json") as fh:
|
||||
cust_test1 = json.loads(fh.read())
|
||||
self.customer1 = convert_to_stripe_object(cust_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_test2.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_cust_test2.json") as fh:
|
||||
cust_test2 = json.loads(fh.read())
|
||||
self.customer2 = convert_to_stripe_object(cust_test2)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_test4_no_subs.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_cust_test4_no_subs.json") as fh:
|
||||
cust_test1_no_subs = json.loads(fh.read())
|
||||
self.customer_no_subs = convert_to_stripe_object(cust_test1_no_subs)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_test5_no_sources.json") as fh:
|
||||
with open(
|
||||
"src/sub/tests/unit/fixtures/stripe_cust_test5_no_sources.json"
|
||||
) as fh:
|
||||
cust_test1_no_sources = json.loads(fh.read())
|
||||
self.customer_no_sources = convert_to_stripe_object(cust_test1_no_sources)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_deleted_cust.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_deleted_cust.json") as fh:
|
||||
deleted_cust = json.loads(fh.read())
|
||||
self.deleted_customer = convert_to_stripe_object(deleted_cust)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_list.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_cust_list.json") as fh:
|
||||
cust_list = json.loads(fh.read())
|
||||
self.empty_customer_list = convert_to_stripe_object(cust_list)
|
||||
|
||||
|
@ -54,7 +56,7 @@ class CustomerTest(TestCase):
|
|||
cust_list["data"].append(cust_test1)
|
||||
self.customer_list = convert_to_stripe_object(cust_list)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_test1.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_sub_test1.json") as fh:
|
||||
sub_test1 = json.loads(fh.read())
|
||||
self.subscription1 = convert_to_stripe_object(sub_test1)
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ def test_delete_user_from_db(app, create_subscription_for_processing):
|
|||
"process_test", "sub_id", "origin", [{"id": "sub_123"}]
|
||||
)
|
||||
logger.info("deleted user from db", deleted_user=deleted_user)
|
||||
assert isinstance(deleted_user, MagicMock)
|
||||
assert isinstance(deleted_user, MagicMock) # type: ignore
|
||||
|
||||
|
||||
def test_delete_user_from_db2(app, create_subscription_for_processing, monkeypatch):
|
||||
|
@ -609,25 +609,25 @@ def test_format_nickname_non_standard_interval():
|
|||
@patch("stripe.Product.retrieve")
|
||||
def test_create_update_data(mock_product, mock_invoice, mock_charge, mock_customer):
|
||||
|
||||
fh = open("tests/unit/fixtures/stripe_prod_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_prod_test1.json")
|
||||
prod_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
fh = open("tests/unit/fixtures/stripe_prod_test2.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_prod_test2.json")
|
||||
prod_test2 = json.loads(fh.read())
|
||||
fh.close()
|
||||
mock_product.side_effect = [prod_test1, prod_test2]
|
||||
|
||||
fh = open("tests/unit/fixtures/stripe_in_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_in_test1.json")
|
||||
invoice_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
mock_invoice.return_value = invoice_test1
|
||||
|
||||
fh = open("tests/unit/fixtures/stripe_ch_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_ch_test1.json")
|
||||
charge_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
mock_charge.return_value = charge_test1
|
||||
|
||||
fh = open("tests/unit/fixtures/stripe_cust_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_cust_test1.json")
|
||||
cust_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
mock_customer.return_value = cust_test1
|
||||
|
@ -668,23 +668,23 @@ def test_create_update_data(mock_product, mock_invoice, mock_charge, mock_custom
|
|||
|
||||
|
||||
def get_test_subscriptions():
|
||||
fh = open("tests/unit/fixtures/stripe_cust_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_cust_test1.json")
|
||||
cust_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
|
||||
fh = open("tests/unit/fixtures/stripe_sub_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_sub_test1.json")
|
||||
sub_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
|
||||
fh = open("tests/unit/fixtures/stripe_sub_test2.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_sub_test2.json")
|
||||
sub_test2 = json.loads(fh.read())
|
||||
fh.close()
|
||||
|
||||
fh = open("tests/unit/fixtures/stripe_plan_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_plan_test1.json")
|
||||
plan_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
|
||||
fh = open("tests/unit/fixtures/stripe_plan_test3.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_plan_test3.json")
|
||||
plan_test3 = json.loads(fh.read())
|
||||
fh.close()
|
||||
|
||||
|
|
|
@ -32,85 +32,87 @@ logger = get_logger()
|
|||
|
||||
class TestPayments(TestCase):
|
||||
def setUp(self) -> None:
|
||||
with open("tests/unit/fixtures/stripe_cust_test1.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_cust_test1.json") as fh:
|
||||
cust_test1 = json.loads(fh.read())
|
||||
self.valid_customer = convert_to_stripe_object(cust_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_test2.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_cust_test2.json") as fh:
|
||||
cust_test2 = json.loads(fh.read())
|
||||
self.valid_customer_no_metadata = convert_to_stripe_object(cust_test2)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_test3.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_cust_test3.json") as fh:
|
||||
cust_test3 = json.loads(fh.read())
|
||||
self.valid_customer3 = convert_to_stripe_object(cust_test3)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_deleted_cust.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_deleted_cust.json") as fh:
|
||||
deleted_cust = json.loads(fh.read())
|
||||
self.deleted_cust = convert_to_stripe_object(deleted_cust)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_prod_test1.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_prod_test1.json") as fh:
|
||||
prod_test1 = json.loads(fh.read())
|
||||
self.product = convert_to_stripe_object(prod_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_plan_test1.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_plan_test1.json") as fh:
|
||||
plan_test1 = json.loads(fh.read())
|
||||
self.plan = convert_to_stripe_object(plan_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_in_test1.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_in_test1.json") as fh:
|
||||
invoice_test1 = json.loads(fh.read())
|
||||
self.invoice = convert_to_stripe_object(invoice_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_ch_test1.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_ch_test1.json") as fh:
|
||||
charge_test1 = json.loads(fh.read())
|
||||
self.charge = convert_to_stripe_object(charge_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_test1.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_sub_test1.json") as fh:
|
||||
subscription_test1 = json.loads(fh.read())
|
||||
self.subscription_test1 = convert_to_stripe_object(subscription_test1)
|
||||
|
||||
subscription_test1["plan"] = plan_test1
|
||||
self.subscription_with_plan = convert_to_stripe_object(subscription_test1)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_cust_test4_no_subs.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_cust_test4_no_subs.json") as fh:
|
||||
cust_test4 = json.loads(fh.read())
|
||||
cust_test4["subscriptions"]["data"].append(subscription_test1)
|
||||
self.customer4 = convert_to_stripe_object(cust_test4)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_test3.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_sub_test3.json") as fh:
|
||||
subscription_test3 = json.loads(fh.read())
|
||||
self.subscription_test3 = convert_to_stripe_object(subscription_test3)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_cancelled.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_sub_cancelled.json") as fh:
|
||||
subscription_test_cancelled = json.loads(fh.read())
|
||||
self.subscription_test_cancelled = convert_to_stripe_object(
|
||||
subscription_test_cancelled
|
||||
)
|
||||
|
||||
with open("tests/unit/fixtures/stripe_sub_test_none.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/stripe_sub_test_none.json") as fh:
|
||||
subscription_none = json.loads(fh.read())
|
||||
self.subscription_none = subscription_none
|
||||
|
||||
with open("tests/unit/fixtures/sns_message.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/sns_message.json") as fh:
|
||||
sns_message_payload = json.loads(fh.read())
|
||||
self.sns_message_payload = sns_message_payload
|
||||
|
||||
with open("tests/unit/fixtures/stripe_subscriptions_no_data.json") as fh:
|
||||
with open(
|
||||
"src/sub/tests/unit/fixtures/stripe_subscriptions_no_data.json"
|
||||
) as fh:
|
||||
subscription_no_data = json.loads(fh.read())
|
||||
self.subscription_list = subscription_no_data
|
||||
|
||||
with open("tests/unit/fixtures/subhub_valid_sub_test.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/subhub_valid_sub_test.json") as fh:
|
||||
valid_sub_test = json.loads(fh.read())
|
||||
self.valid_sub_test = convert_to_stripe_object(valid_sub_test)
|
||||
|
||||
with open("tests/unit/fixtures/valid_plan_response.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/valid_plan_response.json") as fh:
|
||||
valid_plan_response = json.loads(fh.read())
|
||||
self.valid_plan_response = convert_to_stripe_object(valid_plan_response)
|
||||
|
||||
with open("tests/unit/fixtures/subhub_account_user.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/subhub_account_user.json") as fh:
|
||||
subhub_user_account = json.loads(fh.read())
|
||||
self.subhub_user_account = subhub_user_account
|
||||
|
||||
with open("tests/unit/fixtures/subhub_return_data.json") as fh:
|
||||
with open("src/sub/tests/unit/fixtures/subhub_return_data.json") as fh:
|
||||
subhub_return_data = json.loads(fh.read())
|
||||
self.subhub_return_data = subhub_return_data
|
||||
|
||||
|
|
|
@ -51,15 +51,15 @@ def test_list_plans(mock_plans, mock_product, app):
|
|||
WHEN a request for plans is made
|
||||
THEN a success status of 200 is returned
|
||||
"""
|
||||
fh = open("tests/unit/fixtures/stripe_plan_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_plan_test1.json")
|
||||
plan_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
|
||||
fh = open("tests/unit/fixtures/stripe_plan_test2.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_plan_test2.json")
|
||||
plan_test2 = json.loads(fh.read())
|
||||
fh.close()
|
||||
|
||||
fh = open("tests/unit/fixtures/stripe_prod_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_prod_test1.json")
|
||||
prod_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
|
||||
|
@ -178,7 +178,7 @@ def test_subscribe_success(
|
|||
"""
|
||||
|
||||
client = app.app.test_client()
|
||||
fh = open("tests/unit/fixtures/stripe_cust_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_cust_test1.json")
|
||||
cust_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
|
||||
|
@ -186,17 +186,17 @@ def test_subscribe_success(
|
|||
mock_has_plan.return_value = False
|
||||
mock_fetch_customer.return_value = convert_to_stripe_object(cust_test1)
|
||||
|
||||
fh = open("tests/unit/fixtures/stripe_sub_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_sub_test1.json")
|
||||
sub_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
fh = open("tests/unit/fixtures/stripe_plan_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_plan_test1.json")
|
||||
plan_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
sub_test1["plan"] = plan_test1
|
||||
mock_subscription.return_value = sub_test1
|
||||
mock_new_sub.return_value = {"data": [sub_test1]}
|
||||
|
||||
fh = open("tests/unit/fixtures/stripe_prod_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_prod_test1.json")
|
||||
prod_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
mock_product.return_value = prod_test1
|
||||
|
@ -230,7 +230,7 @@ def test_subscribe_customer_existing(mock_new_customer, mock_has_plan, app):
|
|||
"""
|
||||
|
||||
client = app.app.test_client()
|
||||
fh = open("tests/unit/fixtures/stripe_cust_test1.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/stripe_cust_test1.json")
|
||||
cust_test1 = json.loads(fh.read())
|
||||
fh.close()
|
||||
|
||||
|
@ -328,7 +328,7 @@ def test_customer_unsubscribe_server_stripe_error_with_params(app, monkeypatch):
|
|||
|
||||
@mock.patch("sub.payments._get_all_plans")
|
||||
def test_plan_response_valid(mock_plans, app):
|
||||
fh = open("tests/unit/fixtures/valid_plan_response.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/valid_plan_response.json")
|
||||
valid_response = json.loads(fh.read())
|
||||
fh.close()
|
||||
|
||||
|
@ -349,7 +349,7 @@ def test_plan_response_valid(mock_plans, app):
|
|||
|
||||
@mock.patch("sub.payments._get_all_plans")
|
||||
def test_plan_response_invalid(mock_plans, app):
|
||||
fh = open("tests/unit/fixtures/invalid_plan_response.json")
|
||||
fh = open("src/sub/tests/unit/fixtures/invalid_plan_response.json")
|
||||
invalid_response = json.loads(fh.read())
|
||||
fh.close()
|
||||
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
backoff==1.8.0
|
||||
docker==4.1.0
|
||||
jsoncompare==0.1.2
|
||||
locustio==0.11.0
|
||||
mock==3.0.5
|
||||
# requirements for subhub testing to run
|
||||
# do not add requirements for subhub, src/app_requirements.txt already handles that
|
||||
mockito==1.1.1
|
||||
mypy==0.720
|
||||
patch==1.16
|
||||
purl==1.5
|
||||
pyparsing==2.4.0
|
||||
pytest==5.0.1
|
||||
pytest-cov==2.7.1
|
||||
pytest-mock==1.10.4
|
||||
mock==3.0.5
|
||||
patch==1.16
|
||||
pytest-watch==4.2.0
|
||||
locustio==0.11.0
|
||||
purl==1.5
|
||||
jsoncompare==0.1.2
|
||||
pyparsing==2.4.0
|
||||
mypy==0.720
|
||||
responses==0.10.6
|
||||
docker==4.1.0
|
||||
backoff==1.8.0
|
||||
requests==2.22.0
|
||||
responses==0.10.6
|
||||
|
|
67
tox.ini
67
tox.ini
|
@ -1,35 +1,52 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
[tox]
|
||||
minversion = 3.5.0
|
||||
envlist = py37-{sub,hub}
|
||||
minversion = 3.5.3
|
||||
envlist = py{37}
|
||||
skipsdist=true
|
||||
|
||||
[testenv]
|
||||
run_before =
|
||||
export AWS_XRAY_SDK_ENABLED=false
|
||||
|
||||
envdir = {toxinidir}/venv
|
||||
changedir =
|
||||
sub: {toxinidir}/src/sub
|
||||
hub: {toxinidir}/src/hub
|
||||
; NOTE: DEPLOYED_ENV is being set in .travis.yml but cannot be passed in as
|
||||
; it caused a configuration test breakage.
|
||||
passenv =
|
||||
STRIPE_API_KEY
|
||||
USER_TABLE
|
||||
EVENT_TABLE
|
||||
PAYMENT_API_KEY
|
||||
SUPPORT_API_KEY
|
||||
HUB_API_KEY
|
||||
SALESFORCE_BASKET_URI
|
||||
AWS_REGION
|
||||
CI
|
||||
EVENT_TABLE
|
||||
FXA_SQS_URI
|
||||
LOG_LEVEL
|
||||
HUB_API_KEY
|
||||
PAYMENT_API_KEY
|
||||
SALESFORCE_BASKET_URI
|
||||
STRIPE_API_KEY
|
||||
SUPPORT_API_KEY
|
||||
TRAVIS
|
||||
TRAVIS_*
|
||||
USER_TABLE
|
||||
setenv =
|
||||
AWS_XRAY_SDK_ENABLED=false
|
||||
PYTHONDONTWRITEBYTECODE=1
|
||||
envdir = {toxinidir}/venv
|
||||
deps =
|
||||
-r src/test_requirements.txt
|
||||
.[test]
|
||||
tox-run-before
|
||||
codecov
|
||||
|
||||
-r{toxinidir}/src/test_requirements.txt
|
||||
-r{toxinidir}/src/app_requirements.txt
|
||||
commands =
|
||||
sub: pytest --cov-config={toxinidir}/src/.coveragerc --cov=sub --cov-report term-missing --capture=sys {posargs}
|
||||
hub: pytest --cov-config={toxinidir}/src/.coveragerc --cov=hub --cov-report term-missing --capture=sys {posargs}
|
||||
|
||||
; This is valuable to ignore the symlinked shared components into
|
||||
; both the sub and hub modules:
|
||||
; `--ignore=src/sub/shared`
|
||||
;
|
||||
; The test output has been disabled (not captured) here. If this is
|
||||
; ever desired again, merely add in `--capture=sys`
|
||||
;
|
||||
; `--cov-append` is being leveraged as parallel is being specified in the
|
||||
; `.coveragerc` file. This may result in out of order results being
|
||||
; returned and thus append has been added to each result to form the whole
|
||||
; coverage report.
|
||||
;
|
||||
; `--no-cov-on-fail` provide no code coverage on a failing test run.
|
||||
py.test --cov-config={toxinidir}/.coveragerc --cov-append --cov-branch --no-cov-on-fail --cov=src/sub -k src/sub --ignore=src/sub/shared
|
||||
py.test --cov-config={toxinidir}/.coveragerc --cov-append --cov-branch --no-cov-on-fail --cov=src/hub -k src/hub --ignore=src/hub/shared
|
||||
py.test --cov-config={toxinidir}/.coveragerc --cov-append --cov-branch --no-cov-on-fail --cov=src/shared -k src/shared
|
||||
[pytest]
|
||||
norecursedirs = docs *.egg-info .git appdir .tox .venv env
|
||||
norecursedirs = docs *.egg-info .git appdir .tox .venv env services
|
||||
|
|
Загрузка…
Ссылка в новой задаче