from django.conf.urls import url
from django.http import HttpResponse
from django.shortcuts import redirect
from django.contrib import admin
from django.contrib.auth.decorators import login_required
from django.urls import reverse

from tests.fake_webapp import (
    EXAMPLE_HTML,
    EXAMPLE_IFRAME_HTML,
    EXAMPLE_ALERT_HTML,
    EXAMPLE_TYPE_HTML,
    EXAMPLE_NO_BODY_HTML,
    EXAMPLE_POPUP_HTML,
    EXAMPLE_REDIRECT_LOCATION_HTML,
)


admin.autodiscover()


def index(request):
    return HttpResponse(EXAMPLE_HTML)


def iframed(request):
    return HttpResponse(EXAMPLE_IFRAME_HTML)


def alertd(request):
    return HttpResponse(EXAMPLE_ALERT_HTML)


def type(request):
    return HttpResponse(EXAMPLE_TYPE_HTML)


def no_body(request):
    return HttpResponse(EXAMPLE_NO_BODY_HTML)


def get_name(request):
    return HttpResponse("My name is: Master Splinter")


def get_user_agent(request):
    return HttpResponse(request.META["User-Agent"])


def post_form(request):
    items = "\n".join("{}: {}".format(*item) for item in request.POST.items())
    body = "<html><body>{}</body></html>".format(items)
    return HttpResponse(body)


def request_headers(request):
    body = "\n".join(
        "%s: %s" % (key, value) for key, value in request.META.items()
    )
    return HttpResponse(body)


def upload_file(request):
    if request.method == "POST":
        f = request.FILES["file"]
        buffer = [
            "Content-type: {}".format(f.content_type),
            "File content: {}".format(f.read()),
        ]
        return HttpResponse("|".join(buffer))


def foo(request):
    return HttpResponse("BAR!")


def query_string(request):
    if request.query_string == "model":
        return HttpResponse("query string is valid")
    else:
        raise Exception("500")


def popup(request):
    return HttpResponse(EXAMPLE_POPUP_HTML)


@login_required
def auth_required(request):
    return HttpResponse("Success!")


def redirected(request):
    location = "{}?{}".format(reverse("redirect_location"), "come=get&some=true")
    return redirect(location)


def redirect_location(request):
    return HttpResponse(EXAMPLE_REDIRECT_LOCATION_HTML)


urlpatterns = [
    url(r"^$", index),
    url(r"^iframe$", iframed),
    url(r"^alert$", alertd),
    url(r"^type$", type),
    url(r"^no_body$", no_body),
    url(r"^name$", get_name),
    url(r"^useragent$", get_user_agent),
    url(r"^headers$", request_headers),
    url(r"^upload$", upload_file),
    url(r"^foo$", foo),
    url(r"^query$", query_string),
    url(r"^popup$", popup),
    url(r"^authenticate$", auth_required),
    url(r"^redirected", redirected),
    url(r"^post", post_form),
    url(r"^redirect-location", redirect_location, name="redirect_location"),
]

urlpatterns.append(url(r"^admin/", admin.site.urls))

@@ -1,37 +1,4 @@
-from django.conf.urls import url%0A
 from
@@ -182,16 +182,25 @@
 s import
+ re_path,
  reverse
@@ -2163,27 +2163,31 @@
 rns = %5B%0A    
-url
+re_path
 (r%22%5E$%22, inde
@@ -2190,27 +2190,31 @@
 index),%0A    
-url
+re_path
 (r%22%5Eiframe$%22
@@ -2225,27 +2225,31 @@
 ramed),%0A    
-url
+re_path
 (r%22%5Ealert$%22,
@@ -2258,27 +2258,31 @@
 lertd),%0A    
-url
+re_path
 (r%22%5Etype$%22, 
@@ -2288,27 +2288,31 @@
  type),%0A    
-url
+re_path
 (r%22%5Eno_body$
@@ -2324,27 +2324,31 @@
 _body),%0A    
-url
+re_path
 (r%22%5Ename$%22, 
@@ -2358,27 +2358,31 @@
 _name),%0A    
-url
+re_path
 (r%22%5Euseragen
@@ -2403,27 +2403,31 @@
 agent),%0A    
-url
+re_path
 (r%22%5Eheaders$
@@ -2447,27 +2447,31 @@
 aders),%0A    
-url
+re_path
 (r%22%5Eupload$%22
@@ -2486,27 +2486,31 @@
 _file),%0A    
-url
+re_path
 (r%22%5Efoo$%22, f
@@ -2514,27 +2514,31 @@
 , foo),%0A    
-url
+re_path
 (r%22%5Equery$%22,
@@ -2553,27 +2553,31 @@
 tring),%0A    
-url
+re_path
 (r%22%5Epopup$%22,
@@ -2585,27 +2585,31 @@
 popup),%0A    
-url
+re_path
 (r%22%5Eauthenti
@@ -2632,27 +2632,31 @@
 uired),%0A    
-url
+re_path
 (r%22%5Eredirect
@@ -2673,27 +2673,31 @@
 ected),%0A    
-url
+re_path
 (r%22%5Epost%22, p
@@ -2711,19 +2711,23 @@
 m),%0A    
-url
+re_path
 (r%22%5Eredi
@@ -2810,19 +2810,23 @@
 .append(
-url
+re_path
 (r%22%5Eadmi

Replace deprecated calls in fake_django to django.conf.urls.ur… (#959)