示例#1
0
def test_create_customer_invalid_origin_system(monkeypatch):
    """
    GIVEN create a stripe customer
    WHEN An invalid origin system is provided
    THEN An exception should be raised
    """
    origin_system = "NOT_VALID"
    with pytest.raises(InvalidRequestError) as request_error:
        create_customer(
            g.subhub_account,
            user_id="test_mozilla",
            source_token="tok_visa",
            email="*****@*****.**",
            origin_system=origin_system,
            display_name="John Tester",
        )
    msg = f"origin_system={origin_system} not one of allowed origin system values, please contact a system administrator in the #subscription-platform channel."
    assert msg == str(request_error.value)
示例#2
0
    def test_create_customer_not_saved(self):
        subhub_account = self.subhub_account_mock("table", "region")
        subhub_account.get_user.return_value = None
        subhub_account.new_user.return_value = self.subhub_user
        subhub_account.save_user.return_value = False

        self.list_stripe_customer_mock.return_value = self.empty_customer_list
        self.create_stripe_customer_mock.return_value = self.customer_no_subs
        self.delete_stripe_customer_mock.return_value = self.deleted_customer

        with self.assertRaises(IntermittentError):
            create_customer(
                subhub_account,
                "user123",
                "*****@*****.**",
                "token",
                CFG.ALLOWED_ORIGIN_SYSTEMS[0],
                "test name",
            )
示例#3
0
def create_customer_for_processing():
    uid = uuid.uuid4()
    customer = create_customer(
        g.subhub_account,
        user_id="process_customer",
        source_token="tok_visa",
        email="test_fixture@{}tester.com".format(uid.hex),
        origin_system="Test_system",
        display_name="John Tester",
    )
    yield customer
示例#4
0
def test_create_customer_tok_invalid(monkeypatch):
    """
    GIVEN create a stripe customer
    WHEN provided an invalid test token and test userid
    THEN validate the customer metadata is correct
    """
    mock_possible_customers = MagicMock()
    data = PropertyMock(return_value=[])
    type(mock_possible_customers).data = data

    mock_customer_error = Mock(side_effect=InvalidRequestError(
        message="Customer instance has invalid ID",
        param="customer_id",
        code="invalid",
    ))

    subhub_account = MagicMock()

    mock_user = MagicMock()
    user_id = PropertyMock(return_value="user_123")
    cust_id = PropertyMock(return_value="cust_123")
    type(mock_user).user_id = user_id
    type(mock_user).cust_id = cust_id

    mock_save = MagicMock(return_value=True)

    subhub_account.new_user = mock_user
    subhub_account.save_user = mock_save

    monkeypatch.setattr("stripe.Customer.list", mock_possible_customers)
    monkeypatch.setattr("stripe.Customer.create", mock_customer_error)

    with pytest.raises(InvalidRequestError):
        create_customer(
            subhub_account,
            user_id="test_mozilla",
            source_token="tok_invalid",
            email="*****@*****.**",
            origin_system="Test_system",
            display_name="John Tester",
        )
示例#5
0
    def test_create_customer_modify_source(self):
        subhub_account = self.subhub_account_mock("table", "region")
        subhub_account.get_user.return_value = None

        self.list_stripe_customer_mock.return_value = self.customer_list
        self.modify_stripe_customer_mock.return_value = self.customer_no_subs

        customer = create_customer(
            subhub_account,
            "user123",
            "*****@*****.**",
            "token",
            CFG.ALLOWED_ORIGIN_SYSTEMS[0],
            "test name",
        )

        assert customer == self.customer_no_subs
示例#6
0
def test_create_customer(monkeypatch):
    """
    GIVEN create a stripe customer
    WHEN provided a test visa token and test fxa
    THEN validate the customer metadata is correct
    """
    mock_possible_customers = MagicMock()
    data = PropertyMock(return_value=[])
    type(mock_possible_customers).data = data

    mock_customer = MagicMock()
    id = PropertyMock(return_value="cust_123")
    type(mock_customer).id = id

    subhub_account = MagicMock()

    mock_user = MagicMock()
    user_id = PropertyMock(return_value="user_123")
    cust_id = PropertyMock(return_value="cust_123")
    type(mock_user).user_id = user_id
    type(mock_user).cust_id = cust_id

    mock_save = MagicMock(return_value=True)

    subhub_account.new_user = mock_user
    subhub_account.save_user = mock_save

    monkeypatch.setattr("stripe.Customer.list", mock_possible_customers)
    monkeypatch.setattr("stripe.Customer.create", mock_customer)

    customer = create_customer(
        subhub_account,
        user_id="user_123",
        source_token="tok_visa",
        email="*****@*****.**",
        origin_system="Test_system",
        display_name="John Tester",
    )

    assert customer is not None