Skip to content

Commit

Permalink
Add test for product reports(BE-327)
Browse files Browse the repository at this point in the history
  • Loading branch information
xqliu committed Jun 29, 2017
1 parent 47b2015 commit 89af819
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
15 changes: 8 additions & 7 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ engines:
ratings:
paths:
- "**.py"
- "psi/app/static/js/*.js"

exclude_paths:
- psi/migrations
- psi/app/static/ckeditor
- psi/app/static/chart.js
- psi/app/static/Font-Awesome-4.6.3
- psi/app/static/bootbox
- psi/app/static/lightbox2
- tests
- "psi/migrations/"
- "psi/static/ckeditor/"
- "psi/static/chart.js/"
- "psi/static/Font-Awesome-4.6.3/"
- "psi/static/bootbox/"
- "psi/static/lightbox2/"
- "tests/"
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ install:
- mv setup.cfg.template setup.cfg
- mkdir -p app/static/uploaded
script:
- python manage.py test
# - python manage.py test
- nosetests tests --with-coverage --cover-erase --cover-branches --with-xunit --xunit-file=nosetests.xml
after_success:
- export CODECLIMATE_REPO_TOKEN=b66ce794c42bc566d01713825caa2dfd117ba2b8e67e17dcb64ebb85dd2655ba
- codeclimate-test-reporter
Expand Down
6 changes: 0 additions & 6 deletions psi/app/views/sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ class SalesOrderAdmin(ModelViewWithAccess, ModelWithLineFormatter):
}

def create_form(self, obj=None):
from psi.app.models import Customer

form = super(SalesOrderAdmin, self).create_form(obj)
self.hide_line_derive_fields_on_create_form(form)
form_util.filter_by_organization(form.customer, Customer)
Expand All @@ -211,8 +209,6 @@ def hide_line_derive_fields_on_create_form(self, form):
form.lines.form.retail_price = None

def edit_form(self, obj=None):
from psi.app.models import Customer

form = super(SalesOrderAdmin, self).edit_form(obj)
form_util.filter_by_organization(form.customer, Customer)
self.filter_product_by_organization(form)
Expand All @@ -221,8 +217,6 @@ def edit_form(self, obj=None):
@staticmethod
def filter_product_by_organization(form):
# Set query factory for new created line
from psi.app.models import Product

# TODO.xqliu Fix this for AJAX lookup
# If we uncomment follow line to limit the query to current organization
# The AJAX look up fails.
Expand Down
1 change: 0 additions & 1 deletion psi/migrations/versions/40_e1f806a716b9_.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from alembic import op
import sqlalchemy as sa
from datetime import datetime
from sqlalchemy import func
from sqlalchemy.sql import text
from datetime import datetime
Expand Down
32 changes: 32 additions & 0 deletions tests/views/product_sales_report_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import random

from flask import url_for
from six import iteritems

from tests import fixture
from psi.app import const
from psi.app.utils import db_util, calc_inline_field_name
from tests.base_test_case import BaseTestCase
from tests.object_faker import object_faker as of


class TestSupplierSalesReportPage(BaseTestCase):

def test_all_page_rendered(self):
user, password = of.user(
role_names=['sales_report_view', ]
)
db_util.save_objects_commit(user)
fixture.login_user(self.test_client, user.email, password)
self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='overall'))
self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='today'))
self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='yesterday'))
self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='this_week'))
self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='last_week'))
self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='this_month'))
self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='last_month'))
self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='this_quarter'))
self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='last_quarter'))
self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='this_year'))
self.assertPageRendered(endpoint=url_for('supplier_sales_report.index_view', type='last_year'))
fixture.logout_user(self.test_client)

0 comments on commit 89af819

Please sign in to comment.