def record(request, id): record_instance = common.models.Record.objects.get(pk=id) def get(): return JsonResponse(serializers.serialize('json', record_instance)) return resolve_http_method(request, [get])
def test_resolve_http_method_with_list(self): fake_request = FancyHash({"method":"GET"}) def get(): return HttpResponse("hello there") response = resolve_http_method(fake_request, [get]) self.assertEqual(response.content, "hello there")
def song(request, id): song_instance = common.models.Song.objects.get(pk=id) def get(): return JsonResponse(serializers.serialize('json', song_instance)) return resolve_http_method(request, [get])
def author(request, id): author_instance = common.models.Author.objects.get(pk=id) def get(): return JsonResponse(serializers.serialize('json', author_instance)) return resolve_http_method(request, [get])
def test_resolve_http_method_with_list(self): fake_request = FancyHash({"method": "GET"}) def get(): return HttpResponse("hello there") response = resolve_http_method(fake_request, [get]) self.assertEqual(response.content, "hello there")
def search(request, id): search_instance = common.models.Search.objects.get(pk=id) def get(request): return JsonResponse(jsonify(search_instance)) return resolve_http_method(request, [get])
def upload(request): def post(): uploaded = UploadedMedia.objects.create( filename = "NA", file = request.FILES['file']) return jsonify({"filename": uploaded.file.name, "filelink": uploaded.file.url}) return resolve_http_method(request, [post])
def test_resolve_http_method_with_dict(self): fake_request = FancyHash({"method":"GET"}) def get(): return HttpResponse("hello there") def real_get(): return HttpResponse("real hello there") response = resolve_http_method(fake_request, {"get":real_get}) self.assertEqual(response.content, "real hello there")
def test_resolve_http_method_with_dict(self): fake_request = FancyHash({"method": "GET"}) def get(): return HttpResponse("hello there") def real_get(): return HttpResponse("real hello there") response = resolve_http_method(fake_request, {"get": real_get}) self.assertEqual(response.content, "real hello there")
def searches(request): def post(): s = common.models.Search(q=request.GET['q']) s.user = request.user s.save() return JsonResponse(jsonify(s.results())) def get(): searches_by_user = common.models.Search.filter(user = request.user) return JsonResponse(jsonify(searches_by_user)) return resolve_http_method(request, [get, post])
def register(request): new_user_form = UserRegistrationForm() c = { "registration_form": new_user_form } c.update(csrf(request)) def get(): return render(request, 'registration/register.html', c) def post(): new_user_form = UserRegistrationForm(request.POST) c.update({ "registration_form": new_user_form }) if new_user_form.is_valid(): new_user_form.save() return redirect("login") return render(request, 'registration/register.html', c) return resolve_http_method(request, [get, post])
def register(request): new_user_form = UserRegistrationForm() c = {"registration_form": new_user_form} c.update(csrf(request)) def get(): return render(request, 'registration/register.html', c) def post(): new_user_form = UserRegistrationForm(request.POST) c.update({"registration_form": new_user_form}) if new_user_form.is_valid(): new_user_form.save() return redirect("login") return render(request, 'registration/register.html', c) return resolve_http_method(request, [get, post])
def contact(request): c = standard_context() def get(): c.update({'contact_form': ContactForm()}) return render(request, 'pages/contact.html', c) def post(): contact_form = ContactForm(request.POST) if contact_form.is_valid(): contact_form.send_mail() messages.add_message(request, messages.SUCCESS, "Email Sent!") return redirect(request.path) c.update({'contact_form': contact_form}) return render(request, 'pages/contact.html', c) return resolve_http_method(request, [get, post])
def test_resolve_http_method_returns_501_when_method_not_found(self): fake_request = FancyHash({"method":"GET"}) response = resolve_http_method(fake_request, locals()) self.assertEqual(response.status_code, 501)
def test_resolve_http_method_returns_501_when_method_not_found(self): fake_request = FancyHash({"method": "GET"}) response = resolve_http_method(fake_request, locals()) self.assertEqual(response.status_code, 501)