Exemplo n.º 1
0
def test_create_party(app):
    """Test Create party."""
    with app.app_context():
        mock_create_party = patch(
            'pay_api.services.oauth_service.requests.post')
        mock_post = mock_create_party.start()
        mock_post.return_value = Mock(status_code=201)
        mock_post.return_value.json.return_value = PARTY

        create_party_response = PayBcService().create_party(
            ACCESS_TOKEN, INVOICE_REQUEST)

        mock_create_party.stop()

        assert create_party_response.get('party_number') == PARTY_NUMBER
Exemplo n.º 2
0
def test_get_token(app):
    """Test generate token for valid credentials."""
    with app.app_context():

        mock_get_token = patch('pay_api.services.oauth_service.requests.post')
        token = ACCESS_TOKEN_RESPONSE
        mock_get = mock_get_token.start()
        mock_get.return_value = Mock(status_code=201)
        mock_get.return_value.json.return_value = token

        get_token_response = PayBcService().get_token()

        mock_get_token.stop()

        assert get_token_response.json().get('access_token') == ACCESS_TOKEN
Exemplo n.º 3
0
def test_create_invoice(app):
    """Test create invoice."""
    with app.app_context():
        mock_create_invoice = patch(
            'pay_api.services.oauth_service.requests.post')

        mock_post = mock_create_invoice.start()
        mock_post.return_value = Mock(status_code=201)
        mock_post.return_value.json.return_value = INVOICE

        create_invoice_response = PayBcService().create_invoice(
            ACCESS_TOKEN, SITE, INVOICE_REQUEST)

        mock_create_invoice.stop()

        assert create_invoice_response.get('invoice_number') == INVOICE_NUMBER
Exemplo n.º 4
0
def test_create_account(app):
    """Test create account."""
    with app.app_context():
        mock_create_account = patch(
            'pay_api.services.oauth_service.requests.post')

        mock_post = mock_create_account.start()
        mock_post.return_value = Mock(status_code=201)
        mock_post.return_value.json.return_value = ACCOUNT

        create_account_response = PayBcService().create_account(
            ACCESS_TOKEN, PARTY, INVOICE_REQUEST)

        mock_create_account.stop()

        assert create_account_response.get('account_number') == ACCOUNT_NUMBER
Exemplo n.º 5
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Resource for Invoice related endpoints."""
from flask import current_app, request
from flask_restplus import Namespace, Resource

from pay_api.services.paybc import PayBcService
from pay_api.utils.util import cors_preflight

API = Namespace('invoices', description='Payment System - Invoices')

PAY_BC_SERVICE = PayBcService()


@cors_preflight(['POST', 'OPTIONS'])
@API.route('')
class Invoice(Resource):
    """Endpoint resource to manage invoices."""
    @staticmethod
    @API.doc('Creates invoice in payment system')
    @API.response(201, 'Invoice created successfully')
    def post():
        """Return a new invoice in the payment system."""
        request_json = request.get_json()
        user_type = 'basic'  # TODO We will get this from token, hard-coding for now
        if user_type == 'basic' and request_json.get('method_of_payment',
                                                     None) == 'CC':