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 .views import home_page
class HomePageTest(TestCase):
class NewTaskTest(TestCase):
def test_root_url_resolves_to_home_page_view(self):
found = resolve('/')
self.assertEqual(found.func, home_page)
\ No newline at end of file
def test_can_get_create_template(self):
response = self.client.get('/tasks/new')
self.assertTemplateUsed(response, 'task_create_form.html')
\ No newline at end of file
#froyo/urls
from django.conf.urls import url
from .views import home_page
from .views import HomeView, TaskCreateView
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
# Create your views here.
class HomeView(TemplateView):
template_name = "home.html"
class TaskCreateView(CreateView):
template_name_suffix='_create_form'
\ No newline at end of file
import unittest
import time
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):
self.browser.quit()
def test_can_start_and_retrieve_a_list(self):
self.brower.get('http://localhost:8000')
self.assertIn('Django', self.browser.title)
self.fail('Finish the Test')
class NewVisitorTest(unittest.TestCase):
def test_can_create_new_task(self):
self.browser.get('http://localhost:8000/tasks')
input = self.browser.find_element_by_id('id_new_item')
self.assertEqual(input.get_attribute('placeholder'), 'Enter a to-do item')
if __name__=='__main__':
unittest.main(warnings='ignore')
\ No newline at end of file
input.send_keys('Finish CSCI40 Project')
input.send_keys(Keys.Enter)
time.sleep(1)
self.assertIn(browser.getCurrentUrl(), 'http://localhost:8000/task/1')
self.assertIn('Finish CSCI40 Project', self.browser.find_element_by_id('task_name').text)
\ 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