Commit 90a9d7a1 authored by Lance Michael O. Co's avatar Lance Michael O. Co 😢

Made into CBVs

parent 1d4e3403
<html>
<title>Django</title>
</html>
\ No newline at end of file
<html>
<title>Task Form</title>
</html>
\ No newline at end of file
<html>
<title>Task Form</title>
</html>
\ No newline at end of file
from django.urls import resolve #froyo/tests
from django.test import TestCase from django.test import TestCase
from .views import home_page
class HomePageTest(TestCase): class NewTaskTest(TestCase):
def test_root_url_resolves_to_home_page_view(self): def test_can_get_create_template(self):
found = resolve('/') response = self.client.get('/tasks/new')
self.assertEqual(found.func, home_page) self.assertTemplateUsed(response, 'task_create_form.html')
\ No newline at end of file \ No newline at end of file
#froyo/urls
from django.conf.urls import url from django.conf.urls import url
from .views import home_page
from .views import HomeView, TaskCreateView
urlpatterns = [ urlpatterns = [
url(r'^$', home_page, name='home_page'), url(r'^$', HomeView, name='home_page'),
url(r'^tasks/new$', TaskCreateView, name='task_create'),
] ]
\ No newline at end of file
from django.shortcuts import render #froyo/views
from django.views.generic.base import TemplateView
from django.views.generic.edit import CreateView
def home_page():
pass class HomeView(TemplateView):
# Create your views here. template_name = "home.html"
class TaskCreateView(CreateView):
template_name_suffix='_create_form'
\ No newline at end of file
import unittest import unittest
import time
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.browser = webdriver.Firefox()
def teardown(self): class NewVisitorTest(unittest.TestCase):
self.browser.quit()
def test_can_start_and_retrieve_a_list(self): def test_can_create_new_task(self):
self.brower.get('http://localhost:8000') self.browser.get('http://localhost:8000/tasks')
self.assertIn('Django', self.browser.title) input = self.browser.find_element_by_id('id_new_item')
self.fail('Finish the Test') self.assertEqual(input.get_attribute('placeholder'), 'Enter a to-do item')
input.send_keys('Finish CSCI40 Project')
input.send_keys(Keys.Enter)
time.sleep(1)
if __name__=='__main__': self.assertIn(browser.getCurrentUrl(), 'http://localhost:8000/task/1')
unittest.main(warnings='ignore') self.assertIn('Finish CSCI40 Project', self.browser.find_element_by_id('task_name').text)
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment