Пример #1
0
 def setUpClass(cls):
     cls.app = new_app
     cls.app.app_context().push()
     db.create_all()
     cls.SHOP_OWNER_USER = models.User()
     shop = models.Shop(owner=cls.SHOP_OWNER_USER)
     shop_not_owned = models.Shop()
     db.session.add(shop)
     db.session.add(shop_not_owned)
     db.session.commit()
     cls.SHOP_ID = shop.id
     cls.SHOP_NOT_OWNED_ID = shop_not_owned.id
Пример #2
0
 def setUpClass(cls):
     cls.app = new_app
     cls.app.app_context().push()
     db.create_all()
     shop = models.Shop(domain=cls.SHOP_DOMAIN)
     db.session.add(shop)
     db.session.commit()
     cls.SHOP_ID = shop.id
Пример #3
0
    def test_set_email_notifications_no_products_in_order(self):
        order = models.Order.query.first()
        user_buyer = models.User(email=testing_constants.NEW_USER_EMAIL, name=testing_constants.NEW_USER_NAME)
        order.user = user_buyer
        user_shop_owner = models.User()
        models.Customer(user=user_shop_owner)
        shop = models.Shop(name=testing_constants.NEW_SHOP_NAME)
        shop.owner = user_shop_owner
        order.shop = shop
        order.shipment_timestamp = date_parser.parse(testing_constants.ORDER_SHIPPED_AT).astimezone(pytz.utc).replace(tzinfo=None)

        # The results from the asynchronous tasks are executed immediately
        with self.assertRaises(DbException):
            order.set_notifications()
Пример #4
0
    def test_create_review_request_repeated_products(self):
        order = models.Order.query.first()
        user_shop_owner = models.User()
        models.Customer(user=user_shop_owner)
        shop = models.Shop(name=testing_constants.NEW_SHOP_NAME)
        shop.owner = user_shop_owner
        order.shop = shop

        product1 = models.Product(platform_product_id=testing_constants.NEW_PRODUCT_PLATFORM_ID)
        product2 = models.Product(platform_product_id=testing_constants.NEW_PRODUCT_PLATFORM_ID_2)
        # add the first product twice
        order.products.append(product1)
        order.products.append(product1)  # not a typo!. << Good to know ;) -- T.
        order.products.append(product2)
        order.create_review_requests(order.id)
        self.assertEquals(len(order.review_requests), 2)
Пример #5
0
 def test_set_email_notifications_no_shipment_timestamp(self):
     order = models.Order.query.first()
     product = models.Product(name=testing_constants.NEW_PRODUCT_NAME, platform_product_id=testing_constants.NEW_PRODUCT_PLATFORM_ID)
     user_buyer = models.User(email=testing_constants.NEW_USER_EMAIL, name=testing_constants.NEW_USER_NAME)
     order.user = user_buyer
     user_shop_owner = models.User()
     models.Customer(user=user_shop_owner)
     shop = models.Shop(name=testing_constants.NEW_SHOP_NAME)
     shop.owner = user_shop_owner
     product.shop = shop
     order.shop = shop
     order.products.append(product)
     order.shipment_timestamp = None
     # The results from the asynchronous tasks are executed immediately
     with self.assertRaises(DbException):
         order.set_notifications()
Пример #6
0
    def test_set_email_notifications_no_buyer(self):
        order = models.Order.query.first()
        product = models.Product(name=testing_constants.NEW_PRODUCT_NAME, platform_product_id=testing_constants.NEW_PRODUCT_PLATFORM_ID)
        user_buyer = None
        order.user = user_buyer
        user_shop_owner = models.User()
        models.Customer(user=user_shop_owner)
        shop = models.Shop(name=testing_constants.NEW_SHOP_NAME)
        shop.owner = user_shop_owner
        product.shop = shop
        order.shop = shop
        order.products.append(product)
        order.shipment_timestamp = date_parser.parse(testing_constants.ORDER_SHIPPED_AT).astimezone(pytz.utc).replace(tzinfo=None)

        # The results from the asynchronous tasks are executed immediately
        with self.assertRaises(DbException):
            order.set_notifications()
Пример #7
0
    def test_get_order_by_id(self):
        order = models.Order.query.first()
        product = models.Product(name=testing_constants.NEW_PRODUCT_NAME, platform_product_id=testing_constants.NEW_PRODUCT_PLATFORM_ID)
        user_buyer = models.User(email=testing_constants.NEW_USER_EMAIL, name=testing_constants.NEW_USER_NAME)
        order.user = user_buyer
        user_shop_owner = models.User()
        models.Customer(user=user_shop_owner)
        shop = models.Shop(name=testing_constants.NEW_SHOP_NAME)
        shop.owner = user_shop_owner
        product.shop = shop
        order.shop = shop
        order.products.append(product)
        order.shipment_timestamp = date_parser.parse(testing_constants.ORDER_SHIPPED_AT).astimezone(pytz.utc).replace(tzinfo=None)
        order_id = order.id
        db.session.add(order)
        db.session.commit()

        retrieved_order = models.Order.get_by_id(order_id=order_id)
        self.assertTrue(retrieved_order is not None)
        self.assertTrue(isinstance(retrieved_order, models.Order))
