Ejemplo n.º 1
0
 def setUp(self):
     self.gateway = EasyRec("http://some.com", 'tenant', 'key')
     self.listeners = EasyRecListeners(self.gateway)
     self.maxDiff = 1000
Ejemplo n.º 2
0
class EasyRecListenersTest(TestCase):
    def setUp(self):
        self.gateway = EasyRec("http://some.com", 'tenant', 'key')
        self.listeners = EasyRecListeners(self.gateway)
        self.maxDiff = 1000

    @httprettified
    def test_on_product_view(self):
        HTTPretty.register_uri(HTTPretty.GET,
                               "http://some.com/api/1.0/json/itemtypes",
                               body='{"itemTypes": {"itemType": ["ITEM"]}}',
                               content_type="application/json")
        HTTPretty.register_uri(HTTPretty.GET,
                               "http://some.com/api/1.0/json/view",
                               body='{"bob": "hoskin"}',
                               content_type="application/json")

        user = get_auth_user_mock()
        product = get_product_mock()
        request = get_mock_request()

        expected = {
            'itemid': ['12345'],
            'apikey': ['key'],
            'itemtype': ['ITEM'],
            'userid': ["1"],
            'itemdescription': ['Product Title'],
            'itemurl': ['http://a.test.com/product/product-title-12345'],
            'sessionid': ['287384'],
            'tenantid': ['tenant'],
            'itemimageurl': ['http://a.test.com/images/12345.jpg']
        }

        self.listeners.on_product_view(self, product, user, request)
        get_params = HTTPretty.last_request.querystring
        self.assertEqual(get_params, expected)

    @httprettified
    def test_on_post_checkout(self):
        HTTPretty.register_uri(HTTPretty.GET,
                               "http://some.com/api/1.0/json/itemtypes",
                               body='{"itemTypes": {"itemType": ["ITEM"]}}',
                               content_type="application/json")
        HTTPretty.register_uri(HTTPretty.GET,
                               "http://some.com/api/1.0/json/buy",
                               body='{"bob": "hoskin"}',
                               content_type="application/json")
        user = get_auth_user_mock()
        order = get_mock_order()
        request = get_mock_request()

        expected = {
            'itemid': ['12345'],
            'apikey': ['key'],
            'itemtype': ['ITEM'],
            'userid': ["1"],
            'itemdescription': ['Product Title'],
            'itemurl': ['http://a.test.com/product/product-title-12345'],
            'sessionid': ['287384'],
            'actiontime': ['01_01_1970_00_01_40'],
            'tenantid': ['tenant'],
            'itemimageurl': ['http://a.test.com/images/12345.jpg']
        }

        self.listeners.on_post_checkout(self, order, user, request, None)
        get_params = HTTPretty.last_request.querystring
        self.assertEqual(get_params, expected)

    @httprettified
    def test_on_review_added(self):
        HTTPretty.register_uri(HTTPretty.GET,
                               "http://some.com/api/1.0/json/itemtypes",
                               body='{"itemTypes": {"itemType": ["ITEM"]}}',
                               content_type="application/json")
        HTTPretty.register_uri(HTTPretty.GET,
                               "http://some.com/api/1.0/json/rate",
                               body='{"bob": "hoskin"}',
                               content_type="application/json")

        expected = {
            'itemid': ['12345'],
            'apikey': ['key'],
            'itemtype': ['ITEM'],
            'userid': ["1"],
            'itemdescription': ['Product Title'],
            'itemurl': ['http://a.test.com/product/product-title-12345'],
            'sessionid': ['287384'],
            'actiontime': ['01_01_1970_00_01_40'],
            'tenantid': ['tenant'],
            'ratingvalue': ['4'],
            'itemimageurl': ['http://a.test.com/images/12345.jpg']
        }

        user = get_auth_user_mock()
        review = get_mock_review()
        request = get_mock_request()
        self.listeners.on_review_added(self, review, user, request)
        get_params = HTTPretty.last_request.querystring
        self.assertEqual(get_params, expected)
 def setUp(self):
     self.gateway = EasyRec("http://some.com", 'tenant', 'key')
     self.listeners = EasyRecListeners(self.gateway)
     self.maxDiff=1000
