Beispiel #1
0
def create_mock_request():
    """
    Creates and returns a mock request object for testing.
    """
    request = RequestFactory()
    request.COOKIES = {}
    request.META = {}
    request.path = '/'
    return request
Beispiel #2
0
def get_request_for_user(user):
    """Create a request object for user."""
    request = RequestFactory()
    request.user = user
    request.COOKIES = {}
    request.META = {}
    request.is_secure = lambda: True
    request.get_host = lambda: "edx.org"
    request.method = 'GET'
    return request
Beispiel #3
0
 def generate_request(self):
     """
     Create http request
     """
     request = RequestFactory()
     request.COOKIES = {}
     request.META = {}
     request.user = AnonymousUser()
     SessionMiddleware().process_request(request)
     return request
Beispiel #4
0
    def test_get_kissmetrics_instance(self):
        request = RequestFactory()
        request.COOKIES = {}
        km_ai = '1234'
        km_ni = 'asdf'

        # invalid object
        self.assertRaises(ValueError, base.get_kissmetrics_instance, {})

        # no identity error
        self.assertRaises(ValueError, base.get_kissmetrics_instance, request)

        # fetch identity from the cookies
        request.COOKIES = {'km_ai': km_ai, 'km_ni': km_ni}
        km = base.get_kissmetrics_instance(request)
        self.assertEquals(km_ni, km._id)

        # fetch the identity from the user
        request.user = self.user
        km = base.get_kissmetrics_instance(request)
        self.assertEquals(self.user.id, km._id)
Beispiel #5
0
    def create_coupon(
            self,
            title='Test coupon',
            price=100,
            client=None,
            partner=None,
            catalog=None,
            code='',
            benefit_value=100,
            note=None,
            max_uses=None,
            quantity=5
    ):
        """Helper method for creating a coupon.

        Arguments:
            title(str): Title of the coupon
            price(int): Price of the coupon
            partner(Partner): Partner used for creating a catalog
            catalog(Catalog): Catalog of courses for which the coupon applies
            code(str): Custom coupon code
            benefit_value(int): The voucher benefit value

        Returns:
            coupon (Coupon)

        """
        if partner is None:
            partner = PartnerFactory(name='Tester')
        if client is None:
            client, __ = BusinessClient.objects.get_or_create(name='Test Client')
        if catalog is None:
            catalog = Catalog.objects.create(partner=partner)
        if code is not '':
            quantity = 1
        data = {
            'partner': partner,
            'benefit_type': Benefit.PERCENTAGE,
            'benefit_value': benefit_value,
            'catalog': catalog,
            'end_date': datetime.date(2020, 1, 1),
            'code': code,
            'quantity': quantity,
            'start_date': datetime.date(2015, 1, 1),
            'voucher_type': Voucher.SINGLE_USE,
            'categories': [self.category],
            'note': note,
            'max_uses': max_uses,
        }

        coupon = CouponViewSet().create_coupon_product(
            title=title,
            price=price,
            data=data
        )

        request = RequestFactory()
        request.site = self.site
        request.user = factories.UserFactory()
        request.COOKIES = {}

        self.basket = prepare_basket(request, coupon)

        self.response_data = CouponViewSet().create_order_for_invoice(self.basket, coupon_id=coupon.id, client=client)
        coupon.client = client

        return coupon
 def test_only_code(self):
     """GeoIP code is included when the country name is missing."""
     req = RequestFactory()
     req.COOKIES = {"geoip_country_code": "US"}
     val = geoip_cache_detector(req)
     eq_(val["include_geoip"], True)
 def test_when_both(self):
     """GeoIP code is not included when both name and code already exist."""
     req = RequestFactory()
     req.COOKIES = {"geoip_country_name": "United States", "geoip_country_code": "US"}
     val = geoip_cache_detector(req)
     eq_(val["include_geoip"], False)