コード例 #1
0
ファイル: views.py プロジェクト: arpreading/Python
def add_todo(request):
    t = Todo(title = request.POST['title'],
             description = request.POST['description'],
             importance = request.POST['importance'],
             owner=request.user)
    t.save()
    return HttpResponseRedirect(reverse(todo_index))
コード例 #2
0
def add_todo(request):
    t = Todo(title=request.POST['title'],
             description=request.POST['description'],
             importance=request.POST['importance'],
             owner=request.user)
    t.save()
    return HttpResponseRedirect(reverse(todo_index))
コード例 #3
0
ファイル: tests.py プロジェクト: cmcknight/Hello_Python
class TestTodo(TestCase):
    def setUp(self):
        self.user = User(id=1, username="******")
        self.user.set_password("IamBruce")
        self.user.save()
        self.todo = Todo(title="Test Todo", description="This is a test todo", importance="A", owner=self.user)
        self.todo.save()

    def test_short_model_name(self):
        self.assertEqual(self.todo.short_description(), "This is a test todo")

        self.todo.description = "Test\nMultiple\nLines"
        self.assertEqual(self.todo.short_description(), "Test")

        self.todo.description = ("A" * 50) + ("B" * 50)
        self.assertEqual(self.todo.short_description(), ("A" * 50) + ("B" * 30))

    def test_index(self):
        client = Client()
        client.login(username=self.user.username, password="******")

        response = client.get("/todos/")
        # print response.content
        self.assertTrue("Welcome, Bruce" in response.content)
        self.assertTrue(self.todo.title in response.content)

    def test_login(self):
        """ Login should redirect to the index page """
        client = Client()
        response = client.post(reverse(views.todo_login), {"username": self.user.username, "password": "******"})

        self.assertEqual(response.status_code, 302)
        self.assertTrue(response["location"].endswith(reverse(views.todo_index)))
コード例 #4
0
ファイル: tests.py プロジェクト: trefoil-ml/hello-python
 def setUp(self):
     self.user = User(id=1, username="******")
     self.user.set_password("IamBruce")
     self.user.save()
     self.todo = Todo(title='Test Todo',
                      description='This is a test todo',
                      importance='A',
                      owner=self.user)
     self.todo.save()
コード例 #5
0
class TestTodo(TestCase):
    
    def setUp(self):
        self.user = User(id=1, username="******")
        self.user.set_password("IamBruce")
        self.user.save()
        self.todo = Todo(
            title='Test Todo', 
            description='This is a test todo', 
            importance='A', 
            owner=self.user)
        self.todo.save()

    def test_short_model_name(self):
        self.assertEqual(self.todo.short_description(),
                'This is a test todo')
                
        self.todo.description = "Test\nMultiple\nLines"
        self.assertEqual(self.todo.short_description(),
                'Test')
                
        self.todo.description = ("A"*50) + ("B"*50)
        self.assertEqual(self.todo.short_description(),
                ("A"*50) + ("B"*30))

    def test_index(self):
        client = Client()
        client.login(username=self.user.username, 
                     password='******')
        
        response = client.get('/todos/')
        # print response.content
        self.assertTrue('Welcome, Bruce' in
            response.content)
        self.assertTrue(self.todo.title in
            response.content)

    def test_login(self):
        """ Login should redirect to the index page """
        client = Client()
        response = client.post(
            reverse(views.todo_login), 
            {'username': self.user.username, 
             'password': "******"})
        
        self.assertEqual(response.status_code, 302)
        self.assertTrue(response['location'].endswith(
                           reverse(views.todo_index)))
コード例 #6
0
ファイル: tests.py プロジェクト: cmcknight/Hello_Python
 def setUp(self):
     self.user = User(id=1, username="******")
     self.user.set_password("IamBruce")
     self.user.save()
     self.todo = Todo(title="Test Todo", description="This is a test todo", importance="A", owner=self.user)
     self.todo.save()