class EasyRecListenersTest(TestCase):

    def setUp(self):
        self.gateway = EasyRec("http://some.com", 'tenant', 'key')
        self.listeners = EasyRecListeners(self.gateway)
        self.maxDiff=1000

    @httprettified
    def test_on_product_view(self):
        HTTPretty.register_uri(HTTPretty.GET, "http://some.com/api/1.0/json/itemtypes",
                           body='{"itemTypes": {"itemType": ["ITEM"]}}',
                           content_type="application/json")
        HTTPretty.register_uri(HTTPretty.GET, "http://some.com/api/1.0/json/view",
                           body='{"bob": "hoskin"}',
                           content_type="application/json")

        user = get_auth_user_mock()
        product = get_product_mock()
        request = get_mock_request()

        expected  = {
            'itemid': ['12345'],
            'apikey': ['key'],
            'itemtype': ['ITEM'],
            'userid': ["1"],
            'itemdescription': ['Product Title'],
            'itemurl': ['http://a.test.com/product/product-title-12345'],
            'sessionid': ['287384'],
            'tenantid': ['tenant'],
            'itemimageurl': ['http://a.test.com/images/12345.jpg']
        }

        self.listeners.on_product_view(self, product, user, request)
        get_params = HTTPretty.last_request.querystring
        self.assertEqual(get_params, expected)

    @httprettified
    def test_on_post_checkout(self):
        HTTPretty.register_uri(HTTPretty.GET, "http://some.com/api/1.0/json/itemtypes",
                           body='{"itemTypes": {"itemType": ["ITEM"]}}',
                           content_type="application/json")
        HTTPretty.register_uri(HTTPretty.GET, "http://some.com/api/1.0/json/buy",
                           body='{"bob": "hoskin"}',
                           content_type="application/json")
        user = get_auth_user_mock()
        order = get_mock_order()
        request = get_mock_request()

        expected = {
            'itemid': ['12345'],
            'apikey': ['key'],
            'itemtype': ['ITEM'],
            'userid': ["1"],
            'itemdescription': ['Product Title'],
            'itemurl': ['http://a.test.com/product/product-title-12345'],
            'sessionid': ['287384'],
            'actiontime': ['01_01_1970_00_01_40'],
            'tenantid': ['tenant'],
            'itemimageurl': ['http://a.test.com/images/12345.jpg']
        }


        self.listeners.on_post_checkout(self, order, user, request, None)
        get_params = HTTPretty.last_request.querystring
        self.assertEqual(get_params, expected)

    @httprettified
    def test_on_review_added(self):
        HTTPretty.register_uri(HTTPretty.GET, "http://some.com/api/1.0/json/itemtypes",
                           body='{"itemTypes": {"itemType": ["ITEM"]}}',
                           content_type="application/json")
        HTTPretty.register_uri(HTTPretty.GET, "http://some.com/api/1.0/json/rate",
                           body='{"bob": "hoskin"}',
                           content_type="application/json")

        expected = {
            'itemid': ['12345'],
            'apikey': ['key'],
            'itemtype': ['ITEM'],
            'userid': ["1"],
            'itemdescription': ['Product Title'],
            'itemurl': ['http://a.test.com/product/product-title-12345'],
            'sessionid': ['287384'],
            'actiontime': ['01_01_1970_00_01_40'],
            'tenantid': ['tenant'],
            'ratingvalue': ['4'],
            'itemimageurl': ['http://a.test.com/images/12345.jpg']
        }

        user = get_auth_user_mock()
        review = get_mock_review()
        request = get_mock_request()
        self.listeners.on_review_added(self, review, user, request)
        get_params = HTTPretty.last_request.querystring
        self.assertEqual(get_params, expected)
Ejemplo n.º 5
0
from easyrec.receivers import EasyRecListeners
from easyrec.utils import get_gateway

easyrec = get_gateway()
listeners = EasyRecListeners(easyrec)
listeners.register_listeners()
Ejemplo n.º 6
0
from django.core.management.base import BaseCommand
from django.db.models import get_model

from easyrec.utils import get_gateway
from easyrec.receivers import EasyRecListeners

Order = get_model('order', 'Order')
listeners = EasyRecListeners(get_gateway())


class Command(BaseCommand):

    help = "Import all existing orders into EasyRec"

    def handle(self, *args, **options):
        self.stdout.write('Starting order import')
        self.stdout.write('Found %d orders to import', Order.objects.count())
        imported = 0
        skipped = 0
        for order in Order.objects.all():
            if order.is_anonymous:
                skipped += 1
                continue
            user = order.user
            listeners.on_order_placed(self, order, user)
            imported += 1
        self.stdout.write('Import completed (%d imports, %d skipped)',
                          (imported, skipped))