コード例 #1
0
ファイル: yilpil.py プロジェクト: 7flying/yil-pil
 def post(self, id): # OK
     """ Handles a POST request. Creates a new post. """
     debug("POST a post")
     args = self.reqparse.parse_args()
     post = {}
     post['contents'] = args['contents']
     post['title'] = args['title']
     if args['tags'] == None or len(args['tags']) == 0:
         post['tags'] = []
     else:
         post['tags'] = list([b64decode(temp) \
             for temp in args['tags'].split(':')])
     user = args['username']
     created_post = manager.insert_post(post, user)
     return {'post': marshal(created_post, PostAPI.response_post_field)}
コード例 #2
0
ファイル: yilpil.py プロジェクト: 7flying/yil-pil
 def post(self, id):  # OK
     """ Handles a POST request. Creates a new post. """
     debug("POST a post")
     args = self.reqparse.parse_args()
     post = {}
     post['contents'] = args['contents']
     post['title'] = args['title']
     if args['tags'] == None or len(args['tags']) == 0:
         post['tags'] = []
     else:
         post['tags'] = list([b64decode(temp) \
             for temp in args['tags'].split(':')])
     user = args['username']
     created_post = manager.insert_post(post, user)
     return {'post': marshal(created_post, PostAPI.response_post_field)}
コード例 #3
0
 def test_2_user_data(self):
     # User creation
     user = {}
     user['name'] = 'user'
     user['password'] = '******'
     user['email'] = '*****@*****.**'
     self.assertIsNotNone(manager.insert_user(user))
     self.assertTrue(manager._is_user_created('user'))
     self.assertFalse(manager.insert_user(user))
     self.assertFalse(manager.add_favourite('user', '3'))
     # Create post
     post = {'title' : "How to install Node.js", \
        'contents' : "Download files and sudo make, sudo make intall", \
        'tags' : ["node.js", "How-to"]}
     created_post = manager.insert_post(post, 'user')
     self.assertIsNotNone(manager.get_posts('user'))
     self.assertIsNotNone(manager.get_posts('user', 1))
     # Favourites
     self.assertTrue(manager.add_favourite('user', created_post['id']))
     self.assertIsNotNone(manager.get_favourites('user'))
     self.assertEqual(1, manager.get_favourite_count('user'))
     self.assertTrue(manager.delete_favourite('user', created_post['id']))
     # User data modification
     db_user = manager.get_user('user')
     self.assertEqual(md5(user['email'].encode('utf-8')).hexdigest(), \
          db_user['hash'])
     self.assertTrue(user['password'], manager.get_password('user'))
     self.assertTrue(manager.change_password('user', '1234'))
     self.assertTrue(manager.change_email('user', 'some_email'))
     # User tags
     self.assertIsNotNone(manager.get_user_tags('user'))
     # Update post
     post = {'title' : "MODIFY", \
        'contents' : "MODIFY", \
        'tags' : ["node.js", "One tag more"]}
     self.assertIsNotNone(
         manager.update_post(post, created_post['id'], 'user'))
コード例 #4
0
ファイル: test_manager.py プロジェクト: 7flying/yil-pil
	def test_2_user_data(self):
		# User creation
		user = {}
		user['name'] = 'user'
		user['password'] = '******'
		user['email'] = '*****@*****.**'
		self.assertIsNotNone(manager.insert_user(user))
		self.assertTrue(manager._is_user_created('user'))
		self.assertFalse(manager.insert_user(user))
		self.assertFalse(manager.add_favourite('user', '3'))
		# Create post
		post = {'title' : "How to install Node.js", \
				 'contents' : "Download files and sudo make, sudo make intall", \
				 'tags' : ["node.js", "How-to"]}
		created_post = manager.insert_post(post, 'user')
		self.assertIsNotNone(manager.get_posts('user'))
		self.assertIsNotNone(manager.get_posts('user', 1))
		# Favourites
		self.assertTrue(manager.add_favourite('user', created_post['id']))
		self.assertIsNotNone(manager.get_favourites('user'))
		self.assertEqual(1, manager.get_favourite_count('user'))
		self.assertTrue(manager.delete_favourite('user', created_post['id']))
		# User data modification
		db_user = manager.get_user('user')
		self.assertEqual(md5(user['email'].encode('utf-8')).hexdigest(), \
						 db_user['hash'])
		self.assertTrue(user['password'], manager.get_password('user'))
		self.assertTrue(manager.change_password('user', '1234'))
		self.assertTrue(manager.change_email('user', 'some_email'))
		# User tags
		self.assertIsNotNone(manager.get_user_tags('user'))
		# Update post
		post = {'title' : "MODIFY", \
				 'contents' : "MODIFY", \
				 'tags' : ["node.js", "One tag more"]}
		self.assertIsNotNone(manager.update_post(post, created_post['id'], 'user'))