示例#1
0
 def test_YOTPO_import_reviews_verified_review(self):
     self.refresh_db()
     p = Product(shop_id=self.yotpo_shop.id,
                 name=testing_constants.NEW_PRODUCT_NAME)
     user_legacy = UserLegacy(name=testing_constants.ORDER_USER_NAME,
                              email=testing_constants.ORDER_USER_EMAIL)
     o = Order(user_legacy=user_legacy,
               shop=self.yotpo_shop,
               status=Constants.ORDER_STATUS_NOTIFIED)
     o.products.append(p)
     db.session.add(p)
     db.session.add(o)
     db.session.commit()
     before_count = len(Review.query.all())
     self.yotpo_importer.import_reviews(
         testing_constants.YOTPO_REVIEWS_CSV_FILEPATH)
     after_count = len(Review.query.all())
     r = Review.query.filter_by(user_legacy=user_legacy).first()
     self.assertEqual(after_count, before_count + 2)
     self.assertNotEqual(r, None)
     self.assertEqual(r.body, testing_constants.NEW_REVIEW_BODY)
     self.assertEqual(r.product, p)
     self.assertEqual(r.star_rating, 4)
     self.assertEqual(
         r.created_ts,
         parse(
             testing_constants.YOTPO_REVIEW_TIMESTAMP).replace(tzinfo=None))
     self.assertEqual(r.youtube_video, None)
     self.assertTrue(r.verified_review)
示例#2
0
    def create_or_match_user_from_review_data(cls, reviewer_name, email):
        user = None
        existing_user = User.get_by_email_no_exception(email)
        if existing_user:
            user = existing_user
        else:
            user, is_new = UserLegacy.get_or_create_by_email(email, name=reviewer_name)

        return user
示例#3
0
    def create_or_match_user_from_review_data(cls, reviewer_name, email):
        user = None
        existing_user = User.get_by_email_no_exception(email)
        if existing_user:
            user = existing_user
        else:
            user, is_new = UserLegacy.get_or_create_by_email(
                email, name=reviewer_name)

        return user
示例#4
0
 def test_shopify_import_get_or_create_legacy_user_exists(self):
     self.refresh_db()
     user_legacy = UserLegacy(name=testing_constants.ORDER_USER_NAME,
                              email=testing_constants.ORDER_USER_EMAIL)
     db.session.add(user_legacy)
     db.session.commit()
     reviews = self.shopify_importer.csv_to_dicts_SHOPIFY(
         testing_constants.SHOPIFY_REVIEWS_CSV_FILEPATH)
     review_row_1 = reviews[0]
     user = self.shopify_importer.create_or_match_user_from_review_data(
         review_row_1["author"], review_row_1["email"])
     self.assertTrue(isinstance(user, UserLegacy))
     self.assertEqual(user.email, testing_constants.ORDER_USER_EMAIL)
     self.assertEqual(user.name, testing_constants.ORDER_USER_NAME)
     self.assertEqual(
         len(
             UserLegacy.query.filter_by(
                 email=testing_constants.ORDER_USER_EMAIL).all()), 1)
