예제 #1
0
    def test_reports_yelp_business_detail(self):
        """Test that calling business detail on a business that has reports
           written about it includes details about that business.

           # TODO: MOCK out actual yelp API call."""

        u1 = User.register(email='*****@*****.**',
                           username='******', password='******')
        Business.create(
            name='Cuisine of Nepal', longitude=-122.42318,
            latitude=37.74097, id='iUockw0CUssKZLyoGJYEXA',
            city='San Francisco', state='CA', country='US')

        db.session.commit()

        Report.create(user_id=u1.id, text='Good fud.',
                      business_id='iUockw0CUssKZLyoGJYEXA')

        db.session.commit()

        with self.client as c:
            resp = c.get(
                '/v1/business_detail/iUockw0CUssKZLyoGJYEXA?name=Cuisine+of+Nepal&latlng=37.74097,-122.42318')  # noqa e501
            data = resp.get_json()

        self.assertEqual(resp.status_code, 200)
        self.assertIn('reports', data)
        self.assertEqual(data['reports'][0]['text'], 'Good fud.')
예제 #2
0
    def setUp(self):

        self.user = User.register(email="*****@*****.**",
                                  username="******",
                                  password="******")

        self.mission = Mission.create(editor=self.user.id,
                                      name="test mission",
                                      city="Albany",
                                      state="NY",
                                      country='US')

        self.business = Business.create(name='Cuisine of Nepal',
                                        longitude=-122.42318,
                                        latitude=37.74097,
                                        id='iUockw0CUssKZLyoGJYEXA',
                                        city='San Francisco',
                                        state='CA',
                                        country='US')

        self.mission.businesses.append(self.business)

        self.report = Report.create(user_id=self.user.id,
                                    business_id='iUockw0CUssKZLyoGJYEXA',
                                    text='Best nepalese food I ever had!')

        db.session.commit()

        self.report2 = Report.create(user_id=self.user.id,
                                     mission_id=self.mission.id,
                                     text='The curry was devine!')

        db.session.commit()
예제 #3
0
def create_marketing_report(channel_id="C022WMH56KA", mode="daily"):
    spend = (
        "Spend",
        [("FacebookSpend", "SUM"), ("GoogleSpend", "SUM"),
         ("FunnelSpend", "SUM")],
    )
    leads = (
        "Leads",
        [
            ("TotalLeads", "SUM"),
            ("UniqueLeads", "SUM"),
            ("PhonesCollected", "SUM"),
            ("CostPerLead", "AVG", "FunnelSpend", "TotalLeads"),
        ],
    )
    conversions = (
        "Conversions",
        [
            ("AcquiredCustomers", "SUM"),
            ("FunnelCR", "AVG", "AcquiredCustomers", "PhonesCollected"),
            ("FunnelRevenue", "SUM"),
            ("ROAS", "AVG", "FunnelRevenue", "FunnelSpend"),
        ],
    )
    report = Report.create("Marketing", mode, channel_id)
    report.add_section(*spend)
    report.add_section(*leads)
    report.add_section(*conversions)
    return report
예제 #4
0
def create_profit_report(channel_id="C022WMH56KA", mode="daily"):
    profit = (
        "Profit",
        [
            ("Sales", "SUM"),
            ("COGS", "SUM"),
            ("GrossProfit", "SUM"),
            ("GrossMargin", "AVG", "GrossProfit", "Sales"),
        ],
    )
    report = Report.create("Profit", mode, channel_id)
    report.add_section(*profit)
    return report
예제 #5
0
    def setUp(self):

        self.user = User.register(email="*****@*****.**",
                                  username="******",
                                  password="******")

        self.mission = Mission.create(editor=self.user.id,
                                      name="test mission",
                                      city="Albany",
                                      state="NY",
                                      country='US')
        self.mission.share()

        self.mission2 = Mission.create(editor=self.user.id,
                                       name="test mission 2",
                                       city="Ithica",
                                       state="NY",
                                       country='US')
        self.mission2.share()

        self.business = Business.create(name="Cusine of Nepal",
                                        id='82372347',
                                        city='San Francisco',
                                        state='CA',
                                        country='US',
                                        longitude=20.22,
                                        latitude=77.0)

        db.session.commit()

        self.report = Report.create(user_id=self.user.id,
                                    business_id=self.business.id,
                                    text="Amazing!")

        self.report = Report.create(user_id=self.user.id,
                                    mission_id=self.mission.id,
                                    text="Amazing Mission!")

        db.session.commit()
