Ejemplo n.º 1
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.º 2
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.º 3
0
def generate_users(n):
    users = list()
    for i in range(n):
        user = User(faker.name())
        user.username = faker.name()
        user.password = "******"
        try:
            db.session.add(user)
            db.session.commit()
            users.append(user)
        except Exception as e:
            log.error("Fail to add user %s: %s" % (str(user), e))
            db.session.rollback()
    return users
Ejemplo n.º 4
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.º 5
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.º 6
0
#!/usr/bin/python

import os, sys
import hashlib

sys.path.insert(1, os.path.join(sys.path[0], '../src'))

from main import db, User

items = ['NumerousDiamond', 'AcceptableVillage', 'InformalEditor', 'ImportantRoad', 'HistoricalPainting', 'SexualClimate', 'ConsistentConcept', 'DesperateCoffee', 'ScaredFood', 'OddCurrency', 'AsleepImportance', 'GuiltyManager', 'ScaredGrandmother', 'PoliticalChapter', 'UnusualEmphasis', 'DramaticArt', 'InnerHealth', 'SevereAssociation', 'NiceInternet', 'ElectronicAffair', 'MedicalFeedback', 'ElectricalArrival', 'LatterExplanation', 'SufficientApartment', 'CulturalPeople', 'DistinctGirl', 'DangerousIdea', 'SeriousMeaning', 'SuitableCity', 'HotApplication', 'EasternActivity', 'SeveralGrandmother', 'KnownInsurance', 'EducationalOven', 'IntelligentBeer', 'PoorMoment', 'AdministrativeManagement', 'StrictContext', 'EfficientCandidate', 'MentalTale']

for item in items:
  u = User()
  u.username = item
  u.email = item.lower()+'@pnyx.app'
  u.password = hashlib.sha384(os.urandom(24)).hexdigest()
  u.save()
Ejemplo n.º 7
0
for i in range(1000):
    recode = {}
    recode["cname"] = init_categoryname[random.randint(0, 8)]
    recode['date'] = "2019-" + str(random.randint(7, 8)) + "-" + str(
        random.randint(1, 30))
    recode['name'] = "test_" + recode["cname"]
    recode['price'] = random.randint(100, 20000)
    init_recodes.append(recode)

db.drop_all()
db.create_all()
users = ["*****@*****.**", "*****@*****.**", "*****@*****.**"]
for n_user in users:
    you = User()
    you.email = n_user
    you.password = bcrypt.generate_password_hash(
        "password" + app.secret_key).decode('utf-8')
    db.session.add(you)
    db.session.commit()

shreid = str(uuid4())
makebook = BookMap()
makebook.book_name = "newbook"
makebook.email = "*****@*****.**"
makebook.permission = 1
makebook.book_id = shreid
db.session.add(makebook)
db.session.commit()

makebook = BookMap()
makebook.book_name = "newbook"
makebook.email = "*****@*****.**"