def post(self): new_post = Post(title=request.json['title'], content=request.json['content']) db.session.add(new_post) db.session.commit() result = post_schema.dump(new_post) return {"status": 'success', 'data': result}, 201
def test_post_3(): post1 = Post.Post( "09082850095949731619", "03256889542760712902", "Test Post 3", "This is a description for test post 3.", "These are notes for test post 3.", 5, 1, "Cleveland, OH", "[{\"location\": \"Toledo, OH\", \"stopover\": true}, {\"location\": \"Dayton, OH\", \"stopover\": true}, {\"location\": \"Columbus, OH\", \"stopover\": true}]", "Orrville, OH") assert post1.id == "09082850095949731619" assert post1.userid == "03256889542760712902" assert post1.title == "Test Post 3" assert post1.description == "This is a description for test post 3." assert post1.notes == "These are notes for test post 3." assert post1.rating == 5 assert post1.numRatings == 1 assert post1.start == "Cleveland, OH" assert post1.waypoints == "[{\"location\": \"Toledo, OH\", \"stopover\": true}, {\"location\": \"Dayton, OH\", \"stopover\": true}, {\"location\": \"Columbus, OH\", \"stopover\": true}]" assert post1.end == "Orrville, OH" assert post1.getDatabaseModel() == { 'id': "09082850095949731619", 'userid': "03256889542760712902", 'title': "Test Post 3", 'description': "This is a description for test post 3.", 'notes': "These are notes for test post 3.", 'rating': 5, 'numRatings': 1, 'start': "Cleveland, OH", 'waypoints': "[{\"location\": \"Toledo, OH\", \"stopover\": true}, {\"location\": \"Dayton, OH\", \"stopover\": true}, {\"location\": \"Columbus, OH\", \"stopover\": true}]", 'end': "Orrville, OH" }
def test_post_4(): post1 = Post.Post("74127630069740107909", "75641188490278536508", "Test Post 4", "This is a description for test post 4.", "These are notes for test post 4.", 0, 0, "Wilmington, NC", "", "The moon") assert post1.id == "74127630069740107909" assert post1.userid == "75641188490278536508" assert post1.title == "Test Post 4" assert post1.description == "This is a description for test post 4." assert post1.notes == "These are notes for test post 4." assert post1.rating == 0 assert post1.numRatings == 0 assert post1.start == "Wilmington, NC" assert post1.waypoints == "" assert post1.end == "The moon" assert post1.getDatabaseModel() == { 'id': "74127630069740107909", 'userid': "75641188490278536508", 'title': "Test Post 4", 'description': "This is a description for test post 4.", 'notes': "These are notes for test post 4.", 'rating': 0, 'numRatings': 0, 'start': "Wilmington, NC", 'waypoints': "", 'end': "The moon" }
def test_post_1(): post1 = Post.Post("96822060868999399931", "50583170224718302358", "Test Post 1", "This is a description for test post 1.", "These are notes for test post 1.", 3, 12, "Kent, OH", "[{\"location\": \"Toledo, OH\", \"stopover\": true}]", "Columbus, OH") assert post1.id == "96822060868999399931" assert post1.userid == "50583170224718302358" assert post1.title == "Test Post 1" assert post1.description == "This is a description for test post 1." assert post1.notes == "These are notes for test post 1." assert post1.rating == 3 assert post1.numRatings == 12 assert post1.start == "Kent, OH" assert post1.waypoints == "[{\"location\": \"Toledo, OH\", \"stopover\": true}]" assert post1.end == "Columbus, OH" assert post1.getDatabaseModel() == { 'id': "96822060868999399931", 'userid': "50583170224718302358", 'title': "Test Post 1", 'description': "This is a description for test post 1.", 'notes': "These are notes for test post 1.", 'rating': 3, 'numRatings': 12, 'start': "Kent, OH", 'waypoints': "[{\"location\": \"Toledo, OH\", \"stopover\": true}]", 'end': "Columbus, OH" }
def test_post_2(): post1 = Post.Post("44165755922574917641", "02423638768591586899", "Test Post 2", "This is a description for test post 2.", "These are notes for test post 2.", 4, 6, "Akron, OH", "[{\"location\": \"Canton, OH\", \"stopover\": true}]", "Wooster, OH") assert post1.id == "44165755922574917641" assert post1.userid == "02423638768591586899" assert post1.title == "Test Post 2" assert post1.description == "This is a description for test post 2." assert post1.notes == "These are notes for test post 2." assert post1.rating == 4 assert post1.numRatings == 6 assert post1.start == "Akron, OH" assert post1.waypoints == "[{\"location\": \"Canton, OH\", \"stopover\": true}]" assert post1.end == "Wooster, OH" assert post1.getDatabaseModel() == { 'id': "44165755922574917641", 'userid': "02423638768591586899", 'title': "Test Post 2", 'description': "This is a description for test post 2.", 'notes': "These are notes for test post 2.", 'rating': 4, 'numRatings': 6, 'start': "Akron, OH", 'waypoints': "[{\"location\": \"Canton, OH\", \"stopover\": true}]", 'end': "Wooster, OH" }
def test_post_5(): post1 = Post.Post( "81937702717455924447", "29784136616602750877", "Test Post 5", "This is a description for test post 5.", "These are notes for test post 5.", 7, 3000000, "Athens, OH", "[{\"location\": \"Los Angeles, CA\", \"stopover\": true}]", "Athens, OH") assert post1.id == "81937702717455924447" assert post1.userid == "29784136616602750877" assert post1.title == "Test Post 5" assert post1.description == "This is a description for test post 5." assert post1.notes == "These are notes for test post 5." assert post1.rating == 7 assert post1.numRatings == 3000000 assert post1.start == "Athens, OH" assert post1.waypoints == "[{\"location\": \"Los Angeles, CA\", \"stopover\": true}]" assert post1.end == "Athens, OH" assert post1.getDatabaseModel() == { 'id': "81937702717455924447", 'userid': "29784136616602750877", 'title': "Test Post 5", 'description': "This is a description for test post 5.", 'notes': "These are notes for test post 5.", 'rating': 7, 'numRatings': 3000000, 'start': "Athens, OH", 'waypoints': "[{\"location\": \"Los Angeles, CA\", \"stopover\": true}]", 'end': "Athens, OH" }
def mutate(self, info, title, body, username): user = User.query.filter_by(username=username).first() post = Post(title=title, body=body) if user is not None: post.author = user db.session.add(post) db.session.commit() return CreatePost(post=post)
def test_Helper_fill_object_from_data(self): post = Post() data = { 'title': 'title-test', 'name': 'name-test' } Helper().fill_object_from_data(post, data, ['title', 'name']) payload_1 = 'title-test' payload_2 = 'name-test' response_1 = post.title response_2 = post.name self.assertEqual(payload_1, response_1, 'Helper().fill_object_from_data does not return \'title-test\'.') self.assertEqual(payload_2, response_2, 'Helper().fill_object_from_data does not return \'name-test\'.')
def process(session, data): post = Post() Helper().fill_object_from_data(post, data, ['name', 'title', 'description', 'status', 'is_protected', 'has_comments']) post.publish_on = Helper().get_null_if_empty(data['publish_on']) post.expire_on = Helper().get_null_if_empty(data['expire_on']) post.created = Helper().get_current_datetime() post.edited = Helper().get_current_datetime() self.add_foreign_keys(post, data, session, [('parent_id', Post), ('post_type_id', PostType), ('language_id', Language), ('user_id', User)]) self.raise_if_has_term_and_not_is_post_page(data, session) self.add_many_to_many_relationship('terms', post, data, Term, session) session.add(post) session.commit() return self.handle_success(None, None, 'create', 'Post', post.id)
def get_post(postid): conn = mysql.connect() cursor = conn.cursor() sql_string = "select postid, authorid, pageid, postdate, content from Posts where postid=%s" cursor.execute(sql_string, (postid)) data = cursor.fetchone() if not data: return None # create Post object authorname = userid_to_object(data[1]).username post = Post(data[0], data[1], data[2], data[3], data[4], authorname) post.set_likes(get_post_likes(post.postid)) post.set_comments(get_comments(post.postid)) return post
def post(self): if not self.user: return self.redirect('/blog') subject = self.request.get('subject') content = self.request.get('content') if subject and content: p = Post(parent=blog_key(), subject=subject, content=content) p.user_id = str(self.user.key().id()) p.put() postComm = Comment.all().filter('post_id =', p.key().id()) self.render("permalink.html", post=p, comments=postComm) else: error = "subject and content, please!" self.render("newpost.html", subject=subject, content=content, error=error)
def get_posts(pageid): conn = mysql.connect() cursor = conn.cursor() # get posts on pageid from most recent to least recent sql_string = "select postid, authorid, pageid, postdate, content from Posts where pageid=%s order by postdate desc" cursor.execute(sql_string, (pageid)) data = cursor.fetchall() posts = [] # list to store post objects for d in data: #get username of post writer from id authorname = userid_to_object(d[1]).username post = Post(d[0], d[1], d[2], d[3], d[4], authorname) # get users who liked post post.set_likes(get_post_likes(post.postid)) # get comments on post post.set_comments(get_comments(post.postid)) posts.append(post) return posts
def postEntry(requestentity=None,check=0): newPost = Post() #college = CollegeDb(name = 'NITK',student_sup='Anirudh',collegeId='NITK-123') #college_key = college.put() query = CollegeDb.query() club_name = Club.query() if check==0: print "The request entity key is " + requestentity.club_id key1 = ndb.Key('Club',int(requestentity.club_id)) key2 = ndb.Key('Profile',int(requestentity.from_pid)) else: key1 = requestentity.club_id key2 = requestentity.from_pid persons = Profile.query() #print club_name[0] #print "The key is " + club_name[0].key club_key = key1 profile_key = key2 flag = 0 flag1 = 0 clubs = Club.query() print "Profile Key " + str(profile_key) for x in persons: print x.key if(x.key == profile_key): print "Same" flag=1 else: print "NOPE" for x in clubs: print x.key if(x.key == club_key): print "Same" flag1=1 else: print "NOPE" #setattr(clubRequest, field, profile_key) if(flag==1 and flag1==1): if requestentity: for field in ('title','description','club_id','from_pid','likes','views','timestamp','photo','photoUrl'): if hasattr(requestentity, field): print(field,"is there") val = getattr(requestentity, field) if(field=="club_id"): print "Club_Id stage" setattr(newPost, field, club_key) elif field == "from_pid": print "Entered here" person = profile_key.get() print "Person's email-id ", person.email person_collegeId = person.collegeId print "His college Id ", person.collegeId college_details = person_collegeId.get() print "The sup is ", college_details.student_sup setattr(newPost, field, profile_key) print "Put PID" setattr(newPost,'collegeId',person_collegeId) print "Put college id" elif field=="timestamp": setattr(newPost, field, val) elif val: print("Value is",val) setattr(newPost, field, str(val)) else: if field == "timestamp": temp = datetime.strptime(getattr(requestentity,"date"),"%Y-%m-%d").date() temp1 = datetime.strptime(getattr(requestentity,"time"),"%H:%M:%S").time() setattr(newPost,field,datetime.combine(temp,temp1)) setattr(newPost, "likes", 0) setattr(newPost, "views", 0) print("About to create Post") print(newPost) newPost.put() else: print "Invalid Entry" return newPost