Esempio n. 1
0
def seed():
	content = """Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."""

	for i in range(25):
		post = Post(title="Test Post #{}".format(i),content=content)
		session.add(post)
	session.commit()
Esempio n. 2
0
    def setUp(self):
        """ Test Setup """
        self.browser = Browser("phantomjs")

        # Set up the tables in the database
        Base.metadata.create_all(engine)

        # Create an example user
        self.user = User(name="Alice",
                         email="*****@*****.**",
                         password=generate_password_hash("test"))
        session.add(self.user)
        session.commit()

        # multiprocessing module gives you the ability to start and run other code simultaneously with your own scripts
        # also allows you to communicate and control this code, by called methods such as start and terminate
        # also provides features for implements concurrency in your applications
        # in this test, you can't call app.run method as usual because this method is blocking and will stop the tests from running
        # instead, you target which function to run
        self.process = multiprocessing.Process(target=app.run,
                                               kwargs={"port": 8080})

        self.process.start()
        # time.sleep(1) in order to pause for a second to allow server to start
        time.sleep(1)
Esempio n. 3
0
def seed():
    content = """somesome wordssome wordssome wordssome wordssome words words"""

    for i in range(25):
        entry = Entry(title="Test Entry #{}".format(i), content=content)
        session.add(entry)
    session.commit()