Пример #8
0
    def test_create_review_request(self):
        user_buyer = models.User(email=testing_constants.NEW_USER_EMAIL, name=testing_constants.NEW_USER_NAME)
        user_shop_owner = models.User(is_shop_owner=True)
        order = models.Order()
        product = models.Product(name=testing_constants.NEW_PRODUCT_NAME, platform_product_id=testing_constants.NEW_PRODUCT_PLATFORM_ID)
        order.user = user_buyer
        customer = models.Customer(user=user_shop_owner)
        shop = models.Shop(name=testing_constants.NEW_SHOP_NAME)
        shop.owner = user_shop_owner
        product.shop = shop
        order.shop = shop
        order.products.append(product)

        #creates a review request and returns a token associated with it
        review_request_token = models.ReviewRequest.create(to_user=user_buyer, from_customer=customer,
                                                           for_product=product, for_shop=shop, for_order=order)
        review_request = models.ReviewRequest.query.filter_by(token=review_request_token).first()

        self.assertEqual(review_request.token, review_request_token)
        self.assertEqual(review_request.for_shop.name, shop.name)
        self.assertEqual(review_request.from_customer.user.is_shop_owner, user_shop_owner.is_shop_owner)
Пример #9
0
    def test_set_email_notifications(self):
        # setup an order
        order = models.Order.query.first()
        product = models.Product(name=testing_constants.NEW_PRODUCT_NAME, platform_product_id=testing_constants.NEW_PRODUCT_PLATFORM_ID)
        user_buyer = models.User(email=testing_constants.NEW_USER_EMAIL, name=testing_constants.NEW_USER_NAME)
        order.user = user_buyer
        user_shop_owner = models.User()
        models.Customer(user=user_shop_owner)
        shop = models.Shop(name=testing_constants.NEW_SHOP_NAME)
        shop.owner = user_shop_owner
        product.shop = shop
        order.shop = shop
        order.products.append(product)
        order.shipment_timestamp = date_parser.parse(testing_constants.ORDER_SHIPPED_AT).astimezone(pytz.utc).replace(tzinfo=None)

        # The results from the asynchronous tasks are executed immediately
        order.set_notifications()
        self.assertEquals(len(self.outbox), 1)
        self.assertEquals(len(self.outbox[0].send_to), 1)
        self.assertEquals(self.outbox[0].send_to.pop(), testing_constants.NEW_USER_EMAIL)
        self.assertEquals(self.outbox[0].subject, Constants.DEFAULT_REVIEW_SUBJECT %(testing_constants.NEW_USER_NAME.split()[0],
                          testing_constants.NEW_SHOP_NAME))
        self.assertTrue(testing_constants.NEW_USER_NAME.split()[0] in self.outbox[0].body)
        self.assertTrue(testing_constants.NEW_PRODUCT_NAME in self.outbox[0].body)
        self.assertTrue(testing_constants.NEW_SHOP_NAME in self.outbox[0].body)

        order = models.Order.query.first()

        expected_notification_ts = date_parser.parse(testing_constants.ORDER_SHIPPED_AT).astimezone(pytz.utc).replace(tzinfo=None) + \
                                   datetime.timedelta(days=Constants.DIFF_SHIPMENT_NOTIFY)

        self.assertEquals(order.status, Constants.ORDER_STATUS_NOTIFIED)
        self.assertEquals(order.to_notify_timestamp,expected_notification_ts)
        self.assertEquals(len(order.tasks), 2)
        for task in order.tasks:
            self.assertEquals(task.status, 'SUCCESS')
            self.assertEquals(task.eta, date_parser.parse('2015-12-16 18:56:26'))
Пример #10
0
    db.session.add(madeline_s)

    test_u = models.User(email="*****@*****.**", is_shop_owner=True)
    test_c = models.Customer(user=test_u,
                             stripe_customer_id="cus_8EAt4P3noce59l")
    test_s = models.Subscription(customer=test_c)
    db.session.add(test_s)

    now = datetime.datetime.utcnow()
    started = datetime.datetime(2016, 3, 22, 10, 32)
    osg_u = models.User(email="*****@*****.**",
                        is_shop_owner=True,
                        confirmed_at=started)
    osg_shop = models.Shop(
        name="Global Hair Extensions Australia",
        owner=osg_u,
        platform=platform_shopify,
        domain="global-hair-extensions-australia.myshopify.com")
    osg_c = models.Customer(user=osg_u,
                            stripe_customer_id="cus_8FvwOPDU6NgnuG",
                            active=True)
    trialed_for = (now - started).days
    osg_s = models.Subscription(customer=osg_c,
                                stripe_subscription_id="sub_8FvxLurv2KBxw3",
                                timestamp=started,
                                trialed_for=trialed_for)
    db.session.add(osg_s)
    db.session.add(osg_shop)

    # Uninstalled and Trialed for
    for cid in [