def create(self, request, *args, **kwargs): if request.data is None: return rc.BAD_REQUEST if not self.check_create_permission(request, "x"): return rc.FORBIDDEN currency = Currency() form = CurrencyForm( request.user.profile, request.data, instance=currency) if form.is_valid(): currency = form.save(commit=False) cname = dict_currencies[currency.code] currency.name = cname[cname.index(' ') + 2:] # currency.factor = 1.0 #Get currency conversion here currency.save() currency.set_user_from_request(request) return currency else: self.status = 400 return form.errors
def create(self, request, *args, **kwargs): if request.data is None: return rc.BAD_REQUEST if not self.check_create_permission(request, "x"): return rc.FORBIDDEN currency = Currency() form = CurrencyForm(request.user.profile, request.data, instance=currency) if form.is_valid(): currency = form.save(commit=False) cname = dict_currencies[currency.code] currency.name = cname[cname.index(' ') + 2:] # currency.factor = 1.0 #Get currency conversion here currency.save() currency.set_user_from_request(request) return currency else: self.status = 400 return form.errors
class SalesAPITest(TestCase): username = "******" password = "******" authentication_headers = { "CONTENT_TYPE": "application/json", "HTTP_AUTHORIZATION": "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk" } content_type = 'application/json' def setUp(self): self.group, created = Group.objects.get_or_create(name='test') self.user, created = DjangoUser.objects.get_or_create( username=self.username) self.user.set_password(self.password) self.user.save() self.perspective = Perspective(name='test') self.perspective.set_default_user() self.perspective.save() ModuleSetting.set('default_perspective', self.perspective.id) self.contact_type = ContactType() self.contact_type.slug = 'machine' self.contact_type.name = 'machine' self.contact_type.save() self.contact = Contact() self.contact.contact_type = self.contact_type self.contact.set_default_user() self.contact.save() self.assertNotEquals(self.contact.id, None) self.status = SaleStatus() self.status.active = True self.status.use_sales = True self.status.use_leads = True self.status.use_opportunities = True self.status.set_default_user() self.status.save() self.assertNotEquals(self.status.id, None) self.currency = Currency(code="GBP", name="Pounds", symbol="L", is_default=True) self.currency.save() self.source = SaleSource() self.source.active = True self.source.save() self.source.set_user(self.user.profile) self.assertNotEquals(self.source.id, None) self.product = Product(name="Test") self.product.product_type = 'service' self.product.active = True self.product.sell_price = 10 self.product.buy_price = 100 self.product.set_default_user() self.product.save() self.assertNotEquals(self.product.id, None) self.subscription = Subscription() self.subscription.client = self.contact self.subscription.set_default_user() self.subscription.save() self.assertNotEquals(self.subscription.id, None) self.lead = Lead() self.lead.contact_method = 'email' self.lead.status = self.status self.lead.contact = self.contact self.lead.set_default_user() self.lead.save() self.assertNotEquals(self.lead.id, None) self.opportunity = Opportunity() self.opportunity.lead = self.lead self.opportunity.contact = self.contact self.opportunity.status = self.status self.opportunity.amount = 100 self.opportunity.amount_currency = self.currency self.opportunity.amount_display = 120 self.opportunity.set_default_user() self.opportunity.save() self.assertNotEquals(self.opportunity.id, None) self.order = SaleOrder(reference="Test") self.order.opportunity = self.opportunity self.order.status = self.status self.order.source = self.source self.order.currency = self.currency self.order.total = 0 self.order.total_display = 0 self.order.set_default_user() self.order.save() self.assertNotEquals(self.order.id, None) self.ordered_product = OrderedProduct() self.ordered_product.product = self.product self.ordered_product.order = self.order self.ordered_product.rate = 0 self.ordered_product.subscription = self.subscription self.ordered_product.set_default_user() self.ordered_product.save() self.assertNotEquals(self.ordered_product.id, None) def test_unauthenticated_access(self): """Test index page at /sales/statuses""" response = self.client.get('/api/sales/statuses') # Redirects as unauthenticated self.assertEquals(response.status_code, 401) def test_get_statuses_list(self): """ Test index page api/sales/status """ response = self.client.get(path=reverse('api_sales_status'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_status(self): response = self.client.get(path=reverse( 'api_sales_status', kwargs={'object_ptr': self.status.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_status(self): updates = { "name": "Close_API", "active": True, "details": "api test details", "use_leads": True, "use_opportunities": True, "hidden": False } response = self.client.put(path=reverse( 'api_sales_status', kwargs={'object_ptr': self.status.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['active'], updates['active']) self.assertEquals(data['details'], updates['details']) self.assertEquals(data['use_leads'], updates['use_leads']) self.assertEquals(data['use_opportunities'], updates['use_opportunities']) self.assertEquals(data['hidden'], updates['hidden']) def test_get_products_list(self): """ Test index page api/sales/products """ response = self.client.get(path=reverse('api_sales_products'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_product(self): response = self.client.get(path=reverse( 'api_sales_products', kwargs={'object_ptr': self.product.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_product(self): updates = { "name": "API product", "parent": None, "product_type": "service", "code": "api_test_code", "buy_price": '100.05', "sell_price": '10.5', "active": True, "runout_action": "ignore", "details": "api details" } response = self.client.put(path=reverse( 'api_sales_products', kwargs={'object_ptr': self.product.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['product_type'], updates['product_type']) self.assertEquals(data['code'], updates['code']) self.assertEquals(data['buy_price'], updates['buy_price']) self.assertEquals(data['sell_price'], updates['sell_price']) self.assertEquals(data['active'], updates['active']) self.assertEquals(data['runout_action'], updates['runout_action']) self.assertEquals(data['details'], updates['details']) def test_get_sources_list(self): """ Test index page api/sales/sources """ response = self.client.get(path=reverse('api_sales_sources'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_source(self): response = self.client.get(path=reverse( 'api_sales_sources', kwargs={'object_ptr': self.source.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_source(self): updates = { "name": "Api source", "active": True, "details": "api details" } response = self.client.put(path=reverse( 'api_sales_sources', kwargs={'object_ptr': self.source.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['active'], updates['active']) self.assertEquals(data['details'], updates['details']) # def test_get_leads_list(self): """ Test index page api/sales/leads """ response = self.client.get(path=reverse('api_sales_leads'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_lead(self): response = self.client.get(path=reverse( 'api_sales_leads', kwargs={'object_ptr': self.lead.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_lead(self): updates = { "status": self.status.id, "contact_method": "email", "contact": self.contact.id, "products_interested": [self.product.id], "source": self.source.id, 'details': 'Api details' } response = self.client.put(path=reverse( 'api_sales_leads', kwargs={'object_ptr': self.lead.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['status']['id'], updates['status']) self.assertEquals(data['contact_method'], updates['contact_method']) self.assertEquals(data['contact']['id'], updates['contact']) for i, product in enumerate(data['products_interested']): self.assertEquals(product['id'], updates['products_interested'][i]) self.assertEquals(data['source']['id'], updates['source']) self.assertEquals(data['details'], updates['details']) def test_get_opportunities_list(self): """ Test index page api/sales/opportunities """ response = self.client.get(path=reverse('api_sales_opportunities'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_opportunity(self): response = self.client.get(path=reverse( 'api_sales_opportunities', kwargs={'object_ptr': self.opportunity.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_opportunity(self): updates = { "status": self.status.id, "products_interested": [self.product.id], "contact": self.contact.id, "amount_display": 3000.56, "amount_currency": self.currency.id, "details": "API DETAILS" } response = self.client.put(path=reverse( 'api_sales_opportunities', kwargs={'object_ptr': self.opportunity.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['status']['id'], updates['status']) self.assertEquals(data['contact']['id'], updates['contact']) for i, product in enumerate(data['products_interested']): self.assertEquals(product['id'], updates['products_interested'][i]) self.assertEquals(data['amount_currency']['id'], updates['amount_currency']) self.assertEquals(data['details'], updates['details']) def test_get_orders_list(self): """ Test index page api/sales/orders """ response = self.client.get(path=reverse('api_sales_orders'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_order(self): response = self.client.get(path=reverse( 'api_sales_orders', kwargs={'object_ptr': self.order.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_order(self): updates = { "datetime": "2011-04-11 12:01:15", "status": self.status.id, "source": self.source.id, "details": "api details" } response = self.client.put(path=reverse( 'api_sales_orders', kwargs={'object_ptr': self.order.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['status']['id'], updates['status']) self.assertEquals(data['source']['id'], updates['source']) self.assertEquals(data['details'], updates['details']) def test_get_subscriptions_list(self): """ Test index page api/sales/subscriptions""" response = self.client.get(path=reverse('api_sales_subscriptions'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_subscription(self): response = self.client.get(path=reverse( 'api_sales_subscriptions', kwargs={'object_ptr': self.subscription.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_subscription(self): updates = { "product": self.product.id, "start": "2011-06-30", "cycle_period": "daily", "active": True, "details": "api details" } response = self.client.put(path=reverse( 'api_sales_subscriptions', kwargs={'object_ptr': self.subscription.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['product']['id'], updates['product']) self.assertEquals(data['cycle_period'], updates['cycle_period']) self.assertEquals(data['active'], updates['active']) self.assertEquals(data['details'], updates['details']) def test_get_ordered_product(self): response = self.client.get(path=reverse( 'api_sales_ordered_products', kwargs={'object_ptr': self.ordered_product.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_ordered_product(self): updates = { "discount": '10.0', "product": self.product.id, "quantity": '10' } response = self.client.put(path=reverse( 'api_sales_ordered_products', kwargs={'object_ptr': self.ordered_product.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['product']['id'], updates['product']) self.assertEquals(data['discount'], updates['discount']) self.assertEquals(data['quantity'], updates['quantity'])
class FinanceAPITest(TestCase): """Finance api tests""" username = "******" password = "******" authentication_headers = { "CONTENT_TYPE": "application/json", "HTTP_AUTHORIZATION": "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk" } content_type = 'application/json' def setUp(self): self.group, created = Group.objects.get_or_create(name='test') self.user, created = DjangoUser.objects.get_or_create( username=self.username) self.user.set_password(self.password) self.user.save() self.perspective = Perspective(name='test') self.perspective.set_default_user() self.perspective.save() ModuleSetting.set('default_perspective', self.perspective.id) self.contact_type = ContactType(name='test') self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name='test', contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.category = Category(name='test') self.category.set_default_user() self.category.save() self.equity = Equity(issue_price=10, sell_price=10, issuer=self.contact, owner=self.contact) self.equity.set_default_user() self.equity.save() self.asset = Asset(name='test', owner=self.contact) self.asset.set_default_user() self.asset.save() self.tax = Tax(name='test', rate=10) self.tax.set_default_user() self.tax.save() self.currency = Currency(code="GBP", name="Pounds", symbol="L", is_default=True) self.currency.set_default_user() self.currency.save() self.account = Account(name='test', owner=self.contact, balance_currency=self.currency) self.account.set_default_user() self.account.save() self.liability = Liability(name='test', source=self.contact, target=self.contact, account=self.account, value=10, value_currency=self.currency) self.liability.set_default_user() self.liability.save() self.transaction = Transaction(name='test', account=self.account, source=self.contact, target=self.contact, value=10, value_currency=self.currency) self.transaction.set_default_user() self.transaction.save() def test_unauthenticated_access(self): """Test index page at /api/finance/currencies""" response = self.client.get('/api/finance/currencies') # Redirects as unauthenticated self.assertEquals(response.status_code, 401) def test_get_currencies_list(self): """ Test index page api/finance/currencies """ response = self.client.get(path=reverse('api_finance_currencies'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_currency(self): response = self.client.get(path=reverse( 'api_finance_currencies', kwargs={'object_ptr': self.currency.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_currency(self): updates = { "code": "RUB", "name": "api RUB", "factor": "10.00", "is_active": True } response = self.client.put(path=reverse( 'api_finance_currencies', kwargs={'object_ptr': self.currency.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['code'], updates['code']) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['factor'], updates['factor']) self.assertEquals(data['is_active'], updates['is_active']) def test_get_taxes_list(self): """ Test index page api/finance/taxes """ response = self.client.get(path=reverse('api_finance_taxes'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_tax(self): response = self.client.get(path=reverse( 'api_finance_taxes', kwargs={'object_ptr': self.tax.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_tax(self): updates = {"name": "API TEST TAX", "rate": "20.00", "compound": False} response = self.client.put(path=reverse( 'api_finance_taxes', kwargs={'object_ptr': self.tax.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['rate'], updates['rate']) self.assertEquals(data['compound'], updates['compound']) def test_get_categories_list(self): """ Test index page api/finance/categories """ response = self.client.get(path=reverse('api_finance_categories'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_category(self): response = self.client.get(path=reverse( 'api_finance_categories', kwargs={'object_ptr': self.category.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_category(self): updates = {"name": "Api category", "details": "api details"} response = self.client.put(path=reverse( 'api_finance_categories', kwargs={'object_ptr': self.category.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['details'], updates['details']) def test_get_assets_list(self): """ Test index page api/finance/assets """ response = self.client.get(path=reverse('api_finance_assets'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_asset(self): response = self.client.get(path=reverse( 'api_finance_assets', kwargs={'object_ptr': self.asset.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_asset(self): updates = { "current_value": "20.0", "owner": self.contact.id, "asset_type": "fixed", "name": "Api name", "initial_value": '40.0' } response = self.client.put(path=reverse( 'api_finance_assets', kwargs={'object_ptr': self.asset.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['owner']['id'], updates['owner']) self.assertEquals(data['asset_type'], updates['asset_type']) self.assertEquals(data['initial_value'], updates['initial_value']) self.assertEquals(data['current_value'], updates['current_value']) def test_get_accounts_list(self): """ Test index page api/finance/accounts """ response = self.client.get(path=reverse('api_finance_accounts'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_account(self): response = self.client.get(path=reverse( 'api_finance_accounts', kwargs={'object_ptr': self.account.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_account(self): updates = { "owner": self.contact.id, "balance_display": '40.0', "name": "api test name", "balance_currency": self.currency.id } response = self.client.put(path=reverse( 'api_finance_accounts', kwargs={'object_ptr': self.account.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['owner']['id'], updates['owner']) self.assertEquals(data['balance_display'], updates['balance_display']) self.assertEquals(data['balance_currency']['id'], updates['balance_currency']) def test_get_equities_list(self): """ Test index page api/finance/equities""" response = self.client.get(path=reverse('api_finance_equities'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_equity(self): response = self.client.get(path=reverse( 'api_finance_equities', kwargs={'object_ptr': self.equity.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_account_2(self): updates = { "issue_price": "100.0", "equity_type": "warrant", "sell_price": "50.0", "amount": 100, "purchase_date": "2011-06-06", "owner": self.contact.id, "issuer": self.contact.id } response = self.client.put(path=reverse( 'api_finance_equities', kwargs={'object_ptr': self.equity.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['issue_price'], updates['issue_price']) self.assertEquals(data['equity_type'], updates['equity_type']) self.assertEquals(data['sell_price'], updates['sell_price']) self.assertEquals(data['amount'], updates['amount']) self.assertEquals(data['purchase_date'], updates['purchase_date']) self.assertEquals(data['owner']['id'], updates['owner']) self.assertEquals(data['issuer']['id'], updates['issuer']) self.assertEquals(data['issuer']['id'], updates['issuer']) def test_get_liabilities_list(self): """ Test index page api/finance/liabilities""" response = self.client.get(path=reverse('api_finance_liabilities'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_liability(self): response = self.client.get(path=reverse( 'api_finance_liabilities', kwargs={'object_ptr': self.liability.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_liability(self): updates = { "account": self.account.id, "target": self.contact.id, "value_display": "20.0", "name": "api test name", "value_currency": self.currency.id } response = self.client.put(path=reverse( 'api_finance_liabilities', kwargs={'object_ptr': self.liability.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['target']['id'], updates['target']) self.assertEquals(data['account']['id'], updates['account']) self.assertEquals(data['value_display'], updates['value_display']) self.assertEquals(data['value_currency']['id'], updates['value_currency']) def test_get_transactions_list(self): """ Test index page api/finance/transactions""" response = self.client.get(path=reverse('api_finance_transactions'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_transaction(self): response = self.client.get(path=reverse( 'api_finance_transactions', kwargs={'object_ptr': self.transaction.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_transaction(self): updates = { "value_display": "1000.0", "account": self.account.id, "name": "api test name", "value_currency": self.currency.id, "datetime": "2011-03-21 11:04:42", "target": self.contact.id, "source": self.contact.id } response = self.client.put(path=reverse( 'api_finance_transactions', kwargs={'object_ptr': self.transaction.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['value_display'], updates['value_display']) self.assertEquals(data['account']['id'], updates['account']) self.assertEquals(data['value_currency']['id'], updates['value_currency']) self.assertEquals(data['datetime'].replace("T", " "), updates['datetime']) self.assertEquals(data['target']['id'], updates['target']) self.assertEquals(data['account']['id'], updates['account']) self.assertEquals(data['source']['id'], updates['source'])
class SalesViewsTest(TestCase): username = "******" password = "******" def setUp(self): self.group, created = Group.objects.get_or_create(name='test') self.user, created = DjangoUser.objects.get_or_create(username=self.username) self.user.set_password(self.password) self.user.save() perspective, created = Perspective.objects.get_or_create(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.contact_type = ContactType() self.contact_type.slug = 'machine' self.contact_type.name = 'machine' self.contact_type.save() self.contact = Contact() self.contact.contact_type = self.contact_type self.contact.set_default_user() self.contact.save() self.assertNotEquals(self.contact.id, None) self.status = SaleStatus() self.status.set_default_user() self.status.save() self.assertNotEquals(self.status.id, None) self.currency = Currency(code="GBP", name="Pounds", symbol="L", is_default=True) self.currency.save() self.source = SaleSource() self.source.set_default_user() self.source.save() self.assertNotEquals(self.source.id, None) self.product = Product(name="Test") self.product.product_type = 'service' self.product.active = True self.product.sell_price = 10 self.product.buy_price = 100 self.product.set_default_user() self.product.save() self.assertNotEquals(self.product.id, None) self.subscription = Subscription() self.subscription.client = self.contact self.subscription.set_default_user() self.subscription.save() self.assertNotEquals(self.subscription.id, None) self.lead = Lead() self.lead.contact_method = 'email' self.lead.status = self.status self.lead.contact = self.contact self.lead.set_default_user() self.lead.save() self.assertNotEquals(self.lead.id, None) self.opportunity = Opportunity() self.opportunity.lead = self.lead self.opportunity.contact = self.contact self.opportunity.status = self.status self.opportunity.amount = 100 self.opportunity.amount_currency = self.currency self.opportunity.amount_display = 120 self.opportunity.set_default_user() self.opportunity.save() self.assertNotEquals(self.opportunity.id, None) self.order = SaleOrder(reference="Test") self.order.opportunity = self.opportunity self.order.status = self.status self.order.source = self.source self.order.currency = self.currency self.order.total = 0 self.order.total_display = 0 self.order.set_default_user() self.order.save() self.assertNotEquals(self.order.id, None) self.ordered_product = OrderedProduct() self.ordered_product.product = self.product self.ordered_product.order = self.order self.ordered_product.rate = 0 self.ordered_product.subscription = self.subscription self.ordered_product.set_default_user() self.ordered_product.save() self.assertNotEquals(self.ordered_product.id, None) ###################################### # Testing views when user is logged in ###################################### def test_index(self): "Test page with login at /sales/index" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_index')) self.assertEquals(response.status_code, 200) def test_index_open(self): "Test page with login at /sales/open" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_index_open')) self.assertEquals(response.status_code, 200) def test_index_assigned(self): "Test page with login at /sales/index/assigned" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_index_assigned')) self.assertEquals(response.status_code, 200) # Orders def test_order_add(self): "Test page with login at /sales/order/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_order_add')) self.assertEquals(response.status_code, 200) def test_order_add_lead(self): "Test page with login at /sales/order/add/lead/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_order_add_with_lead', args=[self.lead.id])) self.assertEquals(response.status_code, 200) def test_order_add_opportunity(self): "Test page with login at /sales/order/add/opportunity/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_order_add_with_opportunity', args=[self.opportunity.id])) self.assertEquals(response.status_code, 200) def test_order_edit(self): "Test page with login at /sales/order/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_order_edit', args=[self.order.id])) self.assertEquals(response.status_code, 200) def test_order_view(self): "Test page with login at /sales/order/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_order_view', args=[self.order.id])) self.assertEquals(response.status_code, 200) def test_order_delete(self): "Test page with login at /sales/order/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_order_delete', args=[self.order.id])) self.assertEquals(response.status_code, 200) def test_order_invoice_view(self): "Test page with login at /sales/order/invoice/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_order_invoice_view', args=[self.order.id])) self.assertEquals(response.status_code, 200) # Products def test_product_index(self): "Test page with login at /sales/product/index" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_product_index')) self.assertEquals(response.status_code, 200) def test_product_add(self): "Test page with login at /sales/product/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_product_add')) self.assertEquals(response.status_code, 200) def test_product_add_parent(self): "Test page with login at /sales/product/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_product_add', args=[self.product.id])) self.assertEquals(response.status_code, 200) def test_product_edit(self): "Test page with login at /sales/product/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_product_edit', args=[self.product.id])) self.assertEquals(response.status_code, 200) def test_product_view(self): "Test page with login at /sales/product/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_product_view', args=[self.product.id])) self.assertEquals(response.status_code, 200) def test_product_delete(self): "Test page with login at /sales/product/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_product_delete', args=[self.product.id])) self.assertEquals(response.status_code, 200) # Settings def test_settings_view(self): "Test page with login at /sales/settings/view" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_settings_view')) self.assertEquals(response.status_code, 200) def test_settings_edit(self): "Test page with login at /sales/settings/edit" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_settings_edit')) self.assertEquals(response.status_code, 200) # Statuses def test_status_add(self): "Test page with login at /sales/status/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_status_add')) self.assertEquals(response.status_code, 200) def test_status_edit(self): "Test page with login at /sales/status/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_status_edit', args=[self.status.id])) self.assertEquals(response.status_code, 200) def test_status_view(self): "Test page with login at /sales/status/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_status_view', args=[self.status.id])) self.assertEquals(response.status_code, 200) def test_status_delete(self): "Test page with login at /sales/status/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_status_delete', args=[self.status.id])) self.assertEquals(response.status_code, 200) # Subscriptions def test_subscription_add(self): "Test page with login at /sales/subscription/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_subscription_add')) self.assertEquals(response.status_code, 200) def test_subscription_add_product(self): "Test page with login at /sales/subscription/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_subscription_add_with_product', args=[self.product.id])) self.assertEquals(response.status_code, 200) def test_subscription_edit(self): "Test page with login at /sales/subscription/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_subscription_edit', args=[self.subscription.id])) self.assertEquals(response.status_code, 200) def test_subscription_view(self): "Test page with login at /sales/subscription/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_subscription_view', args=[self.subscription.id])) self.assertEquals(response.status_code, 200) def test_subscription_delete(self): "Test page with login at /sales/subscription/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_subscription_delete', args=[self.subscription.id])) self.assertEquals(response.status_code, 200) # Ordered Products def test_ordered_product_add(self): "Test page with login at /sales/ordered_product/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_ordered_product_add', args=[self.order.id])) self.assertEquals(response.status_code, 200) def test_ordered_product_edit(self): "Test page with login at /sales/ordered_product/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_ordered_product_edit', args=[self.ordered_product.id])) self.assertEquals(response.status_code, 200) def test_ordered_product_view(self): "Test page with login at /sales/ordered_product/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_ordered_product_view', args=[self.ordered_product.id])) self.assertEquals(response.status_code, 200) def test_ordered_product_delete(self): "Test page with login at /sales/ordered_product/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_ordered_product_delete', args=[self.ordered_product.id])) self.assertEquals(response.status_code, 200) # Sources def test_source_add(self): "Test page with login at /sales/source/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_source_add')) self.assertEquals(response.status_code, 200) def test_source_edit(self): "Test page with login at /sales/source/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_source_edit', args=[self.source.id])) self.assertEquals(response.status_code, 200) def test_source_view(self): "Test page with login at /sales/source/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_source_view', args=[self.source.id])) self.assertEquals(response.status_code, 200) def test_source_delete(self): "Test page with login at /sales/source/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_source_delete', args=[self.source.id])) self.assertEquals(response.status_code, 200) # Leads def test_lead_index(self): "Test page with login at /sales/lead/index" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_lead_index')) self.assertEquals(response.status_code, 200) def test_lead_index_assigned(self): "Test page with login at /sales/lead/index/assigned" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_lead_index_assigned')) self.assertEquals(response.status_code, 200) def test_lead_add(self): "Test page with login at /sales/lead/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_lead_add')) self.assertEquals(response.status_code, 200) def test_lead_edit(self): "Test page with login at /sales/lead/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_lead_edit', args=[self.lead.id])) self.assertEquals(response.status_code, 200) def test_lead_view(self): "Test page with login at /sales/lead/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_lead_view', args=[self.lead.id])) self.assertEquals(response.status_code, 200) def test_lead_delete(self): "Test page with login at /sales/lead/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_lead_delete', args=[self.lead.id])) self.assertEquals(response.status_code, 200) # Opportunities def test_opportunity_index(self): "Test page with login at /sales/opportunity/index" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_opportunity_index')) self.assertEquals(response.status_code, 200) def test_opportunity_index_assigned(self): "Test page with login at /sales/opportunity/index/assigned" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_opportunity_index_assigned')) self.assertEquals(response.status_code, 200) def test_opportunity_add(self): "Test page with login at /sales/opportunity/add" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('sales_opportunity_add')) self.assertEquals(response.status_code, 200) def test_opportunity_add_lead(self): "Test page with login at /sales/opportunity/add/lead/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_opportunity_add_with_lead', args=[self.lead.id])) self.assertEquals(response.status_code, 200) def test_opportunity_edit(self): "Test page with login at /sales/opportunity/edit/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_opportunity_edit', args=[self.opportunity.id])) self.assertEquals(response.status_code, 200) def test_opportunity_view(self): "Test page with login at /sales/opportunity/view/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_opportunity_view', args=[self.opportunity.id])) self.assertEquals(response.status_code, 200) def test_opportunity_delete(self): "Test page with login at /sales/opportunity/delete/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('sales_opportunity_delete', args=[self.opportunity.id])) self.assertEquals(response.status_code, 200) ###################################### # Testing views when user is not logged in ###################################### def test_index_anonymous(self): "Test index page at /sales/" response = self.client.get('/sales/') # Redirects as unauthenticated self.assertRedirects(response, reverse('user_login')) def test_index_open_out(self): "Testing /sales/open" response = self.client.get(reverse('sales_index_open')) self.assertRedirects(response, reverse('user_login')) def test_index_assigned_out(self): "Testing /sales/index/assigned" response = self.client.get(reverse('sales_index_assigned')) self.assertRedirects(response, reverse('user_login')) # Orders def test_order_add_out(self): "Testing /sales/order/add" response = self.client.get(reverse('sales_order_add')) self.assertRedirects(response, reverse('user_login')) def test_order_add_lead_out(self): "Testing /sales/order/add/lead/" response = self.client.get( reverse('sales_order_add_with_lead', args=[self.lead.id])) self.assertRedirects(response, reverse('user_login')) def test_order_add_opportunity_out(self): "Testing /sales/order/add/opportunity/" response = self.client.get( reverse('sales_order_add_with_opportunity', args=[self.opportunity.id])) self.assertRedirects(response, reverse('user_login')) def test_order_edit_out(self): "Testing /sales/order/edit/" response = self.client.get( reverse('sales_order_edit', args=[self.order.id])) self.assertRedirects(response, reverse('user_login')) def test_order_view_out(self): "Testing /sales/order/view/" response = self.client.get( reverse('sales_order_view', args=[self.order.id])) self.assertRedirects(response, reverse('user_login')) def test_order_delete_out(self): "Testing /sales/order/delete/" response = self.client.get( reverse('sales_order_delete', args=[self.order.id])) self.assertRedirects(response, reverse('user_login')) def test_order_invoice_view_out(self): "Testing /sales/order/invoice/" response = self.client.get( reverse('sales_order_invoice_view', args=[self.order.id])) self.assertRedirects(response, reverse('user_login')) # Products def test_product_index_out(self): "Testing /sales/product/index" response = self.client.get(reverse('sales_product_index')) self.assertRedirects(response, reverse('user_login')) def test_product_add_out(self): "Testing /sales/product/add/" response = self.client.get(reverse('sales_product_add')) self.assertRedirects(response, reverse('user_login')) def test_product_add_parent_out(self): "Testing /sales/product/add" response = self.client.get( reverse('sales_product_add', args=[self.product.id])) self.assertRedirects(response, reverse('user_login')) def test_product_edit_out(self): "Testing /sales/product/edit/" response = self.client.get( reverse('sales_product_edit', args=[self.product.id])) self.assertRedirects(response, reverse('user_login')) def test_product_view_out(self): "Testing /sales/product/view/" response = self.client.get( reverse('sales_product_view', args=[self.product.id])) self.assertRedirects(response, reverse('user_login')) def test_product_delete_out(self): "Testing /sales/product/delete/" response = self.client.get( reverse('sales_product_delete', args=[self.product.id])) self.assertRedirects(response, reverse('user_login')) # Settings def test_settings_view_out(self): "Testing /sales/settings/view" response = self.client.get(reverse('sales_settings_view')) self.assertRedirects(response, reverse('user_login')) def test_settings_edit_out(self): "Testing /sales/settings/edit" response = self.client.get(reverse('sales_settings_edit')) self.assertRedirects(response, reverse('user_login')) # Statuses def test_status_add_out(self): "Testing /sales/status/add" response = self.client.get(reverse('sales_status_add')) self.assertRedirects(response, reverse('user_login')) def test_status_edit_out(self): "Testing /sales/status/edit/" response = self.client.get( reverse('sales_status_edit', args=[self.status.id])) self.assertRedirects(response, reverse('user_login')) def test_status_view_out(self): "Testing /sales/status/view/" response = self.client.get( reverse('sales_status_view', args=[self.status.id])) self.assertRedirects(response, reverse('user_login')) def test_status_delete_out(self): "Testing /sales/status/delete/" response = self.client.get( reverse('sales_status_delete', args=[self.status.id])) self.assertRedirects(response, reverse('user_login')) # Subscriptions def test_subscription_add_out(self): "Testing /sales/subscription/add" response = self.client.get(reverse('sales_subscription_add')) self.assertRedirects(response, reverse('user_login')) def test_subscription_add_product_out(self): "Testing /sales/subscription/add/" response = self.client.get( reverse('sales_subscription_add_with_product', args=[self.product.id])) self.assertRedirects(response, reverse('user_login')) def test_subscription_edit_out(self): "Testing /sales/subscription/edit/" response = self.client.get( reverse('sales_subscription_edit', args=[self.subscription.id])) self.assertRedirects(response, reverse('user_login')) def test_subscription_view_out(self): "Testing /sales/subscription/view/" response = self.client.get( reverse('sales_subscription_view', args=[self.subscription.id])) self.assertRedirects(response, reverse('user_login')) def test_subscription_delete_out(self): "Testing /sales/subscription/delete/" response = self.client.get( reverse('sales_subscription_delete', args=[self.subscription.id])) self.assertRedirects(response, reverse('user_login')) # Ordered Products def test_ordered_product_add_out(self): "Testing /sales/ordered_product/add/" response = self.client.get( reverse('sales_ordered_product_add', args=[self.order.id])) self.assertRedirects(response, reverse('user_login')) def test_ordered_product_edit_out(self): "Testing /sales/ordered_product/edit/" response = self.client.get( reverse('sales_ordered_product_edit', args=[self.ordered_product.id])) self.assertRedirects(response, reverse('user_login')) def test_ordered_product_view_out(self): "Testing /sales/ordered_product/view/" response = self.client.get( reverse('sales_ordered_product_view', args=[self.ordered_product.id])) self.assertRedirects(response, reverse('user_login')) def test_ordered_product_delete_out(self): "Testing /sales/ordered_product/delete/" response = self.client.get( reverse('sales_ordered_product_delete', args=[self.ordered_product.id])) self.assertRedirects(response, reverse('user_login')) # Sources def test_source_add_out(self): "Testing /sales/source/add" response = self.client.get(reverse('sales_source_add')) self.assertRedirects(response, reverse('user_login')) def test_source_edit_out(self): "Testing /sales/source/edit/" response = self.client.get( reverse('sales_source_edit', args=[self.source.id])) self.assertRedirects(response, reverse('user_login')) def test_source_view_out(self): "Testing /sales/source/view/" response = self.client.get( reverse('sales_source_view', args=[self.source.id])) self.assertRedirects(response, reverse('user_login')) def test_source_delete_out(self): "Testing /sales/source/delete/" response = self.client.get( reverse('sales_source_delete', args=[self.source.id])) self.assertRedirects(response, reverse('user_login')) # Leads def test_lead_index_out(self): "Testing /sales/lead/index" response = self.client.get(reverse('sales_lead_index')) self.assertRedirects(response, reverse('user_login')) def test_lead_index_assigned_out(self): "Testing /sales/lead/index/assigned" response = self.client.get(reverse('sales_lead_index_assigned')) self.assertRedirects(response, reverse('user_login')) def test_lead_add_out(self): "Testing /sales/lead/add" response = self.client.get(reverse('sales_lead_add')) self.assertRedirects(response, reverse('user_login')) def test_lead_edit_out(self): "Testing /sales/lead/edit/" response = self.client.get( reverse('sales_lead_edit', args=[self.lead.id])) self.assertRedirects(response, reverse('user_login')) def test_lead_view_out(self): "Testing /sales/lead/view/" response = self.client.get( reverse('sales_lead_view', args=[self.lead.id])) self.assertRedirects(response, reverse('user_login')) def test_lead_delete_out(self): "Testing /sales/lead/delete/" response = self.client.get( reverse('sales_lead_delete', args=[self.lead.id])) self.assertRedirects(response, reverse('user_login')) # Opportunities def test_opportunity_index_out(self): "Testing /sales/opportunity/index/" response = self.client.get(reverse('sales_opportunity_index')) self.assertRedirects(response, reverse('user_login')) def test_opportunity_index_assigned_out(self): "Testing /sales/opportunity/index/assigned/" response = self.client.get(reverse('sales_opportunity_index_assigned')) self.assertRedirects(response, reverse('user_login')) def test_opportunity_add_out(self): "Testing /sales/opportunity/add/" response = self.client.get(reverse('sales_opportunity_add')) self.assertRedirects(response, reverse('user_login')) def test_opportunity_add_lead_out(self): "Testing /sales/opportunity/add/lead/" response = self.client.get( reverse('sales_opportunity_add_with_lead', args=[self.lead.id])) self.assertRedirects(response, reverse('user_login')) def test_opportunity_edit_out(self): "Testing /sales/opportunity/edit/" response = self.client.get( reverse('sales_opportunity_edit', args=[self.opportunity.id])) self.assertRedirects(response, reverse('user_login')) def test_opportunity_view_out(self): "Testing /sales/opportunity/view/" response = self.client.get( reverse('sales_opportunity_view', args=[self.opportunity.id])) self.assertRedirects(response, reverse('user_login')) def test_opportunity_delete_out(self): "Testing /sales/opportunity/delete/" response = self.client.get( reverse('sales_opportunity_delete', args=[self.opportunity.id])) self.assertRedirects(response, reverse('user_login'))
class FinanceAPITest(TestCase): """Finance api tests""" username = "******" password = "******" authentication_headers = {"CONTENT_TYPE": "application/json", "HTTP_AUTHORIZATION": "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk"} content_type = 'application/json' def setUp(self): self.group, created = Group.objects.get_or_create(name='test') self.user, created = DjangoUser.objects.get_or_create(username=self.username) self.user.set_password(self.password) self.user.save() self.perspective = Perspective(name='test') self.perspective.set_default_user() self.perspective.save() ModuleSetting.set('default_perspective', self.perspective.id) self.contact_type = ContactType(name='test') self.contact_type.set_default_user() self.contact_type.save() self.contact = Contact(name='test', contact_type=self.contact_type) self.contact.set_default_user() self.contact.save() self.category = Category(name='test') self.category.set_default_user() self.category.save() self.equity = Equity( issue_price=10, sell_price=10, issuer=self.contact, owner=self.contact) self.equity.set_default_user() self.equity.save() self.asset = Asset(name='test', owner=self.contact) self.asset.set_default_user() self.asset.save() self.tax = Tax(name='test', rate=10) self.tax.set_default_user() self.tax.save() self.currency = Currency(code="GBP", name="Pounds", symbol="L", is_default=True) self.currency.set_default_user() self.currency.save() self.account = Account( name='test', owner=self.contact, balance_currency=self.currency) self.account.set_default_user() self.account.save() self.liability = Liability(name='test', source=self.contact, target=self.contact, account=self.account, value=10, value_currency=self.currency) self.liability.set_default_user() self.liability.save() self.transaction = Transaction(name='test', account=self.account, source=self.contact, target=self.contact, value=10, value_currency=self.currency) self.transaction.set_default_user() self.transaction.save() def test_unauthenticated_access(self): """Test index page at /api/finance/currencies""" response = self.client.get('/api/finance/currencies') # Redirects as unauthenticated self.assertEquals(response.status_code, 401) def test_get_currencies_list(self): """ Test index page api/finance/currencies """ response = self.client.get( path=reverse('api_finance_currencies'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_currency(self): response = self.client.get(path=reverse('api_finance_currencies', kwargs={ 'object_ptr': self.currency.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_currency(self): updates = {"code": "RUB", "name": "api RUB", "factor": "10.00", "is_active": True} response = self.client.put(path=reverse('api_finance_currencies', kwargs={'object_ptr': self.currency.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['code'], updates['code']) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['factor'], updates['factor']) self.assertEquals(data['is_active'], updates['is_active']) def test_get_taxes_list(self): """ Test index page api/finance/taxes """ response = self.client.get( path=reverse('api_finance_taxes'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_tax(self): response = self.client.get(path=reverse( 'api_finance_taxes', kwargs={'object_ptr': self.tax.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_tax(self): updates = {"name": "API TEST TAX", "rate": "20.00", "compound": False} response = self.client.put(path=reverse('api_finance_taxes', kwargs={'object_ptr': self.tax.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['rate'], updates['rate']) self.assertEquals(data['compound'], updates['compound']) def test_get_categories_list(self): """ Test index page api/finance/categories """ response = self.client.get( path=reverse('api_finance_categories'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_category(self): response = self.client.get(path=reverse('api_finance_categories', kwargs={ 'object_ptr': self.category.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_category(self): updates = {"name": "Api category", "details": "api details"} response = self.client.put(path=reverse('api_finance_categories', kwargs={'object_ptr': self.category.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['details'], updates['details']) def test_get_assets_list(self): """ Test index page api/finance/assets """ response = self.client.get( path=reverse('api_finance_assets'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_asset(self): response = self.client.get(path=reverse('api_finance_assets', kwargs={ 'object_ptr': self.asset.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_asset(self): updates = {"current_value": "20.0", "owner": self.contact.id, "asset_type": "fixed", "name": "Api name", "initial_value": '40.0'} response = self.client.put(path=reverse('api_finance_assets', kwargs={'object_ptr': self.asset.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['owner']['id'], updates['owner']) self.assertEquals(data['asset_type'], updates['asset_type']) self.assertEquals(data['initial_value'], updates['initial_value']) self.assertEquals(data['current_value'], updates['current_value']) def test_get_accounts_list(self): """ Test index page api/finance/accounts """ response = self.client.get( path=reverse('api_finance_accounts'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_account(self): response = self.client.get(path=reverse('api_finance_accounts', kwargs={ 'object_ptr': self.account.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_account(self): updates = {"owner": self.contact.id, "balance_display": '40.0', "name": "api test name", "balance_currency": self.currency.id} response = self.client.put(path=reverse('api_finance_accounts', kwargs={'object_ptr': self.account.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['owner']['id'], updates['owner']) self.assertEquals(data['balance_display'], updates['balance_display']) self.assertEquals( data['balance_currency']['id'], updates['balance_currency']) def test_get_equities_list(self): """ Test index page api/finance/equities""" response = self.client.get( path=reverse('api_finance_equities'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_equity(self): response = self.client.get(path=reverse('api_finance_equities', kwargs={ 'object_ptr': self.equity.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_account_2(self): updates = {"issue_price": "100.0", "equity_type": "warrant", "sell_price": "50.0", "amount": 100, "purchase_date": "2011-06-06", "owner": self.contact.id, "issuer": self.contact.id} response = self.client.put(path=reverse('api_finance_equities', kwargs={'object_ptr': self.equity.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['issue_price'], updates['issue_price']) self.assertEquals(data['equity_type'], updates['equity_type']) self.assertEquals(data['sell_price'], updates['sell_price']) self.assertEquals(data['amount'], updates['amount']) self.assertEquals(data['purchase_date'], updates['purchase_date']) self.assertEquals(data['owner']['id'], updates['owner']) self.assertEquals(data['issuer']['id'], updates['issuer']) self.assertEquals(data['issuer']['id'], updates['issuer']) def test_get_liabilities_list(self): """ Test index page api/finance/liabilities""" response = self.client.get( path=reverse('api_finance_liabilities'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_liability(self): response = self.client.get(path=reverse('api_finance_liabilities', kwargs={ 'object_ptr': self.liability.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_liability(self): updates = {"account": self.account.id, "target": self.contact.id, "value_display": "20.0", "name": "api test name", "value_currency": self.currency.id} response = self.client.put(path=reverse('api_finance_liabilities', kwargs={'object_ptr': self.liability.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['target']['id'], updates['target']) self.assertEquals(data['account']['id'], updates['account']) self.assertEquals(data['value_display'], updates['value_display']) self.assertEquals( data['value_currency']['id'], updates['value_currency']) def test_get_transactions_list(self): """ Test index page api/finance/transactions""" response = self.client.get( path=reverse('api_finance_transactions'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_transaction(self): response = self.client.get(path=reverse('api_finance_transactions', kwargs={ 'object_ptr': self.transaction.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_transaction(self): updates = {"value_display": "1000.0", "account": self.account.id, "name": "api test name", "value_currency": self.currency.id, "datetime": "2011-03-21 11:04:42", "target": self.contact.id, "source": self.contact.id} response = self.client.put(path=reverse('api_finance_transactions', kwargs={'object_ptr': self.transaction.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['value_display'], updates['value_display']) self.assertEquals(data['account']['id'], updates['account']) self.assertEquals(data['value_currency']['id'], updates['value_currency']) self.assertEquals(data['datetime'].replace("T", " "), updates['datetime']) self.assertEquals(data['target']['id'], updates['target']) self.assertEquals(data['account']['id'], updates['account']) self.assertEquals(data['source']['id'], updates['source'])
class SalesAPITest(TestCase): username = "******" password = "******" authentication_headers = {"CONTENT_TYPE": "application/json", "HTTP_AUTHORIZATION": "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk"} content_type = 'application/json' def setUp(self): self.group, created = Group.objects.get_or_create(name='test') self.user, created = DjangoUser.objects.get_or_create(username=self.username) self.user.set_password(self.password) self.user.save() self.perspective = Perspective(name='test') self.perspective.set_default_user() self.perspective.save() ModuleSetting.set('default_perspective', self.perspective.id) self.contact_type = ContactType() self.contact_type.slug = 'machine' self.contact_type.name = 'machine' self.contact_type.save() self.contact = Contact() self.contact.contact_type = self.contact_type self.contact.set_default_user() self.contact.save() self.assertNotEquals(self.contact.id, None) self.status = SaleStatus() self.status.active = True self.status.use_sales = True self.status.use_leads = True self.status.use_opportunities = True self.status.set_default_user() self.status.save() self.assertNotEquals(self.status.id, None) self.currency = Currency(code="GBP", name="Pounds", symbol="L", is_default=True) self.currency.save() self.source = SaleSource() self.source.active = True self.source.save() self.source.set_user(self.user.profile) self.assertNotEquals(self.source.id, None) self.product = Product(name="Test") self.product.product_type = 'service' self.product.active = True self.product.sell_price = 10 self.product.buy_price = 100 self.product.set_default_user() self.product.save() self.assertNotEquals(self.product.id, None) self.subscription = Subscription() self.subscription.client = self.contact self.subscription.set_default_user() self.subscription.save() self.assertNotEquals(self.subscription.id, None) self.lead = Lead() self.lead.contact_method = 'email' self.lead.status = self.status self.lead.contact = self.contact self.lead.set_default_user() self.lead.save() self.assertNotEquals(self.lead.id, None) self.opportunity = Opportunity() self.opportunity.lead = self.lead self.opportunity.contact = self.contact self.opportunity.status = self.status self.opportunity.amount = 100 self.opportunity.amount_currency = self.currency self.opportunity.amount_display = 120 self.opportunity.set_default_user() self.opportunity.save() self.assertNotEquals(self.opportunity.id, None) self.order = SaleOrder(reference="Test") self.order.opportunity = self.opportunity self.order.status = self.status self.order.source = self.source self.order.currency = self.currency self.order.total = 0 self.order.total_display = 0 self.order.set_default_user() self.order.save() self.assertNotEquals(self.order.id, None) self.ordered_product = OrderedProduct() self.ordered_product.product = self.product self.ordered_product.order = self.order self.ordered_product.rate = 0 self.ordered_product.subscription = self.subscription self.ordered_product.set_default_user() self.ordered_product.save() self.assertNotEquals(self.ordered_product.id, None) def test_unauthenticated_access(self): """Test index page at /sales/statuses""" response = self.client.get('/api/sales/statuses') # Redirects as unauthenticated self.assertEquals(response.status_code, 401) def test_get_statuses_list(self): """ Test index page api/sales/status """ response = self.client.get( path=reverse('api_sales_status'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_status(self): response = self.client.get(path=reverse('api_sales_status', kwargs={ 'object_ptr': self.status.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_status(self): updates = {"name": "Close_API", "active": True, "details": "api test details", "use_leads": True, "use_opportunities": True, "hidden": False} response = self.client.put(path=reverse('api_sales_status', kwargs={'object_ptr': self.status.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['active'], updates['active']) self.assertEquals(data['details'], updates['details']) self.assertEquals(data['use_leads'], updates['use_leads']) self.assertEquals( data['use_opportunities'], updates['use_opportunities']) self.assertEquals(data['hidden'], updates['hidden']) def test_get_products_list(self): """ Test index page api/sales/products """ response = self.client.get( path=reverse('api_sales_products'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_product(self): response = self.client.get(path=reverse('api_sales_products', kwargs={ 'object_ptr': self.product.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_product(self): updates = {"name": "API product", "parent": None, "product_type": "service", "code": "api_test_code", "buy_price": '100.05', "sell_price": '10.5', "active": True, "runout_action": "ignore", "details": "api details"} response = self.client.put(path=reverse('api_sales_products', kwargs={'object_ptr': self.product.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['product_type'], updates['product_type']) self.assertEquals(data['code'], updates['code']) self.assertEquals(data['buy_price'], updates['buy_price']) self.assertEquals(data['sell_price'], updates['sell_price']) self.assertEquals(data['active'], updates['active']) self.assertEquals(data['runout_action'], updates['runout_action']) self.assertEquals(data['details'], updates['details']) def test_get_sources_list(self): """ Test index page api/sales/sources """ response = self.client.get( path=reverse('api_sales_sources'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_source(self): response = self.client.get(path=reverse('api_sales_sources', kwargs={ 'object_ptr': self.source.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_source(self): updates = { "name": "Api source", "active": True, "details": "api details"} response = self.client.put(path=reverse('api_sales_sources', kwargs={'object_ptr': self.source.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['name'], updates['name']) self.assertEquals(data['active'], updates['active']) self.assertEquals(data['details'], updates['details']) # def test_get_leads_list(self): """ Test index page api/sales/leads """ response = self.client.get( path=reverse('api_sales_leads'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_lead(self): response = self.client.get(path=reverse( 'api_sales_leads', kwargs={'object_ptr': self.lead.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_lead(self): updates = {"status": self.status.id, "contact_method": "email", "contact": self.contact.id, "products_interested": [self.product.id], "source": self.source.id, 'details': 'Api details'} response = self.client.put(path=reverse('api_sales_leads', kwargs={'object_ptr': self.lead.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['status']['id'], updates['status']) self.assertEquals(data['contact_method'], updates['contact_method']) self.assertEquals(data['contact']['id'], updates['contact']) for i, product in enumerate(data['products_interested']): self.assertEquals(product['id'], updates['products_interested'][i]) self.assertEquals(data['source']['id'], updates['source']) self.assertEquals(data['details'], updates['details']) def test_get_opportunities_list(self): """ Test index page api/sales/opportunities """ response = self.client.get( path=reverse('api_sales_opportunities'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_opportunity(self): response = self.client.get(path=reverse('api_sales_opportunities', kwargs={ 'object_ptr': self.opportunity.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_opportunity(self): updates = {"status": self.status.id, "products_interested": [self.product.id], "contact": self.contact.id, "amount_display": 3000.56, "amount_currency": self.currency.id, "details": "API DETAILS"} response = self.client.put(path=reverse('api_sales_opportunities', kwargs={'object_ptr': self.opportunity.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['status']['id'], updates['status']) self.assertEquals(data['contact']['id'], updates['contact']) for i, product in enumerate(data['products_interested']): self.assertEquals(product['id'], updates['products_interested'][i]) self.assertEquals( data['amount_currency']['id'], updates['amount_currency']) self.assertEquals(data['details'], updates['details']) def test_get_orders_list(self): """ Test index page api/sales/orders """ response = self.client.get( path=reverse('api_sales_orders'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_order(self): response = self.client.get(path=reverse( 'api_sales_orders', kwargs={'object_ptr': self.order.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_order(self): updates = {"datetime": "2011-04-11 12:01:15", "status": self.status.id, "source": self.source.id, "details": "api details"} response = self.client.put(path=reverse('api_sales_orders', kwargs={'object_ptr': self.order.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['status']['id'], updates['status']) self.assertEquals(data['source']['id'], updates['source']) self.assertEquals(data['details'], updates['details']) def test_get_subscriptions_list(self): """ Test index page api/sales/subscriptions""" response = self.client.get( path=reverse('api_sales_subscriptions'), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_get_subscription(self): response = self.client.get(path=reverse('api_sales_subscriptions', kwargs={ 'object_ptr': self.subscription.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_subscription(self): updates = {"product": self.product.id, "start": "2011-06-30", "cycle_period": "daily", "active": True, "details": "api details"} response = self.client.put(path=reverse('api_sales_subscriptions', kwargs={'object_ptr': self.subscription.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['product']['id'], updates['product']) self.assertEquals(data['cycle_period'], updates['cycle_period']) self.assertEquals(data['active'], updates['active']) self.assertEquals(data['details'], updates['details']) def test_get_ordered_product(self): response = self.client.get(path=reverse('api_sales_ordered_products', kwargs={ 'object_ptr': self.ordered_product.id}), **self.authentication_headers) self.assertEquals(response.status_code, 200) def test_update_ordered_product(self): updates = { "discount": '10.0', "product": self.product.id, "quantity": '10'} response = self.client.put( path=reverse('api_sales_ordered_products', kwargs={'object_ptr': self.ordered_product.id}), content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers) self.assertEquals(response.status_code, 200) data = json.loads(response.content) self.assertEquals(data['product']['id'], updates['product']) self.assertEquals(data['discount'], updates['discount']) self.assertEquals(data['quantity'], updates['quantity'])
class SalesViewsTest(TestCase): username = "******" password = "******" def setUp(self): self.group, created = Group.objects.get_or_create(name="test") self.user, created = DjangoUser.objects.get_or_create(username=self.username) self.user.set_password(self.password) self.user.save() perspective, created = Perspective.objects.get_or_create(name="default") perspective.set_default_user() perspective.save() ModuleSetting.set("default_perspective", perspective.id) self.contact_type = ContactType() self.contact_type.slug = "machine" self.contact_type.name = "machine" self.contact_type.save() self.contact = Contact() self.contact.contact_type = self.contact_type self.contact.set_default_user() self.contact.save() self.assertNotEquals(self.contact.id, None) self.status = SaleStatus() self.status.set_default_user() self.status.save() self.assertNotEquals(self.status.id, None) self.currency = Currency(code="GBP", name="Pounds", symbol="L", is_default=True) self.currency.save() self.source = SaleSource() self.source.set_default_user() self.source.save() self.assertNotEquals(self.source.id, None) self.product = Product(name="Test") self.product.product_type = "service" self.product.active = True self.product.sell_price = 10 self.product.buy_price = 100 self.product.set_default_user() self.product.save() self.assertNotEquals(self.product.id, None) self.subscription = Subscription() self.subscription.client = self.contact self.subscription.set_default_user() self.subscription.save() self.assertNotEquals(self.subscription.id, None) self.lead = Lead() self.lead.contact_method = "email" self.lead.status = self.status self.lead.contact = self.contact self.lead.set_default_user() self.lead.save() self.assertNotEquals(self.lead.id, None) self.opportunity = Opportunity() self.opportunity.lead = self.lead self.opportunity.contact = self.contact self.opportunity.status = self.status self.opportunity.amount = 100 self.opportunity.amount_currency = self.currency self.opportunity.amount_display = 120 self.opportunity.set_default_user() self.opportunity.save() self.assertNotEquals(self.opportunity.id, None) self.order = SaleOrder(reference="Test") self.order.opportunity = self.opportunity self.order.status = self.status self.order.source = self.source self.order.currency = self.currency self.order.total = 0 self.order.total_display = 0 self.order.set_default_user() self.order.save() self.assertNotEquals(self.order.id, None) self.ordered_product = OrderedProduct() self.ordered_product.product = self.product self.ordered_product.order = self.order self.ordered_product.rate = 0 self.ordered_product.subscription = self.subscription self.ordered_product.set_default_user() self.ordered_product.save() self.assertNotEquals(self.ordered_product.id, None) ###################################### # Testing views when user is logged in ###################################### def test_index(self): "Test page with login at /sales/index" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_index")) self.assertEquals(response.status_code, 200) def test_index_open(self): "Test page with login at /sales/open" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_index_open")) self.assertEquals(response.status_code, 200) def test_index_assigned(self): "Test page with login at /sales/index/assigned" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_index_assigned")) self.assertEquals(response.status_code, 200) # Orders def test_order_add(self): "Test page with login at /sales/order/add" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_order_add")) self.assertEquals(response.status_code, 200) def test_order_add_lead(self): "Test page with login at /sales/order/add/lead/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_order_add_with_lead", args=[self.lead.id])) self.assertEquals(response.status_code, 200) def test_order_add_opportunity(self): "Test page with login at /sales/order/add/opportunity/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_order_add_with_opportunity", args=[self.opportunity.id])) self.assertEquals(response.status_code, 200) def test_order_edit(self): "Test page with login at /sales/order/edit/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_order_edit", args=[self.order.id])) self.assertEquals(response.status_code, 200) def test_order_view(self): "Test page with login at /sales/order/view/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_order_view", args=[self.order.id])) self.assertEquals(response.status_code, 200) def test_order_delete(self): "Test page with login at /sales/order/delete/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_order_delete", args=[self.order.id])) self.assertEquals(response.status_code, 200) def test_order_invoice_view(self): "Test page with login at /sales/order/invoice/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_order_invoice_view", args=[self.order.id])) self.assertEquals(response.status_code, 200) # Products def test_product_index(self): "Test page with login at /sales/product/index" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_product_index")) self.assertEquals(response.status_code, 200) def test_product_add(self): "Test page with login at /sales/product/add/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_product_add")) self.assertEquals(response.status_code, 200) def test_product_add_parent(self): "Test page with login at /sales/product/add" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_product_add", args=[self.product.id])) self.assertEquals(response.status_code, 200) def test_product_edit(self): "Test page with login at /sales/product/edit/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_product_edit", args=[self.product.id])) self.assertEquals(response.status_code, 200) def test_product_view(self): "Test page with login at /sales/product/view/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_product_view", args=[self.product.id])) self.assertEquals(response.status_code, 200) def test_product_delete(self): "Test page with login at /sales/product/delete/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_product_delete", args=[self.product.id])) self.assertEquals(response.status_code, 200) # Settings def test_settings_view(self): "Test page with login at /sales/settings/view" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_settings_view")) self.assertEquals(response.status_code, 200) def test_settings_edit(self): "Test page with login at /sales/settings/edit" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_settings_edit")) self.assertEquals(response.status_code, 200) # Statuses def test_status_add(self): "Test page with login at /sales/status/add" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_status_add")) self.assertEquals(response.status_code, 200) def test_status_edit(self): "Test page with login at /sales/status/edit/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_status_edit", args=[self.status.id])) self.assertEquals(response.status_code, 200) def test_status_view(self): "Test page with login at /sales/status/view/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_status_view", args=[self.status.id])) self.assertEquals(response.status_code, 200) def test_status_delete(self): "Test page with login at /sales/status/delete/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_status_delete", args=[self.status.id])) self.assertEquals(response.status_code, 200) # Subscriptions def test_subscription_add(self): "Test page with login at /sales/subscription/add" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_subscription_add")) self.assertEquals(response.status_code, 200) def test_subscription_add_product(self): "Test page with login at /sales/subscription/add/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_subscription_add_with_product", args=[self.product.id])) self.assertEquals(response.status_code, 200) def test_subscription_edit(self): "Test page with login at /sales/subscription/edit/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_subscription_edit", args=[self.subscription.id])) self.assertEquals(response.status_code, 200) def test_subscription_view(self): "Test page with login at /sales/subscription/view/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_subscription_view", args=[self.subscription.id])) self.assertEquals(response.status_code, 200) def test_subscription_delete(self): "Test page with login at /sales/subscription/delete/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_subscription_delete", args=[self.subscription.id])) self.assertEquals(response.status_code, 200) # Ordered Products def test_ordered_product_add(self): "Test page with login at /sales/ordered_product/add/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_ordered_product_add", args=[self.order.id])) self.assertEquals(response.status_code, 200) def test_ordered_product_edit(self): "Test page with login at /sales/ordered_product/edit/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_ordered_product_edit", args=[self.ordered_product.id])) self.assertEquals(response.status_code, 200) def test_ordered_product_view(self): "Test page with login at /sales/ordered_product/view/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_ordered_product_view", args=[self.ordered_product.id])) self.assertEquals(response.status_code, 200) def test_ordered_product_delete(self): "Test page with login at /sales/ordered_product/delete/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_ordered_product_delete", args=[self.ordered_product.id])) self.assertEquals(response.status_code, 200) # Sources def test_source_add(self): "Test page with login at /sales/source/add" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_source_add")) self.assertEquals(response.status_code, 200) def test_source_edit(self): "Test page with login at /sales/source/edit/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_source_edit", args=[self.source.id])) self.assertEquals(response.status_code, 200) def test_source_view(self): "Test page with login at /sales/source/view/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_source_view", args=[self.source.id])) self.assertEquals(response.status_code, 200) def test_source_delete(self): "Test page with login at /sales/source/delete/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_source_delete", args=[self.source.id])) self.assertEquals(response.status_code, 200) # Leads def test_lead_index(self): "Test page with login at /sales/lead/index" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_lead_index")) self.assertEquals(response.status_code, 200) def test_lead_index_assigned(self): "Test page with login at /sales/lead/index/assigned" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_lead_index_assigned")) self.assertEquals(response.status_code, 200) def test_lead_add(self): "Test page with login at /sales/lead/add" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_lead_add")) self.assertEquals(response.status_code, 200) def test_lead_edit(self): "Test page with login at /sales/lead/edit/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_lead_edit", args=[self.lead.id])) self.assertEquals(response.status_code, 200) def test_lead_view(self): "Test page with login at /sales/lead/view/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_lead_view", args=[self.lead.id])) self.assertEquals(response.status_code, 200) def test_lead_delete(self): "Test page with login at /sales/lead/delete/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_lead_delete", args=[self.lead.id])) self.assertEquals(response.status_code, 200) # Opportunities def test_opportunity_index(self): "Test page with login at /sales/opportunity/index" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_opportunity_index")) self.assertEquals(response.status_code, 200) def test_opportunity_index_assigned(self): "Test page with login at /sales/opportunity/index/assigned" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_opportunity_index_assigned")) self.assertEquals(response.status_code, 200) def test_opportunity_add(self): "Test page with login at /sales/opportunity/add" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_opportunity_add")) self.assertEquals(response.status_code, 200) def test_opportunity_add_lead(self): "Test page with login at /sales/opportunity/add/lead/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_opportunity_add_with_lead", args=[self.lead.id])) self.assertEquals(response.status_code, 200) def test_opportunity_edit(self): "Test page with login at /sales/opportunity/edit/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_opportunity_edit", args=[self.opportunity.id])) self.assertEquals(response.status_code, 200) def test_opportunity_view(self): "Test page with login at /sales/opportunity/view/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_opportunity_view", args=[self.opportunity.id])) self.assertEquals(response.status_code, 200) def test_opportunity_delete(self): "Test page with login at /sales/opportunity/delete/" response = self.client.post("/accounts/login", {"username": self.username, "password": self.password}) self.assertRedirects(response, "/") response = self.client.get(reverse("sales_opportunity_delete", args=[self.opportunity.id])) self.assertEquals(response.status_code, 200) ###################################### # Testing views when user is not logged in ###################################### def test_index_anonymous(self): "Test index page at /sales/" response = self.client.get("/sales/") # Redirects as unauthenticated self.assertRedirects(response, reverse("user_login")) def test_index_open_out(self): "Testing /sales/open" response = self.client.get(reverse("sales_index_open")) self.assertRedirects(response, reverse("user_login")) def test_index_assigned_out(self): "Testing /sales/index/assigned" response = self.client.get(reverse("sales_index_assigned")) self.assertRedirects(response, reverse("user_login")) # Orders def test_order_add_out(self): "Testing /sales/order/add" response = self.client.get(reverse("sales_order_add")) self.assertRedirects(response, reverse("user_login")) def test_order_add_lead_out(self): "Testing /sales/order/add/lead/" response = self.client.get(reverse("sales_order_add_with_lead", args=[self.lead.id])) self.assertRedirects(response, reverse("user_login")) def test_order_add_opportunity_out(self): "Testing /sales/order/add/opportunity/" response = self.client.get(reverse("sales_order_add_with_opportunity", args=[self.opportunity.id])) self.assertRedirects(response, reverse("user_login")) def test_order_edit_out(self): "Testing /sales/order/edit/" response = self.client.get(reverse("sales_order_edit", args=[self.order.id])) self.assertRedirects(response, reverse("user_login")) def test_order_view_out(self): "Testing /sales/order/view/" response = self.client.get(reverse("sales_order_view", args=[self.order.id])) self.assertRedirects(response, reverse("user_login")) def test_order_delete_out(self): "Testing /sales/order/delete/" response = self.client.get(reverse("sales_order_delete", args=[self.order.id])) self.assertRedirects(response, reverse("user_login")) def test_order_invoice_view_out(self): "Testing /sales/order/invoice/" response = self.client.get(reverse("sales_order_invoice_view", args=[self.order.id])) self.assertRedirects(response, reverse("user_login")) # Products def test_product_index_out(self): "Testing /sales/product/index" response = self.client.get(reverse("sales_product_index")) self.assertRedirects(response, reverse("user_login")) def test_product_add_out(self): "Testing /sales/product/add/" response = self.client.get(reverse("sales_product_add")) self.assertRedirects(response, reverse("user_login")) def test_product_add_parent_out(self): "Testing /sales/product/add" response = self.client.get(reverse("sales_product_add", args=[self.product.id])) self.assertRedirects(response, reverse("user_login")) def test_product_edit_out(self): "Testing /sales/product/edit/" response = self.client.get(reverse("sales_product_edit", args=[self.product.id])) self.assertRedirects(response, reverse("user_login")) def test_product_view_out(self): "Testing /sales/product/view/" response = self.client.get(reverse("sales_product_view", args=[self.product.id])) self.assertRedirects(response, reverse("user_login")) def test_product_delete_out(self): "Testing /sales/product/delete/" response = self.client.get(reverse("sales_product_delete", args=[self.product.id])) self.assertRedirects(response, reverse("user_login")) # Settings def test_settings_view_out(self): "Testing /sales/settings/view" response = self.client.get(reverse("sales_settings_view")) self.assertRedirects(response, reverse("user_login")) def test_settings_edit_out(self): "Testing /sales/settings/edit" response = self.client.get(reverse("sales_settings_edit")) self.assertRedirects(response, reverse("user_login")) # Statuses def test_status_add_out(self): "Testing /sales/status/add" response = self.client.get(reverse("sales_status_add")) self.assertRedirects(response, reverse("user_login")) def test_status_edit_out(self): "Testing /sales/status/edit/" response = self.client.get(reverse("sales_status_edit", args=[self.status.id])) self.assertRedirects(response, reverse("user_login")) def test_status_view_out(self): "Testing /sales/status/view/" response = self.client.get(reverse("sales_status_view", args=[self.status.id])) self.assertRedirects(response, reverse("user_login")) def test_status_delete_out(self): "Testing /sales/status/delete/" response = self.client.get(reverse("sales_status_delete", args=[self.status.id])) self.assertRedirects(response, reverse("user_login")) # Subscriptions def test_subscription_add_out(self): "Testing /sales/subscription/add" response = self.client.get(reverse("sales_subscription_add")) self.assertRedirects(response, reverse("user_login")) def test_subscription_add_product_out(self): "Testing /sales/subscription/add/" response = self.client.get(reverse("sales_subscription_add_with_product", args=[self.product.id])) self.assertRedirects(response, reverse("user_login")) def test_subscription_edit_out(self): "Testing /sales/subscription/edit/" response = self.client.get(reverse("sales_subscription_edit", args=[self.subscription.id])) self.assertRedirects(response, reverse("user_login")) def test_subscription_view_out(self): "Testing /sales/subscription/view/" response = self.client.get(reverse("sales_subscription_view", args=[self.subscription.id])) self.assertRedirects(response, reverse("user_login")) def test_subscription_delete_out(self): "Testing /sales/subscription/delete/" response = self.client.get(reverse("sales_subscription_delete", args=[self.subscription.id])) self.assertRedirects(response, reverse("user_login")) # Ordered Products def test_ordered_product_add_out(self): "Testing /sales/ordered_product/add/" response = self.client.get(reverse("sales_ordered_product_add", args=[self.order.id])) self.assertRedirects(response, reverse("user_login")) def test_ordered_product_edit_out(self): "Testing /sales/ordered_product/edit/" response = self.client.get(reverse("sales_ordered_product_edit", args=[self.ordered_product.id])) self.assertRedirects(response, reverse("user_login")) def test_ordered_product_view_out(self): "Testing /sales/ordered_product/view/" response = self.client.get(reverse("sales_ordered_product_view", args=[self.ordered_product.id])) self.assertRedirects(response, reverse("user_login")) def test_ordered_product_delete_out(self): "Testing /sales/ordered_product/delete/" response = self.client.get(reverse("sales_ordered_product_delete", args=[self.ordered_product.id])) self.assertRedirects(response, reverse("user_login")) # Sources def test_source_add_out(self): "Testing /sales/source/add" response = self.client.get(reverse("sales_source_add")) self.assertRedirects(response, reverse("user_login")) def test_source_edit_out(self): "Testing /sales/source/edit/" response = self.client.get(reverse("sales_source_edit", args=[self.source.id])) self.assertRedirects(response, reverse("user_login")) def test_source_view_out(self): "Testing /sales/source/view/" response = self.client.get(reverse("sales_source_view", args=[self.source.id])) self.assertRedirects(response, reverse("user_login")) def test_source_delete_out(self): "Testing /sales/source/delete/" response = self.client.get(reverse("sales_source_delete", args=[self.source.id])) self.assertRedirects(response, reverse("user_login")) # Leads def test_lead_index_out(self): "Testing /sales/lead/index" response = self.client.get(reverse("sales_lead_index")) self.assertRedirects(response, reverse("user_login")) def test_lead_index_assigned_out(self): "Testing /sales/lead/index/assigned" response = self.client.get(reverse("sales_lead_index_assigned")) self.assertRedirects(response, reverse("user_login")) def test_lead_add_out(self): "Testing /sales/lead/add" response = self.client.get(reverse("sales_lead_add")) self.assertRedirects(response, reverse("user_login")) def test_lead_edit_out(self): "Testing /sales/lead/edit/" response = self.client.get(reverse("sales_lead_edit", args=[self.lead.id])) self.assertRedirects(response, reverse("user_login")) def test_lead_view_out(self): "Testing /sales/lead/view/" response = self.client.get(reverse("sales_lead_view", args=[self.lead.id])) self.assertRedirects(response, reverse("user_login")) def test_lead_delete_out(self): "Testing /sales/lead/delete/" response = self.client.get(reverse("sales_lead_delete", args=[self.lead.id])) self.assertRedirects(response, reverse("user_login")) # Opportunities def test_opportunity_index_out(self): "Testing /sales/opportunity/index/" response = self.client.get(reverse("sales_opportunity_index")) self.assertRedirects(response, reverse("user_login")) def test_opportunity_index_assigned_out(self): "Testing /sales/opportunity/index/assigned/" response = self.client.get(reverse("sales_opportunity_index_assigned")) self.assertRedirects(response, reverse("user_login")) def test_opportunity_add_out(self): "Testing /sales/opportunity/add/" response = self.client.get(reverse("sales_opportunity_add")) self.assertRedirects(response, reverse("user_login")) def test_opportunity_add_lead_out(self): "Testing /sales/opportunity/add/lead/" response = self.client.get(reverse("sales_opportunity_add_with_lead", args=[self.lead.id])) self.assertRedirects(response, reverse("user_login")) def test_opportunity_edit_out(self): "Testing /sales/opportunity/edit/" response = self.client.get(reverse("sales_opportunity_edit", args=[self.opportunity.id])) self.assertRedirects(response, reverse("user_login")) def test_opportunity_view_out(self): "Testing /sales/opportunity/view/" response = self.client.get(reverse("sales_opportunity_view", args=[self.opportunity.id])) self.assertRedirects(response, reverse("user_login")) def test_opportunity_delete_out(self): "Testing /sales/opportunity/delete/" response = self.client.get(reverse("sales_opportunity_delete", args=[self.opportunity.id])) self.assertRedirects(response, reverse("user_login"))