/
test_script
executable file
·63 lines (43 loc) · 2.13 KB
/
test_script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
host_name="localhost:5000/"
echo "Deleting database if it exists to test init_db()"
rm -f database.db
echo "Starting server with nohup and putting it in the background"
rm -f nohup.out
. venv/bin/activate
nohup python server.py &
sleep 3
echo "The server is at ${host_name}users/, if this is incorrect, edit the host_name variable"
echo "Attempting to add a few new users"
curl -i -X POST -d "username=cj+zeiger" "${host_name}users/"
curl -i -X POST -d "username=john+doe" "${host_name}users/"
curl -i -X POST -d "username=sam+smith" "${host_name}users/"
curl -i -X POST -d "username=jack+john" "${host_name}users/"
curl -i -X POST -d "username=bob+joe" "${host_name}users/"
echo "Creating a few test transactions"
curl -i -X POST -d "user_id_1=1&user_id_2=2" "${host_name}transaction/"
curl -i -X POST -d "user_id_1=1&user_id_2=5" "${host_name}transaction/"
curl -i -X POST -d "user_id_1=2&user_id_2=3" "${host_name}transaction/"
curl -i -X POST -d "user_id_1=3&user_id_2=1" "${host_name}transaction/"
curl -i -X POST -d "user_id_1=5&user_id_2=4" "${host_name}transaction/"
echo -e "Now requesting a list of the database \n cj zeiger should hav a count of 1 \n john doe should have a count of 2 \n sam smith should have a count of 3"
curl -i -X GET "${host_name}users/"
echo "Requesting the individual count of each user through the /users/<username> endpoint"
echo "CJ Zeiger should have a count of 1"
curl -i -X GET "${host_name}users/1"
echo "John Doe should have a count of 2"
curl -i -X GET "${host_name}users/2"
echo "Sam Smith should have a count of 3"
curl -i -X GET "${host_name}users/3"
echo "Now testing some invalid requests"
echo "cj and john already met, they should not be allowed to meet again."
curl -i -X POST -d "user_id_1=2&user_id_2=1" "${host_name}transaction/"
echo "and again"
curl -i -X POST -d "user_id_1=4&user_id_2=5" "${host_name}transaction/"
curl -i -X POST -d "user_id_1=5&user_id_2=4" "${host_name}transaction/"
echo "Done testing with cURL"
pkill -f server.py
echo "Verifying database structure"
sqlite3 database.db 'select * from users'
echo "Transactions: "
sqlite3 database.db 'select * from interactions'