def test_home_page_returns_correct_html(self): from django.contrib.auth.forms import UserCreationForm from main.forms import UserProfileForm request = HttpRequest() response = homepage(request) expected_html = render_to_string('main/home.html', {'userform': UserCreationForm(), 'profileform': UserProfileForm()}) self.assertEqual(response.content.decode(), expected_html)
def postdeleted(request): if request.user.is_authenticated(): username = request.user.username newsid = request.POST.get("newsid") newstodelete = newsitem.objects.filter(id=request.POST.get("newsid")) newstodelete.delete() return homepage(request) else: return index(request)
def test_home_page_can_save_POST_request(self): request = HttpRequest() request.method = 'POST' request.POST['username'] = '******' response = homepage(request) self.assertEqual(response.status_code, 302) self.assertEqual(response['location'], '/?registration=success')
def test_home_page_returns_correct_html(self): from django.contrib.auth.forms import UserCreationForm from main.forms import UserProfileForm request = HttpRequest() response = homepage(request) expected_html = render_to_string('main/home.html', { 'userform': UserCreationForm(), 'profileform': UserProfileForm() }) self.assertEqual(response.content.decode(), expected_html)
def savechanges(request): if request.user.is_authenticated(): user = request.user user.first_name = request.POST.get('firstname') user.last_name = request.POST.get('lastname') user.email = request.POST.get('email') user.save() username = request.user.username return homepage(request) else: return index(request)
def authenticater(request): username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) return homepage(request) else: return HttpResponse("fail") else: return HttpResponse("login failed")
def posttonews(request): if request.user.is_authenticated(): username = request.user.username title = request.POST.get('title') newstext = request.POST.get('newstext') now = datetime.datetime.now() receiver = request.POST.get('receiver') if title == '': return HttpResponse('please enter in a title for your fancy little news post') elif newstext == '': return HttpResponse('your fancy little news post needs a news post, please type news into your news') else: addnews = newsitem(user_name=username, news_title=title, news_body=newstext, pub_date=now, receiver_name=receiver) addnews.save() return homepage(request) else: return index(request)
def index(request): if request.user.is_authenticated(): return homepage(request) else: return render(request, 'login/index.html')