示例#5
0
    def test_fetch_new_and_updated_orders_already_exist_but_not_shipped(self):
        # setup with existing product 0,1,2
        user_shop_owner = User(email=testing_constants.NEW_USER_EMAIL)
        Customer(user=user_shop_owner)
        shop = Shop(name=testing_constants.MAGENTO_SHOP_NAME)
        shop.owner = user_shop_owner
        product0 = Product(platform_product_id=testing_constants.MAGENTO_PRODUCT_0_PLATFORM_PRODUCT_ID,
                           name=testing_constants.MAGENTO_PRODUCT_0_NAME,
                           active=True,
                           short_description=testing_constants.MAGENTO_PRODUCT_0_DESCRIPTION)

        product1 = Product(platform_product_id=testing_constants.MAGENTO_PRODUCT_1_PLATFORM_PRODUCT_ID,
                           name=testing_constants.MAGENTO_PRODUCT_1_NAME,
                           active=True,
                           short_description=testing_constants.MAGENTO_PRODUCT_1_DESCRIPTION)

        product2 = Product(platform_product_id=testing_constants.MAGENTO_PRODUCT_2_PLATFORM_PRODUCT_ID,
                           name=testing_constants.MAGENTO_PRODUCT_2_NAME,
                           active=False,
                           short_description=testing_constants.MAGENTO_PRODUCT_2_DESCRIPTION)

        order0_user_legacy = UserLegacy(email=testing_constants.MAGENTO_ORDER_0_EMAIL,
                                        name=testing_constants.MAGENTO_ORDER_0_NAME)
        order0 = Order(platform_order_id=testing_constants.MAGENTO_ORDER_0_PLATFORM_ORDER_ID,
                       status=Constants.ORDER_STATUS_PURCHASED,
                       purchase_timestamp=testing_constants.MAGENTO_ORDER_0_CREATED,
                       user_legacy=order0_user_legacy)
        order0.products.append(product0)

        order1_user_legacy = UserLegacy(email=testing_constants.MAGENTO_ORDER_1_EMAIL,
                                        name=testing_constants.MAGENTO_ORDER_1_NAME)
        order1 = Order(platform_order_id=testing_constants.MAGENTO_ORDER_1_PLATFORM_ORDER_ID,
                       status=Constants.ORDER_STATUS_PURCHASED,
                       purchase_timestamp=testing_constants.MAGENTO_ORDER_1_CREATED,
                       user_legacy=order1_user_legacy)
        order1.products.append(product0)
        order1.products.append(product1)

        order2_user_legacy = UserLegacy(email=testing_constants.MAGENTO_ORDER_2_EMAIL,
                                        name=testing_constants.MAGENTO_ORDER_2_NAME)
        order2 = Order(platform_order_id=testing_constants.MAGENTO_ORDER_2_PLATFORM_ORDER_ID,
                       status=Constants.ORDER_STATUS_PURCHASED,
                       purchase_timestamp=testing_constants.MAGENTO_ORDER_2_CREATED,
                       user_legacy=order2_user_legacy)

        shop.products.append(product0)
        shop.products.append(product1)
        shop.products.append(product2)
        shop.orders.append(order0)
        shop.orders.append(order1)
        shop.orders.append(order2)
        db.session.add(shop)
        db.session.commit()

        # test
        api = magento_api.API()
        current_orders = Order.query.filter_by(shop_id=shop.id).all()
        new_and_updated = api.fetch_new_and_updated_orders(current_orders, shop)
        self.assertEquals(len(new_and_updated), 1)
        db.session.add_all(new_and_updated)
        db.session.commit()

        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.MAGENTO_ORDER_1_EMAIL)
        self.assertEquals(self.outbox[0].subject,
                          Constants.DEFAULT_REVIEW_SUBJECT % (testing_constants.MAGENTO_ORDER_1_NAME.split()[0],
                                                              testing_constants.MAGENTO_SHOP_NAME))
        self.assertTrue(testing_constants.MAGENTO_ORDER_1_NAME.split()[0] in self.outbox[0].body)
        self.assertTrue(testing_constants.MAGENTO_PRODUCT_0_NAME in self.outbox[0].body)
        self.assertTrue(testing_constants.MAGENTO_PRODUCT_1_NAME in self.outbox[0].body)
        self.assertTrue(testing_constants.MAGENTO_SHOP_NAME in self.outbox[0].body)

        self.assertEquals(new_and_updated[0].platform_order_id, testing_constants.MAGENTO_ORDER_1_PLATFORM_ORDER_ID)
        self.assertEquals(new_and_updated[0].status, Constants.ORDER_STATUS_NOTIFIED)
        self.assertEquals(new_and_updated[0].purchase_timestamp,
                          datetime.datetime.strptime(testing_constants.MAGENTO_ORDER_1_CREATED, '%Y-%m-%d %H:%M:%S'))
        self.assertEquals(new_and_updated[0].shipment_timestamp,
                          datetime.datetime.strptime(testing_constants.MAGENTO_ORDER_1_SHIPPED, '%Y-%m-%d %H:%M:%S'))
        self.assertEquals(len(new_and_updated[0].products), 2)
        self.assertIsNotNone(new_and_updated[0].products[0])
        self.assertEquals(new_and_updated[0].products[0].platform_product_id,
                          testing_constants.MAGENTO_PRODUCT_0_PLATFORM_PRODUCT_ID)
        self.assertIsNotNone(new_and_updated[0].products[1])
        self.assertEquals(new_and_updated[0].products[1].platform_product_id,
                          testing_constants.MAGENTO_PRODUCT_1_PLATFORM_PRODUCT_ID)
        self.assertEquals(len(new_and_updated[0].tasks), 2)
        self.assertEquals(new_and_updated[0].tasks[0].method, 'notify_for_review')
        self.assertEquals(str(new_and_updated[0].tasks[0].eta), '2015-12-19 12:00:00')
        self.assertEquals(new_and_updated[0].tasks[1].method, 'send_email')
        self.assertEquals(str(new_and_updated[0].tasks[1].eta), '2015-12-19 12:00:00')
        self.assertIsNotNone(new_and_updated[0].user_legacy)
        self.assertEquals(new_and_updated[0].user_legacy.email, testing_constants.MAGENTO_ORDER_1_EMAIL)
        self.assertEquals(new_and_updated[0].user_legacy.name, testing_constants.MAGENTO_ORDER_1_NAME)

        # tear down
        user = User.query.filter_by(email=testing_constants.NEW_USER_EMAIL).first()
        customer = user.customer[0]
        shop = Shop.query.filter_by(name=testing_constants.MAGENTO_SHOP_NAME).first()
        orders = Order.query.all()

        for product in shop.products:
            db.session.delete(product)
        db.session.delete(user)
        db.session.delete(customer)
        db.session.delete(shop)
        db.session.delete(shop)
        for order in orders:
            for review_request in order.review_requests:
                db.session.delete(review_request)
            db.session.delete(order)
        db.session.commit()