Esempio n. 4
0
def adduser():
    """Create new user"""
    
    name = input("Name: ")
    email = input("Email: ")
    if session.query(User).filter_by(email=email).first():
        print ("User with that email address already exists")
        return
    
    password = raw_input("Password: "******"Re-enter password: "******"Password: "******"Re-enter password: "******"""
        generate_password_hash function: 
        1) Function is used to hash our password
        2) Hashing - process that converts our plain text password
                     into a string of characters
        3) Passwords use only One-Way-Hashes: process works in one direction
    """
    session.add(user)
    session.commit()
Esempio n. 5
0
def adduser():
    """
    Ask user for name, email address, and password (twice).
    Check to make sure the user is not already stored in the database.
    Make sure both passwords entered by user match.
    Finally, create the user object and add it to our database.
    """
    name = raw_input("Name: ")
    email = raw_input("Email: ")
    if session.query(User).filter_by(email=email).first():
        print "User with that email address already exists"
        return
    password = raw_input("Password: "******"Re-enter password: "******"Password: "******"Re-enter password: "******"""
        generate_password_hash function: 
        1) Function is used to hash our password
        2) Hashing - process that converts our plain text password
                     into a string of characters
        3) Passwords use only One-Way-Hashes: process works in one direction
    """
    session.add(user)
    session.commit()
Esempio n. 6
0
    def test_edit_entry(self):
        self.simulate_login()

        # Create an test entry
        test_entry = Entry(title="Test title",
                           content="Testing editing entry",
                           author=self.user)
        session.add(test_entry)
        session.commit()

        response = self.client.post("/entry/1/edit",
                                    data={
                                        "title": "Title edited",
                                        "content": "Content edited"
                                    })

        self.assertEqual(response.status_code, 302)
        self.assertEqual(urlparse(response.location).path, "/")
        entries = session.query(Entry).all()
        self.assertEqual(len(entries), 1)

        entry = entries[0]
        self.assertEqual(entry.title, "Title edited")
        self.assertEqual(entry.content, "Content edited")
        self.assertEqual(entry.author, self.user)
def seed():
    content = """Lorem ipsum dolor sit amet, consectetur adipisicing elit"""

    for i in range(25):
        entry = Entry(title = "Test Entry #{}".format(i), content = content)
        session.add(entry)
    session.commit()
Esempio n. 8
0
    def setUp(self):
        """ Test setup """
        self.browser = Browser("phantomjs")

        # Set up the tables in the database
        Base.metadata.create_all(engine)

        # Create an example user
        self.user1 = User(name="Alice",
                          email="*****@*****.**",
                          password=generate_password_hash("test"))
        session.add(self.user1)
        session.commit()

        # Create an second user
        self.user2 = User(name="Alice2",
                          email="*****@*****.**",
                          password=generate_password_hash("test"))
        session.add(self.user2)
        session.commit()

        # Create an entry
        #self.entry = Entry(title = "Test Entry", content = "Test content", author = self.user1)
        #session.add(self.entry)
        #session.commit()

        self.process = multiprocessing.Process(target=app.run,
                                               kwargs={"port": 8080})
        self.process.start()
        time.sleep(1)
Esempio n. 9
0
	def testUpdate(self):
		carol = session.query(User).filter(User.name == "Alice").one()
		carol.name = "Carol"
		session.add(carol)
		session.commit()
		temp = session.query(User).filter(User.id == 1).one()
		self.assertEqual(temp.name, "Carol")
Esempio n. 10
0
    def setUp(self):
        ''' Test setup '''

        self.browser = Browser('phantomjs')

        # if we don't set the window size, we won't be able to interact with UI that might
        # be hidden because of our media queries with a smaller emulated window
        self.browser.driver.set_window_size(1120, 550)

        # set up the tables in the database
        Base.metadata.create_all(engine)

        # create an example user
        self.user = User(name='Alice',
                         email='*****@*****.**',
                         password=generate_password_hash('test'))
        session.add(self.user)
        session.commit()

        # create a second example user
        self.user = User(name='Bob',
                         email='*****@*****.**',
                         password=generate_password_hash('test'))
        session.add(self.user)
        session.commit()

        self.process = multiprocessing.Process(target=app.run,
                                               kwargs={'port': 8080})
        self.process.start()
        time.sleep(1)
Esempio n. 11
0
    def testDeletePost(self):  #this is not described in detail in tutorial, it from example of testAddPost
        self.simulate_login()

        response1 = self.client.post("/post/add", data={
            "title": "Test Post1",
            "content": "Test content1"
        })
        
        response2 = self.client.post("/post/add", data={
            "title": "Test Post2",
            "content": "Test content2"
        })

        self.assertEqual(response1.status_code, 302)
        self.assertEqual(urlparse(response1.location).path, "/")
        posts = session.query(models.Post).all()
        self.assertEqual(len(posts), 2)

        #we are testing that post 2 is NOT being deleted.  In contrast to post 1 which IS deleted
        post2 = posts[1]
        post2_id = post2.id
        delete_url2 = "/post/" + str(post2.id) + "/delete"
        post2_list = session.query(models.Post).filter(models.Post.id == post2_id).all()
        self.assertEqual(len(post2_list), 1)
        
        #we are testing that post1 is in fact being deleted.  This is the real test.
        post1 = posts[0]
        post1_id = post1.id
        delete_url1 = "/post/" + str(post1.id) + "/delete"
        session.delete(post1)
        session.commit()
        post1_list = session.query(models.Post).filter(models.Post.id == post1_id).all()
        self.assertEqual(len(post1_list), 0)
Esempio n. 12
0
def seed():
    content = """Lorem ipsum dolor sit amet, consectetur adipisicing..."""

    for i in range(25):
        post = Post(title="Test Post #{}".format(i), content=content)
        session.add(post)
    session.commit()
    def setUp(self):
        """ Test setup """

        # creating instance of splinter.Browser class, using PhantomJS driver
        self.browser = Browser("phantomjs")

        # Set up the tables in the db
        Base.metadata.create_all(engine)

        # Create an example user
        self.user = User(name="Alice", email="*****@*****.**",
                        password=generate_password_hash("test"))
        session.add(self.user)
        session.commit()

        # Using the multiprocessing module in oder to start the Flask test server
        # because the test will be visiting the actual site you need a server up
        # to run the app.
        # we can not just call app.run method as usual because it will stop the 
        # tests from running after it has started. 
        # Instead we launch app.run in a spearate process via an instance of 
        # multiprocessing.Process
        # The target tells it which function to run, in this case your app.run
        # method, we then start the process by using its start method. However
        # we need to wait for a bit for the server to start, so we use
        # time.sleep(1) in order to pause code execution for a second. 
        self.process = multiprocessing.Process(target=app.run)
        self.process.start()
        time.sleep(1)
Esempio n. 14
0
 def test_edit_post(self):
   self.simulate_login()
   
   test_post = models.Post(
     title="Test Post",
     content="Test Content",
     author_id=self.user.id
   )
   session.add(test_post)
   session.commit()
   
   response = self.client.post("/post/edit/1", data={
     "title": "Edit Post",
     "content": "Edit content"
   })
   
   self.assertEqual(response.status_code, 302)
   self.assertEqual(urlparse(response.location).path, "/")
   posts = session.query(models.Post).all()
   self.assertEqual(len(posts), 1)
   
   post = posts[0]
   self.assertEqual(post.title, "Edit Post")
   # self.assertEqual(post.content, "<p>Edit content</p>\n")
   self.assertEqual(post.content, "Edit content")
   self.assertEqual(post.author, self.user)
    def setUp(self):
        """ Test setup """
        self.browser = Browser("phantomjs")

        # Set up the tables in the database
        Base.metadata.create_all(engine)

        # Create an example user
        self.user = models.User(name="Alice", email="*****@*****.**",
                                password=generate_password_hash("test"))
        session.add(self.user)
        session.commit()

        # Create an example post with example user as author
        self.author = session.query(models.User).filter(
                      models.User.name == "Alice").first()
        self.post = models.Post(
            title="Test Post #1",
            content="The quick brown fox jumps over the lazy dog.",
            author=self.author
        )
        session.add(self.post)
        session.commit()

        self.process = multiprocessing.Process(target=app.run)
        self.process.start()
        time.sleep(1)
Esempio n. 16
0
 def setUp(self):
     ''' Test setup '''
     
     self.browser = Browser('phantomjs')
     
     # if we don't set the window size, we won't be able to interact with UI that might 
     # be hidden because of our media queries with a smaller emulated window
     self.browser.driver.set_window_size(1120, 550)
     
     # set up the tables in the database
     Base.metadata.create_all(engine)
     
     # create an example user
     self.user = User(name = 'Alice', email = '*****@*****.**',
         password = generate_password_hash('test'))
     session.add(self.user)
     session.commit()
     
     # create a second example user
     self.user = User(name = 'Bob', email = '*****@*****.**',
         password = generate_password_hash('test'))
     session.add(self.user)
     session.commit()
     
     self.process = multiprocessing.Process(target = app.run, kwargs = { 'port': 8080 })
     self.process.start()
     time.sleep(1)
Esempio n. 17
0
def adduser():
    """
    Ask user for name, email address, and password (twice).
    Check to make sure the user is not already stored in the database.
    Make sure both passwords entered by user match.
    Finally, create the user object and add it to our database.
    """
    name = raw_input("Name: ")
    email = raw_input("Email: ")
    if session.query(User).filter_by(email=email).first():
        print "User with that email address already exists"
        return
    password = raw_input("Password: "******"Re-enter password: "******"Password: "******"Re-enter password: "******"""
        generate_password_hash function: 
        1) Function is used to hash our password
        2) Hashing - process that converts our plain text password
                     into a string of characters
        3) Passwords use only One-Way-Hashes: process works in one direction
    """
    session.add(user)
    session.commit()
Esempio n. 18
0
    def test_get_posts(self):
        """ Getting posts from a populated database """
        postA = models.Post(title="Example Post A", description = "testingA", content="Just a test")
        postB = models.Post(title="Example Post B", description = "testingB", content="Still a test")

        session.add_all([postA, postB])
        session.commit()

        response = self.client.get("/post/JSON")

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.mimetype, "application/json")

        data = json.loads(response.data)
        self.assertEqual(len(data), 2)

        postA = data[0]
        self.assertEqual(postA["title"], "Example Post A")
        self.assertEqual(postA["description"], "testingA")
        self.assertEqual(postA["content"], "Just a test")

        postB = data[1]
        self.assertEqual(postB["title"], "Example Post B")
        self.assertEqual(postB["description"], "testingB")
        self.assertEqual(postB["content"], "Still a test")
Esempio n. 19
0
def adduser():
    """Create new user"""

    # User input name and email address
    name = raw_input("Name: ")
    email = raw_input("Email: ")
    # Test whether user already exists
    if session.query(User).filter_by(email=email).first():
        print "User with that email address already exists"
        return

    # User input password (entered twice for verification)
    password = ""
    password_2 = ""
    # Loop while either password is empty or passwords do not match
    while not (password and password_2) or password != password_2:
        # Use builtin getpass function to input password without echoing string
        password = getpass("Password: "******"Re-enter password: ")
    # Create new user instance
    # Password is converted to hash - string of characters based on SHA1 hashing algorithm
    # Hashes only work one-way (password to hash string) to prevent malicious use of stored passwords
    user = User(name=name,
                email=email,
                password=generate_password_hash(password))
    session.add(user)
    session.commit()
Esempio n. 20
0
    def test_edit_post(self):
        self.simulate_login()

        test_post = models.Post(title="Test Post",
                                content="Test Content",
                                author_id=self.user.id)
        session.add(test_post)
        session.commit()

        response = self.client.post("/post/edit/1",
                                    data={
                                        "title": "Edit Post",
                                        "content": "Edit content"
                                    })

        self.assertEqual(response.status_code, 302)
        self.assertEqual(urlparse(response.location).path, "/")
        posts = session.query(models.Post).all()
        self.assertEqual(len(posts), 1)

        post = posts[0]
        self.assertEqual(post.title, "Edit Post")
        # self.assertEqual(post.content, "<p>Edit content</p>\n")
        self.assertEqual(post.content, "Edit content")
        self.assertEqual(post.author, self.user)
Esempio n. 21
0
    def setUp(self):
        """ Test setup """
        self.browser = Browser("phantomjs")

        # Set up the tables in the database
        Base.metadata.create_all(engine)

        # Create an example user
        self.user = User(name="Alice",
                         email="*****@*****.**",
                         password=generate_password_hash("test"))
        session.add(self.user)
        #        session.commit()
        try:
            session.commit()
        except:
            session.rollback()
            raise
        finally:
            session.close()  # optional, depends on use case

        self.process = multiprocessing.Process(target=app.run,
                                               kwargs={"port": 8080})
        self.process.start()
        time.sleep(2)
Esempio n. 22
0
def seed():
    content = """Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."""

    for i in range(25):
        entry = Entry(title="Test Entry #{}".format(i), content=content)
        session.add(entry)
    session.commit()
Esempio n. 23
0
 def simulate_add_entry(self, title, content):
     """
     define this method to add test data for edit and delete workflow
     """
     entry = Entry(title=title, content=content)
     session.add(entry)
     session.commit()
     return entry.id
Esempio n. 24
0
	def testRelationships(self):
		alice = session.query(User).filter(User.name == "Alice").one()
		post1 = session.query(Post).filter(Post.title == "Alice's Title").one()
		self.assertEqual(alice.posts[0].title, "Alice's Title")
		self.assertEqual(post1.author.name, "Alice")
		session.delete(alice)
		session.commit()
		self.assertIsNone(post1.author)
Esempio n. 25
0
def seed():
    content = """Ballsacularism nutsack, buttsack, tickle my chod"""
    for i in range(25):
        entry = Entry(
            title="Test Entry #{}".format(i),
            content=content
        )
        session.add(entry) #add entries to db
    session.commit() # commit entries to db
Esempio n. 26
0
 def setUp(self):
     """ test setup"""
     self.client = app.test_client()
     
     Base.metadata.create_all(engine)
     
     self.user = User(name="Alice",email="*****@*****.**",password=generate_password_hash("test"))
     session.add(self.user)
     session.commit()
Esempio n. 27
0
def seed():
  content = """ Hello there this is seed content """
  for i in range(25):
    post = Post(
            title="Seed post {}".format(i),
            content = content
            )
    session.add(post)
  session.commit()  
Esempio n. 28
0
def seed():
	for i in range(25):
		entry = Entry(
			title = "Test Entry #{}".format(i),
			# get_sentences returns a tuple the size of
			# what's passed in. [0] will access the tuple
			content = fake.text()
		)
		session.add(entry)
	session.commit()
Esempio n. 29
0
def seed():
    content = """Lorem ipsum dolor sit amet, consectetur adipisicing..."""
    
    for i in range(25):
        post = Post(
            title="Test Post #{}".format(i),
            content=content
        )
        session.add(post)
    session.commit()
Esempio n. 30
0
 def test_delete_entry(self):
     self.simulate_login()
     self.test_add_entry()
     entry = session.query(Entry).first()
     entries = session.query(Entry).all()
     session.delete(entry)
     session.commit()
     
     entries = session.query(Entry).all()
     self.assertEqual(len(entries), 0)
Esempio n. 31
0
def seed():
    content = """somesome wordssome wordssome wordssome wordssome words words"""

    for i in range(25):
        entry = Entry(
            title="Test Entry #{}".format(i),
            content=content
        )
        session.add(entry)
    session.commit()
Esempio n. 32
0
 def setUp(self):
     """ Test setup """
     self.client = app.test_client()
     
     Base.metadata.create_all(engine)
     
     self.user = User(name="Mike", email="*****@*****.**",
                     password=generate_password_hash("test"))
     session.add(self.user)
     session.commit()
Esempio n. 33
0
def seed():
	content = """Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempora possimus odio aliquam perferendis beatae soluta ipsa, praesentium, rerum esse earum aspernatur blanditiis eaque, nam veritatis! Ut beatae ullam esse neque. """

	for i in range(25):
		post = Post(
			title = "Test Post #{}".format(i),
			content = content
			)
		session.add(post)
	session.commit()
Esempio n. 34
0
def seed():
  content = '''Lorem ipsum'''

  for i in range(25):
    entry = Entry(
      title='Test Entry #{}'.format(i),
      content=content
    )
    session.add(entry)
  session.commit()
    def setUp(self):
        """ Test setup """
        self.client = app.test_client()

        # Set up the tables in the database
        Base.metadata.create_all(engine)

        # Create an example user
        self.user = models.User(name="Alice", email="*****@*****.**", password=generate_password_hash("test"))
        session.add(self.user)
        session.commit()
 def simulate_add_entry(self, title, content):
     """
     define this method to add test data for edit and delete workflow
     """
     entry = Entry(
         title=title,
         content=content
     )
     session.add(entry)
     session.commit()
     return entry.id
Esempio n. 37
0
def seed():
    """Add dummy posts to database"""
    content = """Text comes here."""

    for i in range(10):
        entry = Entry(
            title="Test Entry#{}".format(i),
            content=content
        )
        session.add(entry)
    session.commit()
Esempio n. 38
0
def seed():
    content = """TEST TEST TEST, these entries are all just tests. Mic check one, two
    , one, two, testing, testing."""

    for i in range(1,26):
        entry = Entry(
            title="Test Entry #{}".format(i),
            content=content
        )
        session.add(entry)
    session.commit()
Esempio n. 39
0
def seed():
  content = """Roof party literally farm-to-table, Tumblr Austin selfies letterpress forage craft beer squid cronut drinking vinegar."""
  
  for i in range(25):
    post = Post(
      title = "Test Post #{}".format(i),
      content=content
    )
    session.add(post)
    
  session.commit()
Esempio n. 40
0
    def setUp(self):
        """ Test setup """
        self.client = app.test_client()

        # Set up the tables in the database
        Base.metadata.create_all(engine)

        # Create an example user
        self.user = models.User(name="Alice", email="*****@*****.**",
                                password=generate_password_hash("test"))
        session.add(self.user)
        session.commit()
 def setUp(self):
     """Test setup"""                         
     self.client = app.test_client()
     #makes an interface that allows requests to be made to the server with given parameters
     #Setup tables in the database
     Base.metadata.create_all(engine)
     
     #create an example user
     self.user = User(name="Alice", email="*****@*****.**",
                     password = generate_password_hash("test"))
     session.add(self.user)
     session.commit()
Esempio n. 42
0
 def setUp(self):
     ''' test setup '''
     self.client = app.test_client()
     
     # set up the tables in the database
     Base.metadata.create_all(engine)
     
     # create an example user
     self.user = User(name = 'Alice', email = '*****@*****.**', 
         password = generate_password_hash('test'))
     session.add(self.user)
     session.commit()
Esempio n. 43
0
    def setUp(self):
        """ Test setup """
        #Make requests to views and inspect responses from the app
        self.client = app.test_client()

        # Set up the tables in the database
        Base.metadata.create_all(engine)

        # Create an example user
        self.user = User(name="Alice", email="*****@*****.**",
                         password=generate_password_hash("test"))
        session.add(self.user)
        session.commit()
Esempio n. 44
0
def adduser():
    name=input("Name: ")
    email=input("Email: ")
    if session.query(User).filter_by(email=email).first():
        print("User with that email address alreadye exists")
        return
    password=""
    while len(password)<8 or password!= password_2:
        password=getpass("Password: "******"Re-enter password: ")
    user = User(name=name, email=email, password=generate_password_hash(password))
    session.add(user)
    session.commit()
    def setUp(self):
        """Test Setup"""
        self.client = app.test_client()

        #set up tables in db
        Base.metadata.create_all(engine)

        #create a user
        self.user = User(name="Alice",
                         email="*****@*****.**",
                         password=generate_password_hash("test"))
        session.add(self.user)
        session.commit()
Esempio n. 46
0
 def setUp(self):
     """ Tets Setup """
     self.browser = Browser("phantomjs")
     
     Base.metadata.create_all(engine)
     self.user = User(name="Alice",email="*****@*****.**",password=generate_password_hash("test"))
     session.add(self.user)
     session.commit()
     
     self.process = multiprocessing.Process(target=app.run,kwargs={"port":8080})
     
     self.process.start()
     time.sleep(1)
Esempio n. 47
0
    def setUp(self):
        ''' test setup '''
        self.client = app.test_client()

        # set up the tables in the database
        Base.metadata.create_all(engine)

        # create an example user
        self.user = User(name='Alice',
                         email='*****@*****.**',
                         password=generate_password_hash('test'))
        session.add(self.user)
        session.commit()
	def setUp(self):

		self.browser = Browser("phantomjs")
		Base.metadata.create_all(engine)

		self.user = User(name="Jim", email="*****@*****.**",
						password=generate_password_hash("test"))
		session.add(self.user)
		session.commit()

		self.process = multiprocessing.Process(target=app.run,
												kwargs={"port": 8080})
		self.process.start()
		time.sleep(1)
Esempio n. 49
0
	def setUp(self):
		Base.metadata.create_all(engine)
		alice = User(name="Alice", email="*****@*****.**",
			password=generate_password_hash("atest"))
		bob = User(name="Bob", email="*****@*****.**",
			password=generate_password_hash("btest"))
		session.add_all([alice, bob])
		session.commit()
		post1 = Post(title="Alice's Title", content="Alice's Content",
			author_id=alice.id)
		post2 = Post(title="Bob's Title", content="Bob's Content",
			author_id=bob.id)
		session.add_all([post1, post2])
		session.commit()
Esempio n. 50
0
    def setUp(self):
        """ Test setup """
        
        # Create a test client that allows inspection of app views/responses
        self.client = app.test_client()

        # Set up the tables in the testing database
        Base.metadata.create_all(engine)

        # Create an example user in the testing database
        self.user = models.User(name="Alice", email="*****@*****.**",
                                password=generate_password_hash("test"))
        session.add(self.user)
        session.commit()
Esempio n. 51
0
def adduser():
    name = input("Name: ")
    email = input("Email: ")
    if session.query(User).filter_by(email=email).first():
        print("User with that email address already exists")
        return

    password = ""
    while len(password) < 8 or password != password_2:
        password = getpass("Password: "******"Re-enter password: ")
    user = User(name=name, email=email,
                password=generate_password_hash(password))
    session.add(user)
    session.commit()
Esempio n. 52
0
def adduser():
    name = input('Name: ')
    email = input('Email: ')
    if session.query(User).filter_by(email = email).first():
        print('User with that email address already exists.')
        return
    
    password = ''
    password_2 = ''
    while len(password) < 8 or password != password_2:
        password = getpass('Password: '******'Re-enter password: ')
    user = User(name = name, email = email, password = generate_password_hash(password))
    session.add(user)
    session.commit()
Esempio n. 53
0
def seed():
    """
    seed - command which will add a series of posts to the database
    """
    #create a string of dummy text for the post content
    content = """Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."""

    #use a loop to add 25 posts
    for i in range(25):
        #create a new post
        post = Post(title="Test Post #{}".format(i), content=content)
        #add the new post to the session
        session.add(post)
    #session.commit will synchronize all changes to the database
    session.commit()
Esempio n. 54
0
def adduser():
    user = User()
    user.name = raw_input("Name: ")
    email = raw_input("Email: ")
    if email == session.query(User).filter(User.email==email).first():
        print "Someone's already registered with that email."
        return
    user.email = email  
    password = ""
    password2 = ""
    while not (password and password2) or password != password2:
        password = getpass("Password:"******"Repeat password:")
    user.password = generate_password_hash(password)
    session.add(user)
    session.commit()
Esempio n. 55
0
    def setUp(self):
        """ Test setup """
        self.client = app.test_client()

        # Set up the tables in the database
        Base.metadata.create_all(engine)

        # Create an example user
        self.user = User(name="Alice",
                         email="*****@*****.**",
                         password=generate_password_hash("test"))
        self.entry = Entry(title="test entry",
                           content="test content",
                           author=self.user)
        session.add(self.user, self.entry)
        session.commit()
Esempio n. 56
0
    def test_delete_post(self):

        test_post = models.Post(title="Test Post",
                                content="Test Content",
                                author_id=self.user.id)
        session.add(test_post)
        session.commit()
        post_id = test_post.id

        self.simulate_login()
        response = self.client.post("/post/delete/{}".format(post_id))
        """ self.assertEqual(response.status_code, 302) AssertionError: 405 != 302 """
        self.assertEqual(response.status_code, 302)
        self.assertEqual(urlparse(response.location).path, "/")
        posts = session.query(models.Post).all()
        self.assertEqual(len(posts), 0)
Esempio n. 57
0
def seed():
    content = []
    blog_sample_text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
    print blog_sample_text
    for i in range(25):
        j = i * 10
        k = (i * 10) + 20
        print blog_sample_text[j:k]
        content.append(blog_sample_text[j:k])
        print content[i]

    for i in range(25):
        post = Post(title="Test Post #{}".format(i), content=content[i])
        session.add(post)
        print "i= %s" % i
    session.commit()
Esempio n. 58
0
    def setUp(self):
        """ Test setup """
        self.browser = Browser("phantomjs")

        # Set up the tables in the database
        Base.metadata.create_all(engine)

        # Create an example user
        self.user = models.User(name="Alice", email="*****@*****.**",
                                password=generate_password_hash("test"))
        session.add(self.user)
        session.commit()

        self.process = multiprocessing.Process(target=app.run)
        self.process.start()
        time.sleep(1)