Jason Rossi (jrossi3@stevens.edu),
Nouman Syed (nsyed1@stevens.edu),
Atishay Jain (ajain70@stevens.edu)
https://github.com/Jrossi3/WebForum
Each of the group members spent around 20 hours on the project
The way we tested our code was through a test.sh script. In this file, we would run shell commands to run multiple tests covering various edge-cases for each of the routes we had put together.
To the best of our knowledge, there are no known bugs or issues in our endpoints, extensions or scripts.
An example of a difficult issue or bug was extracting a key from the shell command and putting it into another shell command.
- Update function
- This is the route used for the update a post. It works by sending a PATCH request to the following route.
/post/<int:id>/update/<string:key> - While updating a post, the user is expected to send as the request body, a JSON Object with a single key,
"msg"with the value as whatever the content of the updated post needs to be. - As seen from the route, it also requires and
idof the post that needs to be updated. And the secretkeyso not everybody can update your posts. This requests responds with the updated post. - This route also updates the
timestampon the post.
- Fulltext search
- This is the route used for the fulltext search feature. This works when a GET request is sent to the following route:
"/post/fulltext/<string:msg>". This extension works by iterating through all the posts that exist and looking for posts with a match with the input string from the query. - For example, If I had to look for posts which have their
"msg"fields as"Hi my name is Jason", I would send a request like/post/fulltext/"hi%20my%20name%20is%20jason". This will find all the posts with matching"msg"fields.
- Persistence
- We used MongoDB to implement persistence of data. This makes sure even if the server restarts, the data is not lost as it is all stored in the Database. This extension does everything as specified in the Spec Sheet.
- Data and Time based queries
- This extension works when the user sends a GET request on the
/post/<string:start>/<string:end>route. - As seen, there are two query parameters that can either be two valid dates in the ISO 8601 format in UTC or "none"
/post/2023-04-30T19:29:03Z/2023-04-30T11:54:23Zgets all the posts with timestamps between the start and end time given./post/2023-04-30T19:29:03Z/nonegets all the posts that were made or last updated after the given timestamp./post/none/2023-04-30T19:29:03Zgets all the posts that were made or last updated before the given timestamp./post/none/nonethrows an error telling the user that both start, and end can not be "none"- This extension considers timestamps provided for
startandendare inclusive. So posts which have the same date-time as the query will also be included.
- Threaded Replies
- This extension works when a POST request is sent to the
/post/<int:id>route. Threaded replies works exactly like Endpoint 1 (Create posts). Except, when a reply post is created, theidof the parent post is provided in the query. Thisidis used to fetch the parent post, and insert theidof the newly created reply post into thethread: []array field present in each post. - So, to summarize, each post will have the
ids of all its replies in itsthreadfield.
-
Create Post & Get Post by ID Tests for the first two endpoints are done together. The command
RESPONSE=$(curl http://127.0.0.1:5000/post -X POST -d '{"msg": "hi my name is jason"}')created a post withidas1. We usejqto extract thekey,idandmsgfrom the post we just created. In the next step, we runTEST=$(curl http://127.0.0.1:5000/post/1)command which fetches the first post. If this request results in a response likePost with ID: 1 not found, it means the post was not created and the first endpoint failed. Now, the response for stored inTESTis compared to the fields of the post we created, and stored in varibles. This allows us to make sure that the post that was fetched is the exact same as the one we had originally created. -
Delete Post To test the Delete post feature, we used a while loop to create 5 posts using the
curl http://127.0.0.1:5000/post -X POST -d '{"msg": "hi my name is jason"}'command. Theidandkeyof the posts created above are stored in variables. Each post is then deleted usingcurl -X DELETE http://127.0.0.1:5000/post/$id/delete/$key. After the delete command is run, we try to fetch those posts by getting them using theirids. Each time, since the post has already been deleted, we get the responsePost with ID: $id not foundconfirming that all the posts that were created have been deleted. -
Update Post(Extension) We tested the update message post feature in a very straightforward way. We ran the command
"curl http://127.0.0.1:5000/post -X POST -d '{"msg": "hi my name is jason"}'"to add a new post. After this, we setRESPONSEequal to the new post. We then got thekey,msg, andidof the new post and ran the update command:"curl -X PUT -d '{"msg": "hello I am update"}' http://127.0.0.1:5000/post/$id/update/$key". This changed the message from"hi my name is jason"to"hello I am update". We then got the updated post and set it equal to New. Then we got the updated message and set it equal tonewMsg. From here, we checked ifmsgandnewMsgwere equivalent to each other. If they were equal, then the update function has failed to update the message. If they are not equal, then the message was updated. -
Persistence(Extension) We tested persistence through 2 different ways. Our first way was restarting the server through running two commands to end and start the server. There is a
"kill $PID"command and a"flask run &"command to end and start the server resepctively. The second way of testing was giving it a bad request. The exact command is"curl http://127.0.0.1:5000/post/fulltext"and here this is a bad request because it is an unfinished request and therefore will return an error. Then there is a test to see if the post is still existing after the command is run. There are many comments in the testing to show the exact specifics of when these tests occur. -
Fulltext Search(Extension) We tested persistence in a very simple way. We ran the command
"curl http://127.0.0.1:5000/post -X POST -d '{"msg": "hi my name is jason"}'"to add a new post. We then ran the command'curl http://127.0.0.1:5000/post/fulltext/"hi%20my%20name%20is%20jason"'to find all matching posts with the message"hi my name is jason"essentially targeting the post we just created. This command was set equal toRESPONSE. We then created anEXPECTEDvariable, which was then set to the new post that was just created, but the way it was put together was by extracting the information from the new post that was just created and then adding it to aEXPECTEDvariable. Then we checked if theEXPECTEDwas equivalent to theRESPONSEand if they were, then the test passed since the search found the new post with the matching message. -
Threaded Replies(Extension) For testing the threaded replies endpoint, we first create a post that will act as the parent post for our replies using the
curl http://127.0.0.1:5000/post -X POST -d '{"msg": "hi my name is Atishay"}'command. This post has anidof1. Once we've created this post, we now use thecurl http://127.0.0.1:5000/post/1 -X POST -d '{"msg": "I am the reply"}'command to create a post that is a reply to the first post. This reply post will have theidof2. Now, to test if this new reply post has updated the parent post, we runcurl http://127.0.0.1:5000/post/1to fetch the first post. And we see that now, this post has field"thread": [2]. Which tells us that the post withidof2is a reply to the first post. We repeat this with another reply post that is created usingcurl http://127.0.0.1:5000/post/1 -X POST -d '{"msg": "I am the second reply"}'. This post has anidof3. This time when we run thecurl http://127.0.0.1:5000/post/1, we notice that the field"thread": [2]is now changed to"thread": [2, 3], indicating that there is a new reply withidof3for the first post. -
Data and Time based Range Queries(Extension) To test this post, we created four posts. Using commands like
curl http://127.0.0.1:5000/post -X POST -d '{"msg": "First Post"}'. All the fields of each of these posts are stored into variables. We then run the commandRESPONSE=$(curl http://127.0.0.1:5000/post/$timestamp1/$timestamp4)which essectially allows us to get all the four posts we have created. Then we run the commandRESPONSE=$(curl http://127.0.0.1:5000/post/$timestamp2/none)which gets the second, third and fourth posts, excluding the first post. Similarly, when we run the commandRESPONSE=$(curl http://127.0.0.1:5000/post/none/$timestamp3), the first, second and third posts are fetched, excluding the last post. Finally,RESPONSE=$(curl http://127.0.0.1:5000/post/none/none)this commands gets us an error response,Both Start and End cannot be None.