def test_favorite(self): with main.app.app_context(): account.registerUser("testUser", "*****@*****.**", "1234", "10025") user = {"username": "******", "password": "******"} self.app.post("/loginUser", data=user, follow_redirects=True) postdata = { "title": "test", "description": "wanna sell test", "category": "Books" } rv = self.app.post("/NewSellerPost", data=postdata, follow_redirects=True) res = re.findall("postId=\d+#", rv.data) assert len(res) == 1 postId = res[0][7:-1] postdata = {"postId": postId, "postType": "Seller"} rv = self.app.post("/favorite", data=postdata, follow_redirects=True) assert "Adding to favorites succeeded!" == rv.data rv = self.app.post("/deleteFavorite", data=postdata, follow_redirects=True) assert "Deleting a favorite item succeeded!" == rv.data print "Adding and deleting favorite posts pass\n"
def test_postList(self): with main.app.app_context(): account.registerUser("testUser", "*****@*****.**", "1234", "10025") user = {"username": "******", "password": "******"} self.app.post("/loginUser", data=user, follow_redirects=True) postdata = { "title": "test_sellerpost", "description": "wanna sell test", "category": "Books" } self.app.post("/NewSellerPost", data=postdata, follow_redirects=True) postdata = { "title": "test_buyerpost", "description": "wanna buy test", "category": "Books" } self.app.post("/NewBuyerPost", data=postdata, follow_redirects=True) self.app.get('/logout') rv = self.app.post('/postlist/seller') assert 'test_sellerpost' in rv.data rv = self.app.post('/postlist/buyer') assert 'test_buyerpost' in rv.data print 'post list pass\n'
def test_loginUser(self): with main.app.app_context(): account.registerUser("testUser", "*****@*****.**", "1234", "10025") user = {"username": "******", "password": "******"} rv = self.app.post("/loginUser", data=user, follow_redirects=True) assert b'Wrong password!' not in rv.data assert b'User doesn\'t exist!' not in rv.data user = {"username": "******", "password": "******"} rv = self.app.post("/loginUser", data=user, follow_redirects=True) assert b'Wrong password!' in rv.data account.deleteUser("testUser") user = {"username": "******", "password": "******"} rv = self.app.post("/loginUser", data=user, follow_redirects=True) assert b'User doesn\'t exist!' not in rv.data print "user login pass\n"
def sendMessage(receiver, content, sender='system', title=''): # create system account if not exists if sender == 'system' and account.searchUser('system') is None: account.registerUser('system', '*****@*****.**', 'system-pwd', 10000) time = datetime.datetime.now(pytz.timezone('US/Eastern')) message = Message(senderUsername=sender, receiverUsername=receiver, title=title, content=content, time=time) try: db.session.add(message) db.session.commit() return message.messageId except Exception as e: print e db.session.rollback() return None
def registerUser(): username = str(request.form['username']) email = str(request.form['email']) password = str(request.form['password']) zipcode = str(request.form['zipcode']) res = account.registerUser(username, email, password, zipcode) if res: # signup successful session['logged_in'] = True session['username'] = username return redirect('/') else: return render_template("signup.html", error="User exists!")
def test_message(self): with main.app.app_context(): account.registerUser("testSender", "*****@*****.**", "1234", "10025") account.registerUser("testReceiver", "*****@*****.**", "1234", "10025") message.sendMessage(sender="testSender", receiver="testReceiver", title="message_title", content="message_content") assert "message_title" in json.dumps( message.getMessages(sender="testSender", receiver="testReceiver")) assert "message_title" not in json.dumps( message.getMessages(sender="testReceiver", receiver="testSender")) assert "message_content" in json.dumps( message.getMessagesByUser("testSender")) assert "message_content" in json.dumps( message.getMessagesByUser("testReceiver")) account.deleteUser("testSender") account.deleteUser("testReceiver") print "message test pass"
def test_order(self): with main.app.app_context(): account.registerUser("testUser", "*****@*****.**", "1234", "10025") user = {"username": "******", "password": "******"} self.app.post("/loginUser", data=user, follow_redirects=True) postdata = { "title": "test", "description": "wanna sell test", "category": "Books" } rv = self.app.post("/NewSellerPost", data=postdata, follow_redirects=True) res = re.findall("postId=\d+#", rv.data) assert len(res) == 1 postId = res[0][7:-1] postdata = {"postId": postId, "transactionType": "Face to Face"} rv = self.app.post("/checkout", data=postdata, follow_redirects=True) assert "Placing order succeeded!" in rv.data print "Place order pass\n"
"price": 30, "image": "tennis.jpg", "location": "Kansas", "description": "I start to play tennis recently, and I need a defender tennis racquet. I don't have specific brand requirement, but make sure the tennis is in good condition. The price is negotiable" }) with main.app.app_context(): # add users for user in users: if user['username'] == 'system': users.remove(user) account.registerUser(user["username"], user["email"], user["password"], user["zipcode"]) message.sendMessage(receiver=user["username"], content="Hello, " + user["username"] + ". Welcome to sponge!") # add posts for item in sellerPosts: image = open(os.path.join("image", item["image"]), "r") post.createPost(item["title"], item["description"], item["category"], item["price"], item["location"], image.read(), random.choice(users)["username"], "Seller") image.close() for item in buyerPosts: image = open(os.path.join("image", item["image"]), "r") post.createPost(item["title"], item["description"], item["category"], item["price"], item["location"], image.read(),
def test_post(self): with main.app.app_context(): account.registerUser("testUser", "*****@*****.**", "1234", "10025") user = {"username": "******", "password": "******"} self.app.post("/loginUser", data=user, follow_redirects=True) postdata = { "title": "test", "description": "wanna sell test", "category": "Books" } rv = self.app.post("/NewSellerPost", data=postdata, follow_redirects=True) res = re.findall("postId=\d+#", rv.data) assert len(res) == 1 postId = res[0][7:-1] postdata = { "postType": "Seller", "postId": postId, "title": "test NEW", "description": "wanna sell test NEW", "category": "Beauty" } rv = self.app.post("/updatepost", data=postdata, follow_redirects=True) assert "Updating post succeeded!" in rv.data postdata = {"postType": "Buyer", "postId": postId} rv = self.app.post("/deletepost", data=postdata, follow_redirects=True) assert "Deleting post succeeded!" in rv.data postdata = { "title": "test", "description": "wanna buy test", "category": "Books" } rv = self.app.post("/NewBuyerPost", data=postdata, follow_redirects=True) res = re.findall("postId=\d+#", rv.data) assert len(res) == 1 postId = res[0][7:-1] postdata = { "postType": "Buyer", "postId": postId, "title": "test NEW", "description": "wanna buy test NEW", "category": "Beauty" } rv = self.app.post("/updatepost", data=postdata, follow_redirects=True) assert "Updating post succeeded!" in rv.data postdata = { "postType": "Buyer", "postId": postId, "content": "I have one to sell." } rv = self.app.post("/addPostComment", data=postdata, follow_redirects=True) assert "add comment succeeded" in rv.data postdata = {"postType": "Buyer", "postId": postId} rv = self.app.post("/getPostComments", data=postdata, follow_redirects=True) postdata = {"postType": "Buyer", "postId": postId} rv = self.app.post("/deletepost", data=postdata, follow_redirects=True) assert "Deleting post succeeded!" in rv.data print "Post: create, update and delete pass\n"