コード例 #1
0
	def test_cant_access_someone_elses_page(self):
		new_user = User.objects.create(username = '******')
		new_user.set_password('parola')
		new_user.save()
		page = Page()
		page.title = "Page title";
		page.content = "Page content";
		page.owner = new_user

		page.save()

		res = self.client.get('/wiki/' + str(page.id))
		self.assertEquals(404, res.status_code)
コード例 #2
0
	def test_cant_delete_someone_elses_page(self):
		new_user = User.objects.create(username = '******')
		new_user.set_password('parola')
		new_user.save()
		page = Page()
		page.title = "Page title";
		page.content = "Page content";
		page.owner = new_user

		page.save()

		count_before = Page.objects.all().count()
		self.client.get('/wiki/delete/' + str(page.id))
		count_after = Page.objects.all().count()

		self.assertEqual(count_before, count_after)
コード例 #3
0
	def test_delete_page(self):
		page = Page()
		page.title = "Page title";
		page.content = "Page content";
		page.owner = self.user

		page.save()

		res = self.client.get('/wiki/all')
		self.assertTrue("Page title" in res.content)

		res = self.client.get('/wiki/delete/' + str(page.id))
		self.assertEquals(200, res.status_code)

		res = self.client.get('/wiki/all')
		self.assertFalse("Page title" in res.content)
コード例 #4
0
	def test_update_page_via_request(self):
		page = Page()
		page.title = "Page title";
		page.content = "Page content";
		page.owner = self.user

		page.save()

		title = "New title"
		content = "New content"
		res = self.client.post('/wiki/update/' + str(page.id), {'title': title, 'content': content})

		self.assertEquals(302, res.status_code)

		res = self.client.get('/wiki/' + str(page.id))
		self.assertTrue(title in res.content)
		self.assertTrue(content in res.content)
コード例 #5
0
	def test_creating_a_new_model_page_and_saving_it_to_the_database(self):
		page = Page()
		page.title = "Page title";
		page.content = "Page content";
		page.owner = self.user

		page.save()

		all_pages = Page.objects.all()
		self.assertEquals(len(all_pages), 1)

		only_page_in_database = all_pages[0]
		self.assertEquals(only_page_in_database, page)

		self.assertEquals(only_page_in_database.title, "Page title")
		self.assertEquals(only_page_in_database.content, "Page content")
		self.assertEquals(only_page_in_database.owner_id, self.user.id)