def test_no_coupon_in_next(self): """ Test with a `next` url that doesn't have a coupon """ self.request.GET["next"] = "/dashboard" coupon = get_coupon_code(self.request) assert coupon is None
def test_coupon_in_wrong_next_url(self): """ We should ignore a coupon code that's not for the dashboard """ self.request.GET["next"] = "/profile?coupon=abc" coupon = get_coupon_code(self.request) assert coupon is None
def test_coupon_in_next_url(self): """ Test if the coupon is in the query string of the `next` url """ self.request.GET["next"] = "/dashboard?coupon=abc" coupon = get_coupon_code(self.request) assert coupon == "abc"
def get_context(self, request, *args, **kwargs): programs = Program.objects.filter(live=True).select_related('programpage').order_by("id") js_settings = { "gaTrackingID": settings.GA_TRACKING_ID, "host": webpack_dev_server_host(request), "environment": settings.ENVIRONMENT, "sentry_dsn": sentry.get_public_dsn(), "release_version": settings.VERSION } username = get_social_username(request.user) context = super(HomePage, self).get_context(request) def get_program_page(program): """Return a None if ProgramPage does not exist, to avoid template errors""" try: return program.programpage except ProgramPage.DoesNotExist: return None program_pairs = [(program, get_program_page(program)) for program in programs] context["programs"] = program_pairs context["is_public"] = True context["has_zendesk_widget"] = True context["google_maps_api"] = False context["authenticated"] = not request.user.is_anonymous context["is_staff"] = has_role(request.user, [Staff.ROLE_ID, Instructor.ROLE_ID]) context["username"] = username context["js_settings_json"] = json.dumps(js_settings) context["title"] = self.title context["ga_tracking_id"] = "" context["coupon_code"] = get_coupon_code(request) return context
def get_context(self, request, *args, **kwargs): programs = Program.objects.filter( live=True).select_related('programpage').order_by("id") benefits_page = BenefitsPage.objects.filter(live=True).first() js_settings = { "gaTrackingID": settings.GA_TRACKING_ID, "host": webpack_dev_server_host(request), "environment": settings.ENVIRONMENT, "sentry_dsn": settings.SENTRY_DSN, "release_version": settings.VERSION } username = get_social_username(request.user) context = super(HomePage, self).get_context(request) def get_program_page(program): """Return a None if ProgramPage does not exist, to avoid template errors""" try: return program.programpage except ProgramPage.DoesNotExist: return None program_pairs = [(program, get_program_page(program)) for program in programs] context["programs"] = program_pairs context["is_public"] = True context["has_zendesk_widget"] = True context["google_maps_api"] = False context["authenticated"] = not request.user.is_anonymous context["is_staff"] = has_role(request.user, [Staff.ROLE_ID, Instructor.ROLE_ID]) context["username"] = username context["js_settings_json"] = json.dumps(js_settings) context["title"] = self.title context["ga_tracking_id"] = "" context["coupon_code"] = get_coupon_code(request) context["benefits_url"] = benefits_page.get_url( ) if benefits_page else "" return context
def test_no_coupon(self): """ Test without a query string """ coupon = get_coupon_code(self.request) assert coupon is None