示例#6
0
    def test_fetch_new_and_updated_orders_already_exist(self):
        # setup with existing product 0,1,2
        user_shop_owner = User(email=testing_constants.NEW_USER_EMAIL)
        Customer(user=user_shop_owner)
        shop = Shop(name=testing_constants.MAGENTO_SHOP_NAME)
        shop.owner = user_shop_owner
        product0 = Product(platform_product_id=testing_constants.MAGENTO_PRODUCT_0_PLATFORM_PRODUCT_ID,
                           name=testing_constants.MAGENTO_PRODUCT_0_NAME,
                           active=True,
                           short_description=testing_constants.MAGENTO_PRODUCT_0_DESCRIPTION)

        product1 = Product(platform_product_id=testing_constants.MAGENTO_PRODUCT_1_PLATFORM_PRODUCT_ID,
                           name=testing_constants.MAGENTO_PRODUCT_1_NAME,
                           active=True,
                           short_description=testing_constants.MAGENTO_PRODUCT_1_DESCRIPTION)

        product2 = Product(platform_product_id=testing_constants.MAGENTO_PRODUCT_2_PLATFORM_PRODUCT_ID,
                           name=testing_constants.MAGENTO_PRODUCT_2_NAME,
                           active=False,
                           short_description=testing_constants.MAGENTO_PRODUCT_2_DESCRIPTION)

        order0_user_legacy = UserLegacy(email=testing_constants.MAGENTO_ORDER_0_EMAIL,
                                        name=testing_constants.MAGENTO_ORDER_0_NAME)
        order0 = Order(platform_order_id=testing_constants.MAGENTO_ORDER_0_PLATFORM_ORDER_ID,
                       status=Constants.ORDER_STATUS_PURCHASED,
                       purchase_timestamp=testing_constants.MAGENTO_ORDER_0_CREATED,
                       user_legacy=order0_user_legacy)
        order0.products.append(product0)

        order1_user_legacy = UserLegacy(email=testing_constants.MAGENTO_ORDER_1_EMAIL,
                                        name=testing_constants.MAGENTO_ORDER_1_NAME)
        order1 = Order(platform_order_id=testing_constants.MAGENTO_ORDER_1_PLATFORM_ORDER_ID,
                       status=Constants.ORDER_STATUS_NOTIFIED,
                       purchase_timestamp=testing_constants.MAGENTO_ORDER_1_CREATED,
                       shipment_timestamp=testing_constants.MAGENTO_ORDER_1_SHIPPED,
                       user_legacy=order1_user_legacy)
        order1.products.append(product0)
        order1.products.append(product1)

        order2_user_legacy = UserLegacy(email=testing_constants.MAGENTO_ORDER_2_EMAIL,
                                        name=testing_constants.MAGENTO_ORDER_2_NAME)
        order2 = Order(platform_order_id=testing_constants.MAGENTO_ORDER_2_PLATFORM_ORDER_ID,
                       status=Constants.ORDER_STATUS_PURCHASED,
                       purchase_timestamp=testing_constants.MAGENTO_ORDER_2_CREATED,
                       user_legacy=order2_user_legacy)

        shop.products.append(product0)
        shop.products.append(product1)
        shop.products.append(product2)
        shop.orders.append(order0)
        shop.orders.append(order1)
        shop.orders.append(order2)
        db.session.add(shop)
        db.session.commit()

        # test
        api = magento_api.API()
        current_orders = Order.query.filter_by(shop_id=shop.id).all()
        new_and_updated = api.fetch_new_and_updated_orders(current_orders, shop)
        self.assertEquals(len(new_and_updated), 0)

        # tear down
        user = User.query.filter_by(email=testing_constants.NEW_USER_EMAIL).first()
        customer = user.customer[0]
        shop = Shop.query.filter_by(name=testing_constants.MAGENTO_SHOP_NAME).first()
        orders = Order.query.all()

        for product in shop.products:
            db.session.delete(product)
        db.session.delete(user)
        db.session.delete(customer)
        db.session.delete(shop)
        db.session.delete(shop)
        for order in orders:
            for review_request in order.review_requests:
                db.session.delete(review_request)
            db.session.delete(order)
        db.session.commit()