示例#1
0
def message_response(from_number, from_body='web form'):
    check_telephone = Lead.query.filter_by(telephone=from_number).first()
    if check_telephone is None:
        db.session.add(Lead(from_body, from_number))
        db.session.commit()
        return 'Text Yes to verify your phone number so that we can connect you with a contractor, or No to cancel', False
    elif get_timedelta(check_telephone.received_on).days >= 2:
        return 'Hold tight. We are in the process of connecting you with a contractor.', True
    elif from_body.lower() == 'yes' and check_telephone.is_verified is False:
        check_telephone.is_verified = True
        db.session.add(check_telephone)
        db.session.commit()
        message_admin(from_number)
        if app.config['MAIL_ON'] is True:
            send_email(current_app.config['MAIL_ADMIN'],
                       'Text a Pro Confirmed Phone Number',
                       'mail/contac    t_me',
                       telephone=from_number)
        return 'Thanks for verifying your number. We will connect you with a contractor shortly', True
    elif from_body.lower() == 'yes' and check_telephone.is_verified is True:
        return 'Hold tight. We are in the process of connecting you with a contractor.'
    elif from_body.lower() == 'no' and check_telephone.is_verified is True:
        return None, True
    elif from_body.lower() == 'no' and check_telephone.is_verified is False:
        check_telephone.is_verified = False
        db.session.add(check_telephone)
        db.session.commit()
        return 'Ok we\'ve cancelled your request', True
    elif check_telephone.is_verified is False:
        return 'We\'ve received your request, but please text Yes to continue or No to cancel', True
    else:
        return None, True
def list():
	args = request.args
	if 'token' in args:
		return _search_lead_by_token(args['token'])
	else:
		leads = [l.to_json() for l in Lead.all()]
		return jsonify(data=leads), 200
def click(id):
	lead = Lead.get_by_id(int(id))
	lead.status = 'CLICKED'
	lead.put()

	create_activity('LEAD_CLICKED', lead=lead)
	return '', 200
def read(id):
	lead = Lead.get_by_id(int(id))
	lead.mark_as_read()

	create_activity('LEAD_READ', lead=lead)

	image = Image.new("RGB", (1, 1), "black")
	output = StringIO.StringIO()
	image.save(output, format="png")
	text_layer = output.getvalue()
	logging.debug(text_layer)
	output.close()

	return Response(text_layer, mimetype='image/png')
示例#5
0
 def _save_to_database(self, lead):
     lead = Lead(self.title, index[0], index[1], index[2], index[3])
     lead.save_to_db()
示例#6
0
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'))
示例#7
0
    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)
示例#8
0
文件: tests.py 项目: tovmeod/anaf
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"))
示例#9
0
文件: tests.py 项目: tovmeod/anaf
    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)
