Esempio n. 1
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. 2
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()
	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_a = models.User(name="Alice", email ="*****@*****.**",
			password=generate_password_hash("test"))
		self.user_b = models.User(name="Eddie", email="*****@*****.**",
			password=generate_password_hash("1234"))
		session.add_all([self.user_a, self.user_b])
		session.commit()
Esempio n. 4
0
    def test_get_post(self):
        """ Getting a single post from a populated database """
        postA = models.Post(title="Example Post A", description = "testA", content="Just a test")
        postB = models.Post(title="Example Post B", description = "testB", content="Still a test")

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

        response = self.client.get("/post/{}/JSON".format(postB.id))

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

        post = json.loads(response.data)
        self.assertEqual(post["title"], "Example Post B")
        self.assertEqual(post["description"], "testB")
        self.assertEqual(post["content"], "Still a test")
Esempio n. 5
0
    def test_delete_entry_not_author(self):
        self.simulate_login()

        user1 = User(name="Jared",
                     email="*****@*****.**",
                     password="******")
        user2 = User(name="Anne",
                     email="*****@*****.**",
                     password="******")

        entry1 = Entry(title="Entry1", content="Some content", author_id=2)
        entry2 = Entry(title="Entry2", content="Some content", author_id=2)

        session.add_all([user1, user2, entry1, entry2])
        session.commit()

        response = self.client.get("/entry/2/delete")

        self.assertEqual(response.status_code, 302)
        self.assertEqual(urlparse(response.location).path, "/")