예제 #6
0
    def test_get_by_recent(self):

        report3 = Report.create(user_id=self.user.id,
                                business_id='iUockw0CUssKZLyoGJYEXA',
                                text='The curry was devine!')

        db.session.commit()
        report3.submitted_on = datetime.utcnow()
        db.session.commit()

        recent = Report.get_by_recent()

        self.assertEqual(len(recent), 3)
        self.assertEqual(recent[0], report3)
예제 #7
0
    def setUp(self):

        self.user = User.register(
            email='*****@*****.**',
            username='******', password='******')

        self.user2 = User.register(
            email='*****@*****.**',
            username='******', password='******')

        self.business = Business.create(
            name='Cuisine of Nepal', longitude=-122.42318, latitude=37.74097,
            id='iUockw0CUssKZLyoGJYEXA', city='San Francisco',
            state='CA', country='US')

        self.report = Report.create(
            user_id=self.user.id, business_id='iUockw0CUssKZLyoGJYEXA',
            text='Best dern nipplease fud i eva had!')

        db.session.commit()

        self.client = app.test_client()
예제 #8
0
def create_sales_report(channel_id="C022WMH56KA", mode="daily"):
    sales_order = (
        "SalesOrder",
        [
            ("SalesOrder", "SUM"),
            ("Transactions", "SUM"),
            ("AUSPMattress", "AVG", "SalesOrderMattress", "QuantityMattress"),
            ("StoreTraffic", "SUM"),
        ],
    )
    customers = (
        "Customers",
        [
            ("Customers", "SUM"),
            ("NewCustomers", "SUM"),
            ("AOVCustomers", "AVG", "SalesOrder", "Customers"),
        ],
    )
    report = Report.create("Sales", mode, channel_id)
    report.add_section(*sales_order)
    report.add_section(*customers)
    return report
예제 #9
0
def add_report():
    """Write Report View."""

    mission_id = request.args.get('mission_id')
    business_id = request.args.get('business_id')

    if mission_id and business_id:
        return BadRequest

    form = AddReportForm()

    if form.validate_on_submit():

        relevant_data = {
            k: v
            for k, v in form.data.items() if k in Report.set_get()
        }

        form, relevant_data, f, path = H.check_file_upload_logic(
            form, relevant_data)

        report = Report.create(user_id=g.user.id,
                               mission_id=mission_id,
                               business_id=business_id,
                               **relevant_data)

        try:
            db.session.commit()
            if f:
                S3_CLIENT.upload_fileobj(f, S3_BUCKET_NAME, path)
            flash("Report added!", 'success')
            return redirect(url_for('.report_detail', report_id=report.id))

        except Exception as e:
            db.session.rollback()
            flash("Error Creating Report!", 'danger')
            H.error_logging(e)

    existing_report = H.check_for_existing_report(mission_id, business_id)
    if existing_report:
        # redirect to edit_report view for this report and relay request args.
        request_ars = request.args.to_dict()
        return redirect(
            url_for('.edit_report',
                    report_id=existing_report.id,
                    **request_ars))

    if mission_id:
        kind = 'Mission'
        model = Mission.query.get_or_404(mission_id)
    else:
        kind = 'Business'
        model = Business.query.get(business_id)
        if not model:
            model = H.add_new_business(business_id, request.args)
            if model is False:
                return BadRequest

    if request.method == 'POST':
        flash("Please fix all form errors.", "warning")

    return render_template("reports_crud/add_report.html",
                           form=form,
                           model=model,
                           kind=kind)