def experience():
    # search for resume
    lead = Lead.query.filter_by(id=request.args.get("id")).first()
    print(
        "original lead finding: ",
        lead,
        not not lead,
        flush=True,
    )
    if request.method in ("DELETE", "GET") and not lead:
        return jsonify(success=False)

    if request.method == "DELETE":
        db.session.delete(lead)
        db.session.commit()

    elif request.method == "POST":
        # lead = lead or Lead()
        # print(request.get_json(), flush=True)
        # print(request.args, flush=True)
        body = request_data()
        print("body: ", body, flush=True)

        # Check if another lead with the same email

        if "id" in body and lead:
            if body:
                for key in [
                        "name",
                        "email",
                        "number",
                        "notes",
                        "questionAsked",
                        "tourBookedOn",
                        "tourBookedFor",
                        "notInterested",
                        "hasApplied",
                ]:
                    if key in body:
                        setattr(lead, key, body[key])

                if "leadType" in body:
                    if isinstance(body["leadType"], str):
                        lead.leadType = json.loads(body["leadType"])
                    elif isinstance(body["leadType"], list):
                        lead.leadType = body["leadType"]

                if "followups" in body:
                    lead.followups = body["followups"]

                if "agent" in body:
                    if isinstance(body["agent"], str):
                        temp = json.loads(body["agent"])
                        if isinstance(temp, int):
                            lead.agent = temp

                    elif isinstance(body["agent"], int):
                        lead.agent = body["agent"]

        # conditions for adding info to an existing lead
        if ("email" in body and "id" not in body and len(body["email"]) > 0
                and Lead.query.filter_by(email=body["email"]).first()):
            lead = Lead.query.filter_by(email=body["email"]).first()

            if "name" in body and len(body["name"]) > len(lead.name):
                lead.name = body["name"]

            if "leadType" in body and len(body["leadType"]) > 0:
                temp = []
                if isinstance(body["leadType"], str):
                    temp = json.loads(body["leadType"])
                elif isinstance(body["leadType"], list):
                    temp = body["leadType"]
                leadTypes = lead.leadType + temp
                leadTypes = list(set(leadTypes))
                lead.leadType = leadTypes
                print("the new lead types", leadTypes, flush=True)

            for key in [
                    "number",
                    "notes",
                    "questionAsked",
                    "tourBookedOn",
                    "tourBookedFor",
            ]:
                if key in body and len(body[key]) > 0:
                    # if number is already created
                    if key == "number" and body[key] in lead.number:
                        continue
                    # check to ensure everything we are adding is larger than zero
                    if len(getattr(lead, key)) > 0:
                        separator = ", "
                        if key == "notes":
                            separator = ",\n\n"
                        setattr(lead, key,
                                body[key] + separator + getattr(lead, key))
                    else:
                        setattr(lead, key, body[key])
                # add new information (for questions, tourbooked, tourbookedon, questionasked, notes, number)
                # leadType, add if not already there (make sure it is a number and )
                # agent if there update it
                # hasApplied / not interested else

            for key in [
                    "notInterested",
                    "hasApplied",
            ]:
                if key in body:
                    setattr(lead, key, body[key])

            if "agent" in body:
                if isinstance(body["agent"], str):
                    temp = json.loads(body["agent"])
                    if isinstance(temp, int):
                        lead.agent = temp

                elif isinstance(body["agent"], int):
                    lead.agent = body["agent"]

            if "followups" in body:
                lead.followups = body["followups"]

        # create a new lead
        else:
            lead = lead or Lead()

            if body:
                for key in [
                        "name",
                        "email",
                        "number",
                        "notes",
                        "questionAsked",
                        "tourBookedOn",
                        "tourBookedFor",
                        "notInterested",
                        "hasApplied",
                ]:
                    if key in body:
                        setattr(lead, key, body[key])
                if "followups" in body:
                    lead.followups = body["followups"]

                if "leadType" in body:
                    if isinstance(body["leadType"], str):
                        lead.leadType = json.loads(body["leadType"])
                    elif isinstance(body["leadType"], list):
                        lead.leadType = body["leadType"]

                if "agent" in body:
                    if isinstance(body["agent"], str):
                        temp = json.loads(body["agent"])
                        if isinstance(temp, int):
                            lead.agent = temp

                    elif isinstance(body["agent"], int):
                        lead.agent = body["agent"]

            db.session.add(lead)

        try:
            db.session.commit()
        except Exception as e:
            print(e, flush=True)
            raise e

    elif request.method == "GET":
        return jsonify(sqldict(lead))

    return jsonify(id=lead.id, name=lead.name, email=lead.email)
def create():

	# get the post data
	post_data = get_post_data()

	sender_broker = None
	owner = None
	agency = None
	listing = None

	# validates required parameters
	_validates_required_parameters(post_data)

	# creates or find the property owner
	if 'property_owner' in post_data:
		owner = _create_property_owner(post_data['property_owner'])

	# creates or find the agency
	if 'agency' in post_data:
		agency = _create_agency(post_data['agency'], post_data['source_application'])

	# creates or find the property
	if 'listing' in post_data:
		listing = _create_listing(post_data['listing'])

	# if broker is sent
	if 'sender' in post_data:
		# creates or find the broker
		sender_broker = _create_broker(post_data['sender'], agency)

	# defines the buyer type and creates the lead
	buyer_type = ''

	if 'sender' in post_data and owner is not None:
		buyer_type = 'PROPERTY_OWNER'
	else:
		buyer_type = 'PROPERTY_OWNER_FROM_GAIAFLIX'


	# check if the plan is valid
	plan = None
	if 'plan' in post_data:
		plan = Plan.find_by_slug(post_data['plan'])
		if plan is None:
			abort(400, {'message': PLAN_INVALID_OR_NOT_PROVIDED })
	else:
		abort(400, {'message': PLAN_INVALID_OR_NOT_PROVIDED })

	# creates the lead
	lead = Lead()

	lead.sender_broker = sender_broker.key if sender_broker is not None else None
	lead.property_owner = owner.key if owner is not None else None
	lead.listing = listing.key if listing is not None else None
	lead.plan = plan.key
	lead.buyer_type = buyer_type
	lead.status = 'SENT'

	if lead.put():
		json_lead = lead.to_json()

		if lead.property_owner is not None:
			_enqueue_lead_message(json_lead)
			create_activity('LEAD_SENT', lead=lead)

		return jsonify(data=json_lead), 201
	else:
		return jsonify({'error': 'Error creating Lead'})
def _get_lead(id):
	lead = Lead.get_by_id(int(id))
	if lead is None:
		abort(404, { 'message': 'Lead not found'})
	else:
		return lead
def _search_lead_by_token(token):
	lead = Lead.find_by_key(token)
	if lead is None:
		abort(404, {'message': 'Lead not found'})
	else:
		return jsonify(data=lead.to_json())