def test_exists_client_returns_false_403(self, mock_data):
        """Test exists_client works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        client = iv.exists_client(data.client)
        err_msg = "It should return False, as client does not exist."
        assert client == False, err_msg
    def test_get_frequency_id(self, mock1):
        """Test get_frequency_id works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        id = iv.get_frequency_id('monthly')
        err_msg = "ID should be 4"
        assert id == 4, err_msg
    def test_exists_client_returns_false_403(self, mock_data):
        """Test exists_client works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        client = iv.exists_client(data.client)
        err_msg = "It should return False, as client does not exist."
        assert client == False, err_msg
    def test_create_client(self, mock_data):
        """Test create_client works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        res = iv.create_client(data.client)
        err_msg = "It should return the client as it already exists."
        assert res['data'] == data.client, err_msg
    def test_exists_client_returns_client(self, mock_data):
        """Test exists_client works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        client = iv.exists_client(data.client)
        err_msg = "It should return a client, as it exists."
        assert client['data'] == data.client, err_msg
    def test_get_frequency_id(self, mock1):
        """Test get_frequency_id works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        id = iv.get_frequency_id('monthly')
        err_msg = "ID should be 4"
        assert id == 4, err_msg
    def test_create_client(self, mock_data):
        """Test create_client works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        res = iv.create_client(data.client)
        err_msg = "It should return the client as it already exists."
        assert res['data'] == data.client, err_msg
    def test_exists_client_returns_client(self, mock_data):
        """Test exists_client works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        client = iv.exists_client(data.client)
        err_msg = "It should return a client, as it exists."
        assert client['data'] == data.client, err_msg
    def test_create_client_no_exists(self, mock_data, mock_post):
        """Test create_client works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        res = iv.create_client(data.client)
        err_msg = "It should a new client and have an ID."
        assert res['data']['id'] == 1, err_msg
        assert iv.client['data']['id'] == 1, err_msg
    def test_create_client_no_exists(self, mock_data, mock_post):
        """Test create_client works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        res = iv.create_client(data.client)
        err_msg = "It should a new client and have an ID."
        assert res['data']['id'] == 1, err_msg
        assert iv.client['data']['id'] == 1, err_msg
    def test_exists_client_returns_false_is_deleted(self, mock_data):
        """Test exists_client works."""

        data.client['is_deleted'] = True

        iv = invoiceNinja(token='token', url='http://myurl.com')
        client = iv.exists_client(data.client)
        err_msg = "It should return False, as it exists but has been deleted."
        assert client == False, err_msg
    def test_exists_client_returns_false_is_deleted(self, mock_data):
        """Test exists_client works."""

        data.client['is_deleted'] = True

        iv = invoiceNinja(token='token', url='http://myurl.com')
        client = iv.exists_client(data.client)
        err_msg = "It should return False, as it exists but has been deleted."
        assert client == False, err_msg
    def test_create_recurring_invoice_403(self, mock1, mock2):
        """Test create invoice works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        iv.client = dict()
        iv.client['data'] = dict()
        iv.client['data']['id'] = 1
        res = iv.create_recurring_invoice(dict(qty=1, recurring='monthly'))
        err_msg = "Something went wrong, it returns error"
        assert res['err'] == 403, err_msg
    def test_invoice_ninja_setup(self, mock_data):
        """Test invoice ninja setup works."""
        iv = invoiceNinja(token='token', url='http://myurl.com')

        err_msg = "invoice ninja should have been created with static data."
        assert iv.static == data.static, err_msg
        assert iv.token == 'token', err_msg
        assert iv.url == 'http://myurl.com', err_msg
        assert 'X-Ninja-Token' in iv.headers.keys(), err_msg
        assert iv.headers['X-Ninja-Token'] == 'token', err_msg
    def test_create_recurring_invoice_403(self, mock1, mock2):
        """Test create invoice works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        iv.client = dict()
        iv.client['data'] = dict()
        iv.client['data']['id'] = 1
        res = iv.create_recurring_invoice(dict(qty=1, recurring='monthly'))
        err_msg = "Something went wrong, it returns error"
        assert res['err'] == 403, err_msg
    def test_invoice_ninja_setup(self, mock_data):
        """Test invoice ninja setup works."""
        iv = invoiceNinja(token='token', url='http://myurl.com')

        err_msg = "invoice ninja should have been created with static data."
        assert iv.static == data.static, err_msg
        assert iv.token == 'token', err_msg
        assert iv.url == 'http://myurl.com', err_msg
        assert 'X-Ninja-Token' in iv.headers.keys(), err_msg
        assert iv.headers['X-Ninja-Token'] == 'token', err_msg
    def test_create_recurring_invoice_annually(self, mock1, mock2):
        """Test create recurring invoice works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        iv.client = dict()
        iv.client['data'] = dict()
        iv.client['data']['id'] = 1
        res = iv.create_recurring_invoice(dict(qty=1, recurring='annually'))
        err_msg = "There should be an invoice"
        assert res['data']['id'] == 1, err_msg
        assert iv.invoice['data']['id'] == 1, err_msg
    def test_create_recurring_invoice_annually(self, mock1, mock2):
        """Test create recurring invoice works."""

        iv = invoiceNinja(token='token', url='http://myurl.com')
        iv.client = dict()
        iv.client['data'] = dict()
        iv.client['data']['id'] = 1
        res = iv.create_recurring_invoice(dict(qty=1, recurring='annually'))
        err_msg = "There should be an invoice"
        assert res['data']['id'] == 1, err_msg
        assert iv.invoice['data']['id'] == 1, err_msg
Exemplo n.º 19
0
from forms import NewClient, NewInvoice, INVOICE_SCHEMA, INVOICE_ITEMS_SCHEMA
from flask_cors import CORS
from flask_wtf.csrf import generate_csrf, CsrfProtect
from invoiceninja import invoiceNinja
from jsonschema import validate, Draft4Validator

app = Flask(__name__)
app.config.from_object('settings')
cors = CORS(app,
            resources={
                r"/*": {
                    "origins": app.config.get('CORS'),
                    "supports_credentials": True
                }
            })
invoiceninja = invoiceNinja(app.config.get('TOKEN'))
CsrfProtect(app)


@app.route("/newclient", methods=['GET', 'POST'])
def newclient():
    """Endpoint for creating a new client."""
    form = NewClient()
    if request.method == 'GET':
        resp = form.data
        resp['csrf_token'] = generate_csrf()
        return jsonify(resp)
    else:
        if form.validate_on_submit():
            client = format_client_data(form.data)
            res = invoiceninja.create_client(client)
Exemplo n.º 20
0
#
# You should have received a copy of the GNU Affero General Public License
# along with this software.  If not, see <http://www.gnu.org/licenses/>.

from flask import Flask, jsonify, request
from forms import NewClient, NewInvoice, INVOICE_SCHEMA, INVOICE_ITEMS_SCHEMA
from flask_cors import CORS
from flask_wtf.csrf import generate_csrf, CsrfProtect
from invoiceninja import invoiceNinja
from jsonschema import validate, Draft4Validator


app = Flask(__name__)
app.config.from_object('settings')
cors = CORS(app, resources={r"/*": {"origins": app.config.get('CORS'), "supports_credentials": True}})
invoiceninja = invoiceNinja(app.config.get('TOKEN'))
CsrfProtect(app)


@app.route("/newclient", methods=['GET', 'POST'])
def newclient():
    """Endpoint for creating a new client."""
    form = NewClient()
    if request.method == 'GET':
        resp = form.data
        resp['csrf_token'] = generate_csrf()
        return jsonify(resp)
    else:
        if form.validate_on_submit():
            client = format_client_data(form.data)
            res = invoiceninja.create_client(client)