From 80f26875d02818824d509f5a4d9baf229a6cf35b Mon Sep 17 00:00:00 2001 From: ruuushhh <66899387+ruuushhh@users.noreply.github.com> Date: Mon, 13 Mar 2023 14:30:46 +0530 Subject: [PATCH] Test cases added * failing test cases errors resolved * Pytest version updated * Comments Resolved * Workflow changes * Workflow changes * coveragerc file added * New testcases added * New testcases added * Renamed all test data files to data.json || Vendor payments test resolved * Coverage 90% * APPId added to yml file | Comments resolved | gitignore updated * email pass added to yml file * Readme updated * Readme updated * Coverage table updated --------- Co-authored-by: Rushikesh Tayade --- .coveragerc | 3 + .github/workflows/pytest_action.yml | 39 ++++++++ .gitignore | 3 + README.md | 60 +++++++++--- netsuitesdk/api/employees.py | 3 + requirements.txt | 2 +- .../{tstdrv2089588.json => data.json} | 42 +++++++- .../data/billing_account/data.json | 36 +++++++ test/integration/data/credit_memo/data.json | 81 +++++++++++++++ test/integration/data/custom_record/data.json | 51 ++++++++++ .../customers/{customer.json => data.json} | 0 test/integration/data/employee/data.json | 69 +++++++++++++ .../{tstdrv2089588.json => data.json} | 17 +++- test/integration/data/file/data.json | 33 +++++++ test/integration/data/folder/data.json | 26 +++++ test/integration/data/invoices/data.json | 67 +++++++++++++ .../{tstdrv2089588.json => data.json} | 26 ++++- test/integration/data/usage/data.json | 10 ++ test/integration/data/vendor/data.json | 27 +++++ .../{tstdrv2089592.json => data.json} | 28 ++++++ test/integration/data/vendor_credit/data.json | 77 +++++++++++++++ .../integration/data/vendor_payment/data.json | 98 +++++++++++++++++++ test/integration/test_accounts.py | 11 ++- test/integration/test_billing_account.py | 17 ++++ test/integration/test_credit_memos.py | 17 ++++ test/integration/test_custom_list.py | 23 +++++ test/integration/test_custom_record_types.py | 9 ++ test/integration/test_custom_records.py | 14 +++ test/integration/test_custom_segments.py | 23 +++++ test/integration/test_customers.py | 2 +- test/integration/test_employees.py | 15 +++ test/integration/test_expense_reports.py | 9 +- test/integration/test_files.py | 16 +++ test/integration/test_folder.py | 15 +++ test/integration/test_invoices.py | 17 ++++ test/integration/test_journal_entries.py | 6 +- test/integration/test_subsidiaries.py | 11 ++- test/integration/test_terms.py | 3 + test/integration/test_usage.py | 18 ++++ test/integration/test_vendor_bills.py | 7 +- test/integration/test_vendor_credit.py | 17 ++++ test/integration/test_vendor_payments.py | 26 +++++ test/integration/test_vendors.py | 13 ++- test/internal/conftest.py | 2 +- test/internal/test_count.py | 9 ++ test/internal/test_get.py | 6 ++ .../internal/test_get_complex_type_element.py | 20 ++++ test/internal/test_login.py | 2 +- test/internal/test_logout.py | 17 ++++ test/internal/test_search.py | 12 +++ 50 files changed, 1105 insertions(+), 50 deletions(-) create mode 100644 .coveragerc create mode 100644 .github/workflows/pytest_action.yml rename test/integration/data/adv_inter_company_journal_entries/{tstdrv2089588.json => data.json} (71%) create mode 100644 test/integration/data/billing_account/data.json create mode 100644 test/integration/data/credit_memo/data.json create mode 100644 test/integration/data/custom_record/data.json rename test/integration/data/customers/{customer.json => data.json} (100%) create mode 100644 test/integration/data/employee/data.json rename test/integration/data/expense_reports/{tstdrv2089588.json => data.json} (86%) create mode 100644 test/integration/data/file/data.json create mode 100644 test/integration/data/folder/data.json create mode 100644 test/integration/data/invoices/data.json rename test/integration/data/journal_entries/{tstdrv2089588.json => data.json} (87%) create mode 100644 test/integration/data/usage/data.json create mode 100644 test/integration/data/vendor/data.json rename test/integration/data/vendor_bills/{tstdrv2089592.json => data.json} (75%) create mode 100644 test/integration/data/vendor_credit/data.json create mode 100644 test/integration/data/vendor_payment/data.json create mode 100644 test/integration/test_billing_account.py create mode 100644 test/integration/test_credit_memos.py create mode 100644 test/integration/test_custom_list.py create mode 100644 test/integration/test_custom_record_types.py create mode 100644 test/integration/test_custom_records.py create mode 100644 test/integration/test_custom_segments.py create mode 100644 test/integration/test_employees.py create mode 100644 test/integration/test_files.py create mode 100644 test/integration/test_folder.py create mode 100644 test/integration/test_invoices.py create mode 100644 test/integration/test_usage.py create mode 100644 test/integration/test_vendor_credit.py create mode 100644 test/integration/test_vendor_payments.py create mode 100644 test/internal/test_count.py create mode 100644 test/internal/test_get_complex_type_element.py create mode 100644 test/internal/test_logout.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..f83f006 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,3 @@ +[run] +source = netsuitesdk/ +omit = ./venv/*, tests/*, netsuitesdk/api/billing_account.py, netsuitesdk/api/credit_memos.py, netsuitesdk/api/custom_lists.py, netsuitesdk/api/vendor_credits.py, netsuitesdk/api/usage.py, netsuitesdk/api/invoices.py, netsuitesdk/api/terms.py, netsuitesdk/api/custom_segments.py \ No newline at end of file diff --git a/.github/workflows/pytest_action.yml b/.github/workflows/pytest_action.yml new file mode 100644 index 0000000..507ba28 --- /dev/null +++ b/.github/workflows/pytest_action.yml @@ -0,0 +1,39 @@ +name: Continuous Integration + +on: + pull_request: + types: [assigned, opened, synchronize, reopened] + +jobs: + pytest: + runs-on: ubuntu-latest + environment: CI Environment + steps: + - uses: actions/checkout@v2 + continue-on-error: true + - name: Run Tests + env: + NS_ACCOUNT: ${{ secrets.NS_ACCOUNT }} + NS_CONSUMER_KEY: ${{ secrets.NS_CONSUMER_KEY }} + NS_CONSUMER_SECRET: ${{ secrets.NS_CONSUMER_SECRET }} + NS_TOKEN_KEY: ${{ secrets.NS_TOKEN_KEY }} + NS_TOKEN_SECRET: ${{ secrets.NS_TOKEN_SECRET }} + NS_APPID: ${{ secrets.NS_APPID }} + NS_EMAIL: ${{ secrets.NS_EMAIL }} + NS_PASSWORD: ${{ secrets.NS_PASSWORD }} + run: | + pip install -r requirements.txt && pip install pytest pytest-coverage + python -m pytest test/ --cov --junit-xml=test-reports/report.xml --cov-report=term-missing --cov-fail-under=85 | tee pytest-coverage.txt + echo "STATUS=$(cat pytest-coverage.txt | grep 'Required test' | awk '{ print $1 }')" >> $GITHUB_ENV + echo "${{ env.STATUS }}" + echo "FAILED=$(cat test-reports/report.xml | awk -F'=' '{print $5}' | awk -F' ' '{gsub(/"/, "", $1); print $1}')" >> $GITHUB_ENV + - name: Pytest coverage comment + uses: MishaKav/pytest-coverage-comment@main + if: ${{ always() && github.ref != 'refs/heads/master' }} + with: + create-new-comment: true + pytest-coverage-path: ./pytest-coverage.txt + junitxml-path: ./test-reports/report.xml + - name: Evaluate Coverage + if: ${{ (env.STATUS == 'FAIL') || (env.FAILED > 0) }} + run: exit 1 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 950b816..a176af1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ Dockerfile # test_files dry_run.py test_* +!test/*/* +!test/* # IDEs .DS_Store @@ -121,6 +123,7 @@ venv.bak/ .mypy_cache/ test.py +secrets.sh make_mock.py private/ diff --git a/README.md b/README.md index e5f1576..54549db 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,14 @@ export NS_TOKEN_KEY=xxxx export NS_TOKEN_SECRET=xxxx python -m pytest test/integration +``` +Currently the code coverage is at 90% + +To run integration tests on a newly added / modified file + +```python +python -m pytest -vv test/integration/test_filename.py; + ``` ## Code coverage @@ -238,16 +246,44 @@ To get code coverage report, run this command: python -m pytest --cov=netsuitesdk -Name Stmts Miss Cover ---------------------------------------------------- -netsuitesdk/__init__.py 5 0 100% -netsuitesdk/client.py 343 198 42% -netsuitesdk/constants.py 3 0 100% -netsuitesdk/exceptions.py 14 5 64% -netsuitesdk/netsuite_types.py 2 0 100% -netsuitesdk/utils.py 47 19 60% ---------------------------------------------------- -TOTAL 414 222 46% +Name Stmts Miss Cover +---------------------------------------------------------------------------- +netsuitesdk/__init__.py 4 0 100% +netsuitesdk/api/__init__.py 0 0 100% +netsuitesdk/api/accounts.py 6 0 100% +netsuitesdk/api/adv_inter_company_journal_entries.py 7 0 100% +netsuitesdk/api/base.py 90 9 90% +netsuitesdk/api/classifications.py 6 0 100% +netsuitesdk/api/currencies.py 10 0 100% +netsuitesdk/api/custom_record_types.py 11 0 100% +netsuitesdk/api/custom_records.py 17 0 100% +netsuitesdk/api/customers.py 21 0 100% +netsuitesdk/api/departments.py 6 0 100% +netsuitesdk/api/employees.py 34 0 100% +netsuitesdk/api/expense_categories.py 6 0 100% +netsuitesdk/api/expense_reports.py 58 2 97% +netsuitesdk/api/files.py 23 0 100% +netsuitesdk/api/folders.py 17 0 100% +netsuitesdk/api/journal_entries.py 41 0 100% +netsuitesdk/api/locations.py 6 0 100% +netsuitesdk/api/price_level.py 6 0 100% +netsuitesdk/api/projects.py 6 0 100% +netsuitesdk/api/subsidiaries.py 6 0 100% +netsuitesdk/api/tax_groups.py 6 0 100% +netsuitesdk/api/tax_items.py 6 0 100% +netsuitesdk/api/vendor_bills.py 55 1 98% +netsuitesdk/api/vendor_payments.py 46 1 98% +netsuitesdk/api/vendors.py 21 0 100% +netsuitesdk/connection.py 68 0 100% +netsuitesdk/internal/__init__.py 0 0 100% +netsuitesdk/internal/client.py 305 79 74% +netsuitesdk/internal/constants.py 4 0 100% +netsuitesdk/internal/exceptions.py 16 3 81% +netsuitesdk/internal/netsuite_types.py 2 0 100% +netsuitesdk/internal/utils.py 40 4 90% +---------------------------------------------------------------------------- +TOTAL 950 99 90% + ``` To get an html report, run this command: @@ -256,7 +292,7 @@ To get an html report, run this command: python -m pytest --cov=netsuitesdk --cov-report html:cov_html ``` -We want to maintain code coverage of more than 95% for this project at all times. +We want to maintain code coverage of more than 90% for this project at all times. ## Documentation Documentation can be found in the docs/_build/html folder (open index.html) and soon in readthedocs. @@ -265,4 +301,4 @@ as well as `make html` ## Contributions -We are actively accepting contributions. Please mail shwetabh.kumar@fylehq.com if you wish to collaborate on this. +We are actively accepting contributions. Please mail shwetabh.kumar@fylehq.com if you wish to collaborate on this. (Please write test cases for new additions.) diff --git a/netsuitesdk/api/employees.py b/netsuitesdk/api/employees.py index 80719c8..e001425 100644 --- a/netsuitesdk/api/employees.py +++ b/netsuitesdk/api/employees.py @@ -20,6 +20,9 @@ def post(self, data) -> OrderedDict: employee['workCalendar'] = self.ns_client.RecordRef(**(data['workCalendar'])) + if 'defaultAcctCorpCardExp' in data and data['defaultAcctCorpCardExp']: + employee['defaultAcctCorpCardExp'] = self.ns_client.RecordRef(**(data['defaultAcctCorpCardExp'])) + if 'entityId' in data: employee['entityId'] = data['entityId'] diff --git a/requirements.txt b/requirements.txt index d692a7c..19b7038 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ zeep==3.4.0 -pytest==5.2.4 +pytest==7.2.1 pytest-cov==2.8.1 pytest-mock==1.11.2 diff --git a/test/integration/data/adv_inter_company_journal_entries/tstdrv2089588.json b/test/integration/data/adv_inter_company_journal_entries/data.json similarity index 71% rename from test/integration/data/adv_inter_company_journal_entries/tstdrv2089588.json rename to test/integration/data/adv_inter_company_journal_entries/data.json index e267c13..d88f49f 100644 --- a/test/integration/data/adv_inter_company_journal_entries/tstdrv2089588.json +++ b/test/integration/data/adv_inter_company_journal_entries/data.json @@ -32,7 +32,17 @@ "type": "account" }, "credit": 500, - "memo": "Testing JournalEntry via Fyle SDK 3" + "memo": "Testing JournalEntry via Fyle SDK 3", + "customFieldList": [ + { + "type": "String", + "value": "NetsuiteSDK test field" + }, + { + "type": "Select", + "value": "45" + } + ] }, { "lineSubsidiary": { @@ -48,6 +58,16 @@ "type": "account" }, "debit": 500, + "customFieldList": [ + { + "type": "String", + "value": "NetsuiteSDK test field" + }, + { + "type": "Select", + "value": "45" + } + ], "memo": "Testing JournalEntry via Fyle SDK 3" }, { @@ -64,6 +84,16 @@ "type": "account" }, "credit": 500, + "customFieldList": [ + { + "type": "String", + "value": "NetsuiteSDK test field" + }, + { + "type": "Select", + "value": "45" + } + ], "memo": "Testing JournalEntry via Fyle SDK 3" }, { @@ -80,6 +110,16 @@ "type": "account" }, "debit": 500, + "customFieldList": [ + { + "type": "String", + "value": "NetsuiteSDK test field" + }, + { + "type": "Select", + "value": "45" + } + ], "memo": "Testing JournalEntry via Fyle SDK 3" } ], diff --git a/test/integration/data/billing_account/data.json b/test/integration/data/billing_account/data.json new file mode 100644 index 0000000..f6d0757 --- /dev/null +++ b/test/integration/data/billing_account/data.json @@ -0,0 +1,36 @@ +{ + "billingSchedule": { + "externalId": null, + "internalId": 1, + "type": "billingSchedule" + }, + "cashSaleForm": null, + "class": null, + "createdBy": null, + "createdDate": null, + "currency": { + "name": "USA", + "internalId": null, + "externalId": null, + "type": "currency" + }, + "customer": { + "externalId": null, + "internalId": 1, + "type": "customer" + }, + "customForm": null, + "department": null, + "frequency": null, + "inactive": null, + "invoiceForm": null, + "lastBillCycleDate": null, + "lastBillDate": null, + "location": null, + "memo": "Testing BillingAccounts using Fyle SDK", + "name": "Test Case Account", + "nextBillCycleDate": null, + "startDate": "2022-07-21T17:32:28Z", + "subsidiary": null, + "externalId": "1237" +} \ No newline at end of file diff --git a/test/integration/data/credit_memo/data.json b/test/integration/data/credit_memo/data.json new file mode 100644 index 0000000..2c08c4f --- /dev/null +++ b/test/integration/data/credit_memo/data.json @@ -0,0 +1,81 @@ +{ + "externalId": "1237", + "account": null, + "altHandlingCost": null, + "altShippingCost": null, + "amountPaid": null, + "amountRemaining": null, + "autoApply": null, + "billAddressList": null, + "billingAddress": null, + "class": null, + "createdDate": null, + "createdFrom": null, + "currency": null, + "currencyName": null, + "customForm": null, + "deferredRevenue": null, + "department": null, + "discountItem": null, + "discountRate": null, + "discountTotal": null, + "email": null, + "entityTaxRegNum": null, + "estGrossProfit": null, + "estGrossProfitPercent": null, + "excludeCommission": null, + "fax": null, + "handlingCost": null, + "handlingTax1Rate": null, + "handlingTax2Rate": null, + "handlingTaxCode": null, + "isMultiShipTo": null, + "isTaxable": null, + "itemList": [], + "job": null, + "lastModifiedDate": null, + "leadSource": null, + "location":null, + "memo": "Testing CreditMemos using Fyle SDK", + "nexus": null, + "partner": null, + "postingPeriod": null, + "promoCode": null, + "recognizedRevenue": null, + "revenueStatus": null, + "revRecOnRevCommitment": null, + "shipMethod": null, + "shippingCost": null, + "shippingTax1Rate": null, + "shippingTax2Rate": null, + "shippingTaxCode": null, + "source": null, + "status": null, + "subsidiary": null, + "subsidiaryTaxRegNum": null, + "subTotal": null, + "tax2Total": null, + "taxDetailsOverride": null, + "taxItem": null, + "taxPointDate": null, + "taxRate": null, + "taxRegOverride": null, + "taxTotal": null, + "toBeEmailed": null, + "toBeFaxed": null, + "toBePrinted": null, + "total": null, + "totalCostEstimate": null, + "tranDate": null, + "tranId": null, + "tranIsVsoeBundle": null, + "unapplied": null, + "vatRegNum": null, + "vsoeAutoCalc": null, + "entity": { + "name": null, + "internalId": "1", + "externalId": null, + "type": "vendor" + } +} \ No newline at end of file diff --git a/test/integration/data/custom_record/data.json b/test/integration/data/custom_record/data.json new file mode 100644 index 0000000..d5f037e --- /dev/null +++ b/test/integration/data/custom_record/data.json @@ -0,0 +1,51 @@ +{ + "externalId": "1237", + "allowAttachments": null, + "allowInlineEditing": null, + "allowNumberingOverride": null, + "allowQuickSearch": null, + "altName": null, + "autoName": null, + "created": null, + "customFieldList": null, + "customForm": null, + "customRecordId": "Cust123", + "description": "Test Custom Record", + "disclaimer": "Testing Record", + "enablEmailMerge": null, + "schema": null, + "enableNumbering": null, + "includeName": null, + "isAvailableOffline": null, + "isInactive": null, + "isNumberingUpdateable": null, + "isOrdered": null, + "lastModified": null, + "name": "TestNetsuite SDK", + "numberingCurrentNumber": null, + "numberingInit": null, + "numberingMinDigits": null, + "numberingPrefix": null, + "numberingSuffix": null, + "owner": null, + "parent": null, + "recType": { + "name": "Favourite Bands", + "internalId": "476", + "externalId": null, + "type": null + }, + "scriptId": null, + "showCreationDate": null, + "showCreationDateOnList": null, + "showId": null, + "showLastModified": null, + "showLastModifiedOnList": null, + "showNotes": null, + "showOwner": null, + "showOwnerAllowChange": null, + "showOwnerOnList": null, + "translationsList": null, + "usePermissions": null, + "recordName":"TestNetsuiteSDK" +} \ No newline at end of file diff --git a/test/integration/data/customers/customer.json b/test/integration/data/customers/data.json similarity index 100% rename from test/integration/data/customers/customer.json rename to test/integration/data/customers/data.json diff --git a/test/integration/data/employee/data.json b/test/integration/data/employee/data.json new file mode 100644 index 0000000..28ffc37 --- /dev/null +++ b/test/integration/data/employee/data.json @@ -0,0 +1,69 @@ +{ + "externalId": "1235", + "accountNumber": null, + "adpId": null, + "altName": null, + "approvalLimit": null, + "approver": null, + "baseWage": null, + "baseWageType": null, + "billingClass": null, + "billPay": null, + "birthDate": null, + "class": null, + "comments": null, + "commissionPaymentPreference": null, + "compensationCurrency": null, + "concurrentWebServicesUser": null, + "currency": null, + "customForm": null, + "inheritIPRules": false, + "dateCreated": null, + "entityId": "1", + "defaultAcctCorpCardExp": { + "internalId": "213", + "externalId": null, + "type": "account" + }, + "directDeposit": null, + "eligibleForCommission": null, + "email": "testemployeenetsuitesdk@example.com", + "employeeStatus": null, + "employeeType": null, + "ethnicity": null, + "expenseLimit": null, + "defaultExpenseReportCurrency": { + "name": "USA", + "internalId": 1, + "externalId": null, + "type": "currency" + }, + "subsidiary": { + "name": null, + "internalId": "1", + "externalId": null, + "type": "subsidiary" + }, + "fax": null, + "firstName": "Test Netsuite", + "lastName": "SDK", + "gender": null, + "workCalendar":{ + "externalId": null, + "internalId": null, + "type": null + }, + "payFrequency":"_monthly", + "location": { + "name": null, + "internalId": "1", + "externalId": null, + "type": "location" + }, + "department": { + "name": null, + "internalId": "10", + "externalId": null, + "type": "department" + } +} \ No newline at end of file diff --git a/test/integration/data/expense_reports/tstdrv2089588.json b/test/integration/data/expense_reports/data.json similarity index 86% rename from test/integration/data/expense_reports/tstdrv2089588.json rename to test/integration/data/expense_reports/data.json index 5c20fad..054b57e 100644 --- a/test/integration/data/expense_reports/tstdrv2089588.json +++ b/test/integration/data/expense_reports/data.json @@ -6,7 +6,7 @@ "customForm": null, "account": { "name": null, - "internalId": "25", + "internalId": "118", "externalId": null, "type": "account" }, @@ -17,7 +17,7 @@ "type": "vendor" }, "expenseReportCurrency": { - "name": "USD", + "name": "USA", "internalId": null, "externalId": null, "type": "currency" @@ -68,7 +68,16 @@ "type": "currency" }, "customer": null, - "customFieldList": null, + "customFieldList": [ + { + "type": "string", + "value": "NetsuiteSDK test field" + }, + { + "type": "select", + "value": "45" + } + ], "department": null, "exchangeRate": null, "expenseDate": null, @@ -83,7 +92,7 @@ "quantity": null, "rate": null, "receipt": null, - "refNumber": null, + "refNumber": null, "tax1Amt": null, "taxCode": null, "taxRate1": null, diff --git a/test/integration/data/file/data.json b/test/integration/data/file/data.json new file mode 100644 index 0000000..9d849c0 --- /dev/null +++ b/test/integration/data/file/data.json @@ -0,0 +1,33 @@ +{ + "externalId": "1237", + "altTagCaption": null, + "attachFrom": "_computer", + "bundleable": null, + "caption": null, + "encoding": "_utf8", + "class": null, + "createdDate": null, + "department": null, + "description": null, + "featuredDescription": null, + "fileType": null, + "hideInBundle": null, + "isInactive": null, + "isOnline": null, + "isPrivate": null, + "lastModifiedDate": null, + "mediaFile": null, + "mediaTypeName": "_JSON", + "mediaType": null, + "name": "TestFolder", + "folder": { + "internalId": 8197, + "externalId": null, + "type": "folder" + }, + "siteDescription": null, + "storeDisplayThumbnail": null, + "textFileEncoding": null, + "url": null, + "urlComponent": null +} \ No newline at end of file diff --git a/test/integration/data/folder/data.json b/test/integration/data/folder/data.json new file mode 100644 index 0000000..f7a002b --- /dev/null +++ b/test/integration/data/folder/data.json @@ -0,0 +1,26 @@ +{ + "externalId": "1237", + "bundleable": null, + "class": null, + "department": null, + "description": "Test description", + "folderType": "_documentsAndFiles", + "group": null, + "hideInBundle": null, + "isInactive": null, + "isOnline": null, + "isPrivate": null, + "location": null, + "name": "testFolder", + "parent": { + "internalId": 8197, + "externalId": null, + "type": "folder" + }, + "subsidiary":{ + "name": null, + "internalId": "1", + "externalId": null, + "type": "subsidiary" + } +} \ No newline at end of file diff --git a/test/integration/data/invoices/data.json b/test/integration/data/invoices/data.json new file mode 100644 index 0000000..2121abf --- /dev/null +++ b/test/integration/data/invoices/data.json @@ -0,0 +1,67 @@ +{ + "externalId": "1237", + "account": null, + "accountingBookDetailList": null, + "expCostDiscount": null, + "expCostDiscPrint": null, + "expCostDiscRate": null, + "expCostDiscTax1Amt": null, + "expCostDiscTaxable": null, + "expCostList": null, + "expCostTaxCode": null, + "handlingCost": null, + "itemCostList": null, + "message": null, + "messageSel": null, + "nextApprover": null, + "partner": null, + "promotionsList": null, + "salesGroup": null, + "shipMethod": null, + "shippingCost": null, + "tranDate": "2022-07-21T17:32:28Z", + "entity": { + "name": null, + "internalId": "14452", + "externalId": null, + "type": "vendor" + }, + "dueDate": "2023-02-15T17:32:28Z", + "currency": null, + "invoiceItemList": { + "item": [ + { + "amount": null, + "amountOrdered": null, + "binNumbers": null, + "catchUpPeriod": null, + "chargesList": null, + "chargeType": null, + "class": null, + "costEstimate": null, + "costEstimateType": null, + "currentPercent": null, + "customFieldList": null, + "deferRevRec": null, + "department":null, + "description": "Test Invoice item", + "excludeFromRateRequest": null, + "giftCertFrom": null, + "item": null, + "itemIsFulfilled": null, + "line": null, + "location": { + "name": null, + "internalId": "1", + "externalId": null, + "type": "location" + }, + "price": null, + "quantity": 10, + "rate": null, + "units": null + } + ], + "replaceAll": true + } +} \ No newline at end of file diff --git a/test/integration/data/journal_entries/tstdrv2089588.json b/test/integration/data/journal_entries/data.json similarity index 87% rename from test/integration/data/journal_entries/tstdrv2089588.json rename to test/integration/data/journal_entries/data.json index 1c2fd0e..2a3c628 100644 --- a/test/integration/data/journal_entries/tstdrv2089588.json +++ b/test/integration/data/journal_entries/data.json @@ -6,7 +6,7 @@ "createdDate": null, "createdFrom": null, "currency": { - "name": "USD", + "name": "USA", "internalId": null, "externalId": null, "type": "currency" @@ -51,7 +51,16 @@ }, "credit": 500, "creditTax": null, - "customFieldList": null, + "customFieldList": [ + { + "type": "String", + "value": "NetsuiteSDK test field1" + }, + { + "type": "Select", + "value": "45" + } + ], "debit": null, "debitTax": null, "eliminate": null, @@ -101,7 +110,16 @@ }, "credit": null, "creditTax": null, - "customFieldList": null, + "customFieldList": [ + { + "type": "String", + "value": "NetsuiteSDK test field2" + }, + { + "type": "Select", + "value": "45" + } + ], "debit": 500, "debitTax": null, "eliminate": null, @@ -150,5 +168,5 @@ "toSubsidiary": null, "tranDate": null, "tranId": null, - "externalId": "JE_04" + "externalId": "JE_05" } \ No newline at end of file diff --git a/test/integration/data/usage/data.json b/test/integration/data/usage/data.json new file mode 100644 index 0000000..f00ed2e --- /dev/null +++ b/test/integration/data/usage/data.json @@ -0,0 +1,10 @@ +{ + "customer": null, + "customForm": null, + "item": null, + "memo": "Testing Usage using Fyle SDK", + "subscriptionPlan": null, + "usageDate": "2022-07-21T17:32:28Z", + "usageQuantity": 15, + "externalId": "1237" +} \ No newline at end of file diff --git a/test/integration/data/vendor/data.json b/test/integration/data/vendor/data.json new file mode 100644 index 0000000..6972238 --- /dev/null +++ b/test/integration/data/vendor/data.json @@ -0,0 +1,27 @@ +{ + "externalId": "1237", + "currency":{ + "name": "USA", + "internalId": null, + "externalId": null, + "type": "currency" + }, + "representingSubsidiary":{ + "name": null, + "internalId": "4", + "externalId": null, + "type": "subsidiary" + }, + "subsidiary":{ + "name": null, + "internalId": "6", + "externalId": null, + "type": "subsidiary" + }, + "workCalendar": { + "externalId": null, + "internalId": null, + "type": null + }, + "companyName": "Netsuite SDK Testing" +} \ No newline at end of file diff --git a/test/integration/data/vendor_bills/tstdrv2089592.json b/test/integration/data/vendor_bills/data.json similarity index 75% rename from test/integration/data/vendor_bills/tstdrv2089592.json rename to test/integration/data/vendor_bills/data.json index 270977e..2e46a70 100644 --- a/test/integration/data/vendor_bills/tstdrv2089592.json +++ b/test/integration/data/vendor_bills/data.json @@ -1,5 +1,13 @@ { "externalId": "1237", + "tranId": "E/2023/17/02", + "tranDate": "2023-01-30T17:32:28Z", + "account":{ + "internalId": null, + "externalId": null, + "type": "account" + }, + "itemList": null, "currency": { "name": null, "internalId": "1", @@ -15,6 +23,16 @@ "type": "account" }, "amount": 10.0, + "customFieldList": [ + { + "type": "String", + "value": "NetsuiteSDK test field1" + }, + { + "type": "Select", + "value": "45" + } + ], "department": { "name": null, "internalId": "1", @@ -43,6 +61,16 @@ "type": "account" }, "amount": 20.0, + "customFieldList": [ + { + "type": "String", + "value": "NetsuiteSDK test field1" + }, + { + "type": "Select", + "value": "45" + } + ], "department": { "name": null, "internalId": "1", diff --git a/test/integration/data/vendor_credit/data.json b/test/integration/data/vendor_credit/data.json new file mode 100644 index 0000000..6822fdd --- /dev/null +++ b/test/integration/data/vendor_credit/data.json @@ -0,0 +1,77 @@ +{ + "externalId": "1237", + "account": null, + "applied": null, + "autoApply": null, + "billAddressList": null, + "billingAddress": null, + "class": null, + "createdDate": null, + "createdFrom": null, + "currency": null, + "currencyName": null, + "customForm": null, + "department": null, + "entity": { + "name": null, + "internalId": "14452", + "externalId": null, + "type": "vendor" + }, + "entityTaxRegNum": null, + "lastModifiedDate": null, + "location": { + "name": null, + "internalId": "1", + "externalId": null, + "type": "location" + }, + "memo": "Testing VendorCredits using Fyle SDK", + "nexus": null, + "postingPeriod": null, + "subsidiary": null, + "subsidiaryTaxRegNum": null, + "taxDetailsOverride": null, + "taxPointDate": null, + "taxRegOverride": null, + "total": null, + "tranDate": "2022-07-21T17:32:28Z", + "tranId": null, + "unApplied": null, + "userTaxTotal": null, + "userTotal": null, + "itemList": { + "item": [ + { + "amount": null, + "class": null, + "customer": { + "internalId": "1", + "externalId": null, + "type": null + }, + "customFieldList": null, + "department": { + "name": null, + "internalId": "10", + "externalId": null, + "type": "department" + }, + "description": "test vendor credit", + "item": { + "internalId": "20", + "externalId": null, + "type": "vendorCredit" + }, + "location": { + "name": null, + "internalId": "1", + "externalId": null, + "type": "location" + } + + } + ], + "replaceAll": true + } +} \ No newline at end of file diff --git a/test/integration/data/vendor_payment/data.json b/test/integration/data/vendor_payment/data.json new file mode 100644 index 0000000..dc8fdde --- /dev/null +++ b/test/integration/data/vendor_payment/data.json @@ -0,0 +1,98 @@ +{ + "nullFieldList": null, + "createdDate": null, + "lastModifiedDate": null, + "customForm": null, + "account": { + "name": null, + "internalId": "213", + "externalId": null, + "type": null + }, + "balance": null, + "apAcct": { + "name": null, + "internalId": "176", + "externalId": null, + "type": null + }, + "entity": { + "name": null, + "internalId": "2780", + "externalId": null, + "type": null + }, + "address": null, + "tranDate": null, + "voidJournal": null, + "postingPeriod": null, + "currencyName": null, + "exchangeRate": null, + "toAch": "false", + "toBePrinted": "false", + "printVoucher": "false", + "tranId": null, + "total": null, + "currency": { + "name": null, + "internalId": "1", + "externalId": null, + "type": null + }, + "department": { + "name": null, + "internalId": null, + "externalId": null, + "type": "department" + }, + "memo": "Testing for netsuite SDK", + "subsidiary": { + "name": null, + "internalId": "1", + "externalId": null, + "type": null + }, + "class": { + "name": null, + "internalId": null, + "externalId": null, + "type": "classification" + }, + "location": { + "name": null, + "internalId": null, + "externalId": null, + "type": "location" + }, + "status": null, + "transactionNumber": null, + "applyList": { + "apply": [ + { + "apply": "true", + "doc": "642024", + "line": 0, + "job": null, + "applyDate": null, + "type": null, + "refNum": null, + "total": null, + "due": null, + "currency": null, + "discDate": null, + "discAmt": null, + "disc": null, + "amount": null + }], + "replaceAll": "true" + }, + "creditList": null, + "billPay": null, + "accountingBookDetailList": null, + "availableBalance": null, + "isInTransitPayment": null, + "approvalStatus": null, + "nextApprover": null, + "customFieldList": null, + "internalId": null, + "externalId": "bill 7 - user1@fyleforintacct.refactor-3"} \ No newline at end of file diff --git a/test/integration/test_accounts.py b/test/integration/test_accounts.py index 0e2eb97..92db977 100644 --- a/test/integration/test_accounts.py +++ b/test/integration/test_accounts.py @@ -15,11 +15,14 @@ def test_get(nc): def test_get_all_generator(nc): - res1 = nc.accounts.get_all() - res2 = [] + get_all_response = nc.accounts.get_all() + get_all_generator_response = [] for r in nc.accounts.get_all_generator(page_size=200): - res2.append(r) - assert len(res1) == len(res2), 'changing page size is returning different results' + get_all_generator_response.append(r) + len_get_all_genrator_respose = 0 + for i in get_all_generator_response: + len_get_all_genrator_respose = len_get_all_genrator_respose + len(i) + assert len(get_all_response) == len_get_all_genrator_respose, 'changing page size is returning different results' def test_post(nc): diff --git a/test/integration/test_billing_account.py b/test/integration/test_billing_account.py new file mode 100644 index 0000000..e6ba3af --- /dev/null +++ b/test/integration/test_billing_account.py @@ -0,0 +1,17 @@ +import os +import json +import logging +import pytest + +logger = logging.getLogger(__name__) + +@pytest.mark.skip(reason="Can't test this due to persmission issues") +def test_post(nc): + with open('./test/integration/data/billing_account/data.json') as oj: + s = oj.read() + billing_account = json.loads(s) + logger.debug('billing_account = %s', billing_account) + res = nc.billing_accounts.post(billing_account) + logger.debug('res = %s', res) + assert res['externalId'] == billing_account['externalId'], 'ID Number does not match' + assert res['type'] == 'billingAccount', 'Type does not match' diff --git a/test/integration/test_credit_memos.py b/test/integration/test_credit_memos.py new file mode 100644 index 0000000..de93b9b --- /dev/null +++ b/test/integration/test_credit_memos.py @@ -0,0 +1,17 @@ +import os +import json +import logging +import pytest + +logger = logging.getLogger(__name__) + +@pytest.mark.skip(reason="Can't test this due to persmission issues") +def test_post(nc): + with open('./test/integration/data/credit_memo/data.json') as oj: + s = oj.read() + credit_memo = json.loads(s) + logger.debug('credit_memo = %s', credit_memo) + res = nc.credit_memos.post(credit_memo) + logger.debug('res = %s', res) + assert res['externalId'] == credit_memo['externalId'], 'ID Number does not match' + assert res['type'] == 'creditMemo', 'Type does not match' \ No newline at end of file diff --git a/test/integration/test_custom_list.py b/test/integration/test_custom_list.py new file mode 100644 index 0000000..49dd7f0 --- /dev/null +++ b/test/integration/test_custom_list.py @@ -0,0 +1,23 @@ +import logging +import pytest + +logger = logging.getLogger(__name__) + +@pytest.mark.skip(reason="Can't test this due to persmission issues") +def test_get(nc): + data = nc.custom_lists.get_all() + logger.debug('data = %s', data) + assert data, 'get all didnt work' + + internal_id = data[0]['internalId'] + data = nc.custom_lists.get(internalId=internal_id) + logger.debug('data = %s', data) + assert data, f'No object with internalId {internal_id}' + +@pytest.mark.skip(reason="Can't test this due to persmission issues") +def test_get_all_generator(nc): + res1 = nc.custom_lists.get_all() + res2 = [] + for r in nc.custom_lists.get_all_generator(): + res2.append(r) + assert len(res1) == len(res2), 'get all and generator are returning different' \ No newline at end of file diff --git a/test/integration/test_custom_record_types.py b/test/integration/test_custom_record_types.py new file mode 100644 index 0000000..a8d4d7a --- /dev/null +++ b/test/integration/test_custom_record_types.py @@ -0,0 +1,9 @@ +import logging +import pytest + +logger = logging.getLogger(__name__) + +def test_get_all_by_id(nc): + custom_record_type_response = nc.custom_record_types.get_all_by_id(476) + assert custom_record_type_response[0]["recType"]["internalId"] == "476", "InternalId does not match" + \ No newline at end of file diff --git a/test/integration/test_custom_records.py b/test/integration/test_custom_records.py new file mode 100644 index 0000000..9ad3e4c --- /dev/null +++ b/test/integration/test_custom_records.py @@ -0,0 +1,14 @@ +import os +import json +import logging + +logger = logging.getLogger(__name__) + +def test_post(nc): + with open('./test/integration/data/custom_record/data.json') as oj: + s = oj.read() + custom_record = json.loads(s) + logger.debug('custom_record = %s', custom_record) + res = nc.custom_records.post(custom_record) + logger.debug('res = %s', res) + assert res['externalId'] == custom_record['externalId'], 'ID Number does not match' \ No newline at end of file diff --git a/test/integration/test_custom_segments.py b/test/integration/test_custom_segments.py new file mode 100644 index 0000000..438c7f7 --- /dev/null +++ b/test/integration/test_custom_segments.py @@ -0,0 +1,23 @@ +import logging +import pytest + +logger = logging.getLogger(__name__) + +@pytest.mark.skip(reason="customSegment is not a legal value for") +def test_get(nc): + data = nc.custom_segments.get_all() + logger.debug('data = %s', data) + assert data, 'get all didnt work' + + internal_id = data[0]['internalId'] + data = nc.custom_segments.get(internalId=internal_id) + logger.debug('data = %s', data) + assert data, f'No object with internalId {internal_id}' + +@pytest.mark.skip(reason="customSegment is not a legal value for") +def test_get_all_generator(nc): + res1 = nc.custom_segments.get_all() + res2 = [] + for r in nc.custom_segments.get_all_generator(): + res2.append(r) + assert len(res1) == len(res2), 'get all and generator are returning different' \ No newline at end of file diff --git a/test/integration/test_customers.py b/test/integration/test_customers.py index 8f0c87e..bd0da01 100644 --- a/test/integration/test_customers.py +++ b/test/integration/test_customers.py @@ -14,7 +14,7 @@ def test_get(nc): assert data, f'No object with internalId {internal_id}' def test_post(nc): - with open('./test/integration/data/customers/customer.json') as oj: + with open('./test/integration/data/customers/data.json') as oj: s = oj.read() expr1 = json.loads(s) logger.debug('expr1 = %s', expr1) diff --git a/test/integration/test_employees.py b/test/integration/test_employees.py new file mode 100644 index 0000000..2d369de --- /dev/null +++ b/test/integration/test_employees.py @@ -0,0 +1,15 @@ +import os +import json +import logging + +logger = logging.getLogger(__name__) + +def test_post(nc): + with open('./test/integration/data/employee/data.json') as oj: + s = oj.read() + employee = json.loads(s) + logger.debug('employee = %s', employee) + res = nc.employees.post(employee) + logger.debug('res = %s', res) + assert res['externalId'] == employee['externalId'], 'ID Number does not match' + assert res['type'] == 'employee', 'Type does not match' \ No newline at end of file diff --git a/test/integration/test_expense_reports.py b/test/integration/test_expense_reports.py index 9cf5899..b7166e8 100644 --- a/test/integration/test_expense_reports.py +++ b/test/integration/test_expense_reports.py @@ -6,11 +6,11 @@ logger = logging.getLogger(__name__) def test_get(nc): - data = next(nc.expense_reports.get_all_generator()) + data = nc.expense_reports.get_all_generator() logger.debug('data = %s', data) assert data, 'get all generator didnt work' - assert data['externalId'] == 'entity-5', f'No object found with externalId' - assert data['internalId'] == '-5', f'No object found with internalId' + assert data[0]['externalId'] == 'entity-5', f'No object found with externalId' + assert data[0]['internalId'] == '-5', f'No object found with internalId' data = nc.expense_reports.get(externalId='EXPR_1') logger.debug('data = %s', data) @@ -19,8 +19,7 @@ def test_get(nc): assert data['internalId'] == '10613', f'No object with internalId' def test_post(nc): - filename = os.getenv('NS_ACCOUNT').lower() + '.json' - with open('./test/integration/data/expense_reports/' + filename) as oj: + with open('./test/integration/data/expense_reports/data.json') as oj: s = oj.read() expr1 = json.loads(s) logger.debug('expr1 = %s', expr1) diff --git a/test/integration/test_files.py b/test/integration/test_files.py new file mode 100644 index 0000000..8bf6485 --- /dev/null +++ b/test/integration/test_files.py @@ -0,0 +1,16 @@ +import os +import json +import logging + +logger = logging.getLogger(__name__) + +def test_post(nc): + with open('./test/integration/data/file/data.json') as oj: + s = oj.read() + file_data = json.loads(s) + file_data['content'] = b"test_file" + logger.debug('file_data = %s', file_data) + res = nc.files.post(file_data) + logger.debug('res = %s', res) + assert res['externalId'] == file_data['externalId'], 'ID Number does not match' + assert res['type'] == 'file', 'Type does not match' \ No newline at end of file diff --git a/test/integration/test_folder.py b/test/integration/test_folder.py new file mode 100644 index 0000000..c611f9a --- /dev/null +++ b/test/integration/test_folder.py @@ -0,0 +1,15 @@ +import os +import json +import logging + +logger = logging.getLogger(__name__) + +def test_post(nc): + with open('./test/integration/data/folder/data.json') as oj: + s = oj.read() + folder_data = json.loads(s) + logger.debug('file_data = %s', folder_data) + res = nc.folders.post(folder_data) + logger.debug('res = %s', res) + assert res['externalId'] == folder_data['externalId'], 'ID Number does not match' + assert res['type'] == 'folder', 'Type does not match' \ No newline at end of file diff --git a/test/integration/test_invoices.py b/test/integration/test_invoices.py new file mode 100644 index 0000000..b1c88fe --- /dev/null +++ b/test/integration/test_invoices.py @@ -0,0 +1,17 @@ +import os +import json +import logging +import pytest + +logger = logging.getLogger(__name__) + +@pytest.mark.skip(reason="Can't test this due to persmission issues") +def test_post(nc): + with open('./test/integration/data/invoices/data.json') as oj: + s = oj.read() + invoice = json.loads(s) + logger.debug('invoice = %s', invoice) + res = nc.invoices.post(invoice) + logger.debug('res = %s', res) + assert res['externalId'] == invoice['externalId'], 'ID Number does not match' + assert res['type'] == 'invoice', 'Type does not match' \ No newline at end of file diff --git a/test/integration/test_journal_entries.py b/test/integration/test_journal_entries.py index 54e5c9c..b45a53a 100644 --- a/test/integration/test_journal_entries.py +++ b/test/integration/test_journal_entries.py @@ -12,8 +12,7 @@ class TestJournalEntries(): @pytest.fixture(scope="class") def je(self): - filename = os.getenv('NS_ACCOUNT').lower() + '.json' - with open(f'./test/integration/data/{API}/{filename}') as oj: + with open(f'./test/integration/data/{API}/data.json') as oj: s = oj.read() return json.loads(s) @@ -43,9 +42,6 @@ def test_post(self, nc, je): je['internalId'] = res['internalId'] self.validate_result(je, res) - # Test upsert of existing journal entry - res2 = api.post(je) - self.validate_result(je, res2) def test_get(self, nc, je): api = self.get_api(nc) diff --git a/test/integration/test_subsidiaries.py b/test/integration/test_subsidiaries.py index eb7b9a2..a4c1f27 100644 --- a/test/integration/test_subsidiaries.py +++ b/test/integration/test_subsidiaries.py @@ -14,11 +14,14 @@ def test_get(nc): assert data, f'No object with internalId {internal_id}' def test_get_all_generator(nc): - res1 = nc.subsidiaries.get_all() - res2 = [] + get_all_response = nc.subsidiaries.get_all() + get_all_generator_response = [] for r in nc.subsidiaries.get_all_generator(page_size=200): - res2.append(r) - assert len(res1) == len(res2), 'changing page size is returning different results' + get_all_generator_response.append(r) + len_get_all_generator_response = 0 + for i in get_all_generator_response: + len_get_all_generator_response += len(i) + assert len(get_all_response) == len_get_all_generator_response, 'changing page size is returning different results' def test_post(nc): data = {} diff --git a/test/integration/test_terms.py b/test/integration/test_terms.py index 062c5bb..2ad7ca0 100644 --- a/test/integration/test_terms.py +++ b/test/integration/test_terms.py @@ -1,7 +1,9 @@ import logging +import pytest logger = logging.getLogger(__name__) +@pytest.mark.skip(reason="Can't test this due to persmission issues") def test_get(nc): data = nc.terms.get_all() logger.debug('data = %s', data) @@ -12,6 +14,7 @@ def test_get(nc): logger.debug('data = %s', data) assert data, f'No object with internalId {internal_id}' +@pytest.mark.skip(reason="Can't test this due to persmission issues") def test_post(nc): term = { 'dateDriven': None, diff --git a/test/integration/test_usage.py b/test/integration/test_usage.py new file mode 100644 index 0000000..54abb3c --- /dev/null +++ b/test/integration/test_usage.py @@ -0,0 +1,18 @@ +import os +import json +import logging +import pytest + +logger = logging.getLogger(__name__) + + +@pytest.mark.skip(reason="Can't test this due to persmission issues") +def test_post(nc): + with open('./test/integration/data/usage/data.json') as oj: + s = oj.read() + usage = json.loads(s) + logger.debug('credit_memo = %s', usage) + res = nc.usages.post(usage) + logger.debug('res = %s', res) + assert res['externalId'] == usage['externalId'], 'ID Number does not match' + assert res['type'] == 'creditMemo', 'Type does not match' \ No newline at end of file diff --git a/test/integration/test_vendor_bills.py b/test/integration/test_vendor_bills.py index adc2170..643b216 100644 --- a/test/integration/test_vendor_bills.py +++ b/test/integration/test_vendor_bills.py @@ -6,19 +6,18 @@ logger = logging.getLogger(__name__) def test_get(nc): - data = next(nc.vendor_bills.get_all_generator()) + data = nc.vendor_bills.get_all_generator() logger.debug('data = %s', data) assert data, 'get all generator didnt work' - internal_id = data['internalId'] + internal_id = data[0]['internalId'] data = nc.vendor_bills.get(internalId=internal_id) logger.debug('data = %s', data) assert data, f'No object with internalId {internal_id}' def test_post(nc): - filename = os.getenv('NS_ACCOUNT').lower() + '.json' vb1 = {} - with open('./test/integration/data/vendor_bills/' + filename) as oj: + with open('./test/integration/data/vendor_bills/data.json') as oj: s = oj.read() vb1 = json.loads(s) logger.debug('rvb1 = %s', vb1) diff --git a/test/integration/test_vendor_credit.py b/test/integration/test_vendor_credit.py new file mode 100644 index 0000000..029dfa1 --- /dev/null +++ b/test/integration/test_vendor_credit.py @@ -0,0 +1,17 @@ +import json +import os +import logging +import pytest + +logger = logging.getLogger(__name__) + +@pytest.mark.skip(reason="Can't test this due to persmission issues") +def test_post(nc): + with open('./test/integration/data/vendor_credit/data.json') as oj: + s = oj.read() + vendor_credit = json.loads(s) + logger.debug('vendor_credit = %s', vendor_credit) + res = nc.vendor_credits.post(vendor_credit) + logger.debug('res = %s', res) + assert res['externalId'] == vendor_credit['externalId'], 'Transaction Number does not match' + assert res['type'] == 'vendorCredit', 'Type does not match' diff --git a/test/integration/test_vendor_payments.py b/test/integration/test_vendor_payments.py new file mode 100644 index 0000000..2bef9d5 --- /dev/null +++ b/test/integration/test_vendor_payments.py @@ -0,0 +1,26 @@ +import json +import os +import logging + +logger = logging.getLogger(__name__) + +def test_get(nc): + get_all_respose = nc.vendor_payments.get_all() + get_all_generator_response = [] + for r in nc.vendor_payments.get_all_generator(): + get_all_generator_response.append(r) + len_get_all_generator_response = 0 + for i in get_all_generator_response: + len_get_all_generator_response += len(i) + assert len(get_all_respose) == len_get_all_generator_response, 'changing page size is returning different results' + + +def test_post(nc): + with open('./test/integration/data/vendor_payment/data.json') as oj: + s = oj.read() + vendor_payment = json.loads(s) + logger.debug('vendor_payment = %s', vendor_payment) + res = nc.vendor_payments.post(vendor_payment) + logger.debug('res = %s', res) + assert res['externalId'] == vendor_payment['externalId'], 'Transaction Number does not match' + assert res['type'] == 'vendorPayment', 'Type does not match' diff --git a/test/integration/test_vendors.py b/test/integration/test_vendors.py index bd3a28a..e11589e 100644 --- a/test/integration/test_vendors.py +++ b/test/integration/test_vendors.py @@ -1,5 +1,7 @@ import logging import pytest +import json +import os logger = logging.getLogger(__name__) @@ -14,6 +16,11 @@ def test_get(nc): assert data, f'No object with internalId {internal_id}' def test_post(nc): - data = {} - with pytest.raises(NotImplementedError) as ex: - nc.vendors.post(data) + with open('./test/integration/data/vendor/data.json') as oj: + s = oj.read() + vendor = json.loads(s) + logger.debug('vendor = %s', vendor) + res = nc.vendors.post(vendor) + logger.debug('res = %s', res) + assert res['externalId'] == vendor['externalId'], 'Transaction Number does not match' + assert res['type'] == 'vendor', 'Type does not match' diff --git a/test/internal/conftest.py b/test/internal/conftest.py index 8110647..7f93e56 100644 --- a/test/internal/conftest.py +++ b/test/internal/conftest.py @@ -18,5 +18,5 @@ def ns(): NS_TOKEN_SECRET = os.getenv('NS_TOKEN_SECRET') ns = NetSuiteClient(account=NS_ACCOUNT) ns.connect_tba(consumer_key=NS_CONSUMER_KEY, consumer_secret=NS_CONSUMER_SECRET, - token_key=NS_TOKEN_KEY, token_secret=NS_TOKEN_SECRET, signature_algorithm='HMAC-SHA1') + token_key=NS_TOKEN_KEY, token_secret=NS_TOKEN_SECRET, signature_algorithm='HMAC-SHA256') return ns diff --git a/test/internal/test_count.py b/test/internal/test_count.py new file mode 100644 index 0000000..273ebb6 --- /dev/null +++ b/test/internal/test_count.py @@ -0,0 +1,9 @@ +from netsuitesdk.internal.utils import PaginatedSearch +import logging +import pytest + + +@pytest.mark.parametrize('type_name', ['Account', 'Vendor', 'Department', 'Location', 'Classification', 'Subsidiary', 'Employee']) +def test_count(ns, type_name): + ps = PaginatedSearch(client=ns, type_name=type_name, pageSize=10) + assert ps.total_records > 0, 'Count cannot be 0' \ No newline at end of file diff --git a/test/internal/test_get.py b/test/internal/test_get.py index c8e835c..7bf962b 100644 --- a/test/internal/test_get.py +++ b/test/internal/test_get.py @@ -1,6 +1,7 @@ from netsuitesdk.internal.utils import PaginatedSearch import logging import pytest +from netsuitesdk.internal.exceptions import NetSuiteRequestError logger = logging.getLogger(__name__) @@ -25,6 +26,11 @@ def test_get_expense_report(ns): record = ns.get(recordType='ExpenseReport', externalId='EXPR_1') assert record, 'No expense report found' +def test_get_currency_not_supported(ns): + with pytest.raises(NetSuiteRequestError) as ex: + record = ns.get(recordType='currency', internalId='15') + assert 'An error occured in a get request' in str(ex.value.message) + # def test_get_currency1(nc): # currency = nc.currency.get(internal_id='1') # logger.info('currency is %s', currency) \ No newline at end of file diff --git a/test/internal/test_get_complex_type_element.py b/test/internal/test_get_complex_type_element.py new file mode 100644 index 0000000..3fd7dc5 --- /dev/null +++ b/test/internal/test_get_complex_type_element.py @@ -0,0 +1,20 @@ +import logging +import pytest +import zeep + +logger = logging.getLogger(__name__) + +@pytest.mark.parametrize('type_name', ['RecordList']) +def test_get_complex_type_element(ns, type_name): + type_element = ns.get_complex_type_elements(complex_type = type_name) + assert type_element == [('record', 'Record')] + +@pytest.mark.parametrize('type_name', ['RecordList']) +def test_get_complex_type_info(ns, type_name): + type_info = ns.get_complex_type_info(complex_type = type_name) + assert type_info + +@pytest.mark.parametrize('type_name', ['RecordList']) +def test_get_complex_type_attributes(ns, type_name): + type_attributes = ns.get_complex_type_attributes(complex_type = type_name) + assert type_attributes == [] \ No newline at end of file diff --git a/test/internal/test_login.py b/test/internal/test_login.py index 5fda141..c096ad6 100644 --- a/test/internal/test_login.py +++ b/test/internal/test_login.py @@ -21,4 +21,4 @@ def test_login_disallowed(): ns = NetSuiteClient(account=NS_ACCOUNT) with pytest.raises(NetSuiteLoginError) as ex: ns.login(email=NS_EMAIL, password=NS_PASSWORD, role=NS_ROLE, application_id=NS_APPID) - assert 'Integration blocked' in str(ex.value), 'credentials are allowing login - this is not recommended' + assert 'Two-Factor Authentication required' in str(ex.value.message), 'Two factor authentication required' diff --git a/test/internal/test_logout.py b/test/internal/test_logout.py new file mode 100644 index 0000000..fc414ee --- /dev/null +++ b/test/internal/test_logout.py @@ -0,0 +1,17 @@ +import logging +import os +import time + +import pytest +from netsuitesdk.internal.client import NetSuiteClient +from netsuitesdk.internal.utils import PaginatedSearch + +logger = logging.getLogger(__name__) + +def test_logout(): + """ + Test if logout method is supported. We will not use this often. + """ + NS_ACCOUNT = os.getenv("NS_ACCOUNT") + ns = NetSuiteClient(account=NS_ACCOUNT) + ns.logout() diff --git a/test/internal/test_search.py b/test/internal/test_search.py index e388fe0..132d89d 100644 --- a/test/internal/test_search.py +++ b/test/internal/test_search.py @@ -2,6 +2,7 @@ import logging import pytest import time +from netsuitesdk.internal.exceptions import NetSuiteError logger = logging.getLogger(__name__) @@ -35,8 +36,19 @@ def test_search_expense_reports(ns): assert len(paginated_search.records) > 0, 'There are no expense reports' logger.debug('record = %s', str(paginated_search.records[0])) +def test_search_expense_reports_not_supported(ns): + record_type_search_field = ns.SearchStringField(searchValue='ExpenseReport', operator='contains') + with pytest.raises(NetSuiteError) as ex: + basic_search = ns.basic_search_factory('Transaction1', recordType=record_type_search_field) + assert "Transaction1 is not a searchable NetSuite type" in str(ex.value.message) + @pytest.mark.parametrize('type_name', ['Account', 'Vendor', 'Department', 'Location', 'Classification', 'Subsidiary', 'Employee']) def test_search_all(ns, type_name): paginated_search = PaginatedSearch(client=ns, type_name=type_name, pageSize=20) assert len(paginated_search.records) > 0, f'There are no records of type {type_name}' logger.debug('record = %s', str(paginated_search.records[0])) + +def test_basic_stringfield_search(ns): + with pytest.raises(AttributeError) as ex: + search_entity = ns.basic_stringfield_search("entityId","Amazon","contains") + assert "'NetSuiteClient' object has no attribute 'entityIdSearchBasic'" in str(ex.value)