Ejemplo n.º 1
0
 def addUser(self, email, password, join_date, verified):
     hashed = bcrypt.hashpw(password, bcrypt.gensalt(1))
     user = User(email = email,
                 password = hashed,
                 join_date = join_date,
                 verified = verified)
     user.put()
Ejemplo n.º 2
0
    def testSignUpHandlerBADSTUDENTPost2(self, mock):
        # Arrange: Make the web request with all of the necessary information.
        test_user = User()
        test_user.email = "*****@*****.**"
        test_user.password = "******"
        test_user.put()

        test_request = webapp2.Request.blank('/signup',
                                             POST={
                                                 "firstname": "TESTFIRST",
                                                 "lastname": "TESTLAST",
                                                 "email":
                                                 "*****@*****.**",
                                                 "password": "******",
                                                 "b9": "COMPSCI101"
                                             })
        main.isInstructor = False
        test_request.method = 'POST'
        mock.return_value = None

        # Act
        response = test_request.get_response(main.app)

        # Assert: Inspect the response
        self.assertTrue(main.error != '')
        mock.assert_called_with('/signup')
Ejemplo n.º 3
0
	def test_add_duplicate(self):
		u = User(first_name='A', last_name='B', username='******')
		u.put()
		self.assertEqual(len(User.query().fetch()), 1)
		item = Item(name='car')
		res = u.add_item(item)
		expected = 'added item car to user C'
		self.assertEqual(res, expected)

		res = u.add_item(item)
		expected = 'C already has car'
		self.assertEqual(res, expected)
Ejemplo n.º 4
0
 def testLoginHandlerCookieFaculty(self, mock):
     user = User()
     user.Fname = "Matt"
     user.Lname = "K"
     user.email = "*****@*****.**"
     user.password = "******"
     user.isInstructor = True
     main.u = user
     user.put()
     request = webapp2.Request.blank('/login')
     request.cookies['uname'] = "*****@*****.**"
     response = request.get_response(main.app)
     mock.assert_called_with('Faculty_landing.html')
Ejemplo n.º 5
0
    def testMainHandlerCookie(self, mock_set_cookie, mock_redir):
        user = User()
        user.Fname = "Matt"
        user.Lname = "K"
        user.email = "*****@*****.**"
        user.password = "******"
        user.put()
        request = webapp2.Request.blank('/home',
                                        POST={
                                            "user_email": "*****@*****.**",
                                            "pass_word": "KMatt"
                                        })
        request.method = 'POST'
        mock_redir.return_value = None

        response = request.get_response(main.app)

        mock_set_cookie.assert_called_with('uname', user.email, path='/')
        self.assertEqual(main.error, "")
        mock_redir.assert_called_with('/login')
Ejemplo n.º 6
0
    def testMainHandlerPostPWError(self, mock):
        # Arrange: Put a User in the datastore stub; POST the wrong password.
        test_User = User()
        test_User.email = "*****@*****.**"
        test_User.password = "******"
        test_User.put()
        test_request = webapp2.Request.blank('/home',
                                             POST={
                                                 "user_email":
                                                 "*****@*****.**",
                                                 "pass_word": "WRONGPASSWORD"
                                             })
        test_request.method = 'POST'
        mock.return_value = None

        # Act: Give the request to the app.
        response = test_request.get_response(main.app)

        # Assert: Inspect the response.
        mock.assert_called_with('/home')
        self.assertEqual(main.error, "Incorrect password!")
Ejemplo n.º 7
0
 def test_add_duplicate_person_to_datastore(self):
     u = User(first_name="tanawat", last_name="khunlertkit", username="******")
     u.put()
     u.put()
     self.assertEqual(1, len(User.query().fetch()))
	def test_add_person_to_datastore(self):
		u = User(first_name='tanawat', last_name='khunlertkit', username='******')
		u.put()
		self.assertEqual(1, len(User.query().fetch()))