Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Millon15 committed Jan 15, 2019
1 parent 6a86596 commit ea7dc24
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 70 deletions.
2 changes: 1 addition & 1 deletion rush00
20 changes: 7 additions & 13 deletions unit-tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,17 @@ def run_command(cmd):
# count of things that didn't go so well
failed_count = 0

def execcom(command):
try:
exitcode, out, err = run_command(command)
except:
print("The program couldn't execute the command.\n" +
"Here's the command for debugging purposes: ")
print(str(command))
exit(1)
return exitcode, out, err

def test_command(command, expected, check_std_err = 1):
global failed_count

exitcode, out, err = execcom(command)
exitcode, out, err = 0, 0, ""
try:
exitcode, out, err = run_command(command)
except:
print("")
if (expected == out):
# if (len(command) > 100):
# command = command[:100] + "...";
# command = command[:100] + "..."
print("passed: " + str(command))
else:
print("FAILED: " + str(command))
Expand All @@ -59,7 +53,7 @@ def test_boolean(boolean, string):
print("passed: " + str(string))
else:
print("FAILED: " + str(string))
failed_count += 1;
failed_count += 1

def print_final_results():
print("")
Expand Down
7 changes: 3 additions & 4 deletions unit-tests/test_d01.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from helper import *

# day_location = "/Users/vbrazas/projects/php_piscine/d01/"
day_location = "/Users/vbrazas/.Trash/ang/"
helpers = "/Users/vbrazas/projects/php_piscine/unit-tests/helpers_d01/"
day_location = "/Users/vbrazas/projects/archive/php_piscine/d01/"
helpers = "/Users/vbrazas/projects/archive/php_piscine/unit-tests/helpers_d01/"

# START OF TESTS START OF TESTS START OF TESTS START OF TESTS

Expand Down Expand Up @@ -246,4 +245,4 @@
# Enter a number: ^D""")
# print("")

print_final_results();
print_final_results()
4 changes: 2 additions & 2 deletions unit-tests/test_d02.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
print("")

# ex03
exitcode, out, err = execcom('who')
exitcode, out, err = run_command('who')
test_command(day_location + "/ex03/who.php", out)
print("")

Expand Down Expand Up @@ -153,4 +153,4 @@

# END OF TESTS END OF TESTS END OF TESTS END OF TESTS END OF TESTS

print_final_results();
print_final_results()
12 changes: 6 additions & 6 deletions unit-tests/test_d03.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

from helper import *

# for expanding the ~ in filenames; checking if a file exists
# for expanding the ~ in filenames checking if a file exists
# import os
# from os.path import expanduser
# from os.path import isfile
# from os.path import isdir

day_location = "http://localhost:8100/d03"
day_location = "http://localhost:8100/deleteme"
# day_location = "http://localhost:8100/php_piscine/d03"

# START OF TESTS START OF TESTS START OF TESTS START OF TESTS
Expand Down Expand Up @@ -153,10 +153,10 @@ def lynx_tests():
print("\nTests for ex05:")
def test_ex05():
command = "curl --head " + day_location + "/ex05/read_img.php"
exitcode, out, err = run_command(command);
exitcode, out, err = run_command(command)
test_boolean("Content-Type: image/png" in out, "content type test")
command = "curl " + day_location + "/ex05/read_img.php"
exitcode, out, err = run_command(command);
exitcode, out, err = run_command(command)
test_boolean(out == open((day_location + "/img/42.png"), 'r').read(), "image content test")

# test_ex05()
Expand All @@ -173,9 +173,9 @@ def test_ex05():
test_boolean("<html><body>That area is accessible for members only</body></html>" in out, "actual body part for unauthorized page")
exitcode, out, err = run_command("curl --user zaz:jaimelespetitsponeys " + day_location + "/ex06/members_only.php")
test_boolean("<html><body>\nHello Zaz<br />" in out, "hello zaz")
test_boolean("<img src='data:image/png;base64,iVBORw0KGgoAAAA" in out, "first image")
test_boolean("<img src='data:image/pngbase64,iVBORw0KGgoAAAA" in out, "first image")
test_boolean("6MIHnr2t+eeO4Fr+v/H80AmcVvzqAfAAAAAElFTkSuQmCC'>" in out, "second image")

# END OF TESTS END OF TESTS END OF TESTS END OF TESTS END OF TESTS

print_final_results();
print_final_results()
72 changes: 36 additions & 36 deletions unit-tests/test_d04.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from helper import *

# for expanding the ~ in filenames; checking if a file exists
# for expanding the ~ in filenames checking if a file exists
import os
from os.path import expanduser
from os.path import isfile
from os.path import isdir

day_on_server_location = "http://localhost:8100/php_piscine/d04"
location_of_private = "/Users/vbrazas/http/MyWebSite/php_piscine/d04/private"
day_on_server_location = "http://localhost:8100/d04"
location_of_private = "/Users/vbrazas/http/MyWebSite/d04/private"

# # START OF TESTS START OF TESTS START OF TESTS START OF TESTS

Expand All @@ -19,15 +19,15 @@
# exit(1)

# print("Copying git repo to the correct location...")
# exitcode, out, err = execcom("rsync -rv --exclude=.git " + day_on_server_location + " " + expanduser("~/http/MyWebSite/d04"))
# exitcode, out, err = run_command("rsync -rv --exclude=.git " + day_on_server_location + " " + expanduser("~/http/MyWebSite/d04"))
# if (len(err) > 0 and "identical" not in err):
# print("Failed to copy files!")
# print(err)
# exit(1)
# execcom("mkdir " + expanduser("~/mamp/apps/j04/conf"))
# execcom("cp " + day_on_server_location + "ex00/httpd-app.conf " + expanduser("~/mamp/apps/j04/conf"))
# execcom("cp " + day_on_server_location + "ex00/httpd-vhosts.conf " + expanduser("~/mamp/apps/j04/conf"))
# execcom("cp " + expanduser("~/mamp/apps/demo/conf/httpd-prefix.conf") + " " + expanduser("~/mamp/apps/j04/conf"))
# run_command("mkdir " + expanduser("~/mamp/apps/j04/conf"))
# run_command("cp " + day_on_server_location + "ex00/httpd-app.conf " + expanduser("~/mamp/apps/j04/conf"))
# run_command("cp " + day_on_server_location + "ex00/httpd-vhosts.conf " + expanduser("~/mamp/apps/j04/conf"))
# run_command("cp " + expanduser("~/mamp/apps/demo/conf/httpd-prefix.conf") + " " + expanduser("~/mamp/apps/j04/conf"))

# print("")

Expand All @@ -41,65 +41,65 @@
# ex00
print("\nTests for ex00:")

execcom("rm -f cook.txt")
run_command("rm -f cook.txt")

exitcode, out, err = execcom("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'login'")
exitcode, out, err = run_command("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'login'")
test_boolean('name="login"' in out, "login named correctly")
test_boolean(("value" not in out) or ('value=""' in out), "login set correctly")
exitcode, out, err = execcom("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'passwd'")
exitcode, out, err = run_command("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'passwd'")
test_boolean('name="passwd"' in out, "passwd named correctly")
test_boolean(("value" not in out) or ('value=""' in out), "passwd set correctly")
exitcode, out, err = execcom("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'submit'")
exitcode, out, err = run_command("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'submit'")
test_boolean('name="submit"' in out, "submit named correctly")
test_boolean(("value" not in out) or ('value="OK"' in out), "submit set correctly")

exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'login'")
exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'login'")
test_boolean('name="login"' in out, "login named correctly after no ok")
test_boolean(("value" not in out) or ('value=""' in out), "login set correctly after no ok")
exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'passwd'")
exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'passwd'")
test_boolean('name="passwd"' in out, "passwd named correctly after no ok")
test_boolean(("value" not in out) or ('value=""' in out), "passwd set correctly after no ok")
exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'submit'")
exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'submit'")
test_boolean('name="submit"' in out, "submit named correctly after no ok")
test_boolean(("value" not in out) or ('value="OK"' in out), "submit set correctly after no ok")

exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone&submit=OK' | grep 'login'")
exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone&submit=OK' | grep 'login'")
test_boolean('name="login"' in out, "login named correctly after ok")
test_boolean('value="sb"' in out, "login set correctly after ok")
exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'passwd'")
exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'passwd'")
test_boolean('name="passwd"' in out, "passwd named correctly after ok")
test_boolean('value="beeone"' in out, "passwd set correctly after ok")
exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'submit'")
exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php?login=sb&passwd=beeone' | grep 'submit'")
test_boolean('name="submit"' in out, "submit named correctly after ok")
test_boolean('value="OK"' in out, "submit set correctly after ok")

exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'login'")
exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'login'")
test_boolean('name="login"' in out, "login named correctly after not passing stuff in url")
test_boolean('value="sb"' in out, "login set correctly after not passing stuff in url")
exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'passwd'")
exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'passwd'")
test_boolean('name="passwd"' in out, "passwd named correctly after not passing stuff in url")
test_boolean('value="beeone"' in out, "passwd set correctly after not passing stuff in url")
exitcode, out, err = execcom("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'submit'")
exitcode, out, err = run_command("curl -v -b cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'submit'")
test_boolean('name="submit"' in out, "submit named correctly after not passing stuff in url")
test_boolean('value="OK"' in out, "submit set correctly after not passing stuff in url")

exitcode, out, err = execcom("curl -v '" + day_on_server_location + "/ex00/index.php' | grep 'login'")
exitcode, out, err = run_command("curl -v '" + day_on_server_location + "/ex00/index.php' | grep 'login'")
test_boolean('name="login"' in out, "login named correctly after removing cookie file")
test_boolean(("value" not in out) or ('value=""' in out), "login set correctly after removing cookie file")
exitcode, out, err = execcom("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'passwd'")
exitcode, out, err = run_command("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'passwd'")
test_boolean('name="passwd"' in out, "passwd named correctly after removing cookie file")
test_boolean(("value" not in out) or ('value=""' in out), "passwd set correctly after removing cookie file")
exitcode, out, err = execcom("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'submit'")
exitcode, out, err = run_command("curl -v -c cook.txt '" + day_on_server_location + "/ex00/index.php' | grep 'submit'")
test_boolean('name="submit"' in out, "submit named correctly after removing cookie file")
test_boolean(("value" not in out) or ('value="OK"' in out), "submit set correctly after removing cookie file")

execcom("rm -f cook.txt")
run_command("rm -f cook.txt")

print("")

# ex01
print("Tests for ex01:")
execcom("rm -rf " + expanduser(location_of_private))
run_command("rm -rf " + expanduser(location_of_private))
test_command("curl -d login=toto1 -d passwd=titi1 -d submit=OK '" + day_on_server_location + "/ex01/create.php'", "OK\n", 0)
password_file = expanduser(location_of_private + "/passwd")
test_boolean('a:1:{' == get_file_contents(password_file)[:5]
Expand All @@ -110,14 +110,14 @@
test_command("curl -d login=toto1 -d passwd=titi1 -d submit=OK '" + day_on_server_location + "/ex01/create.php'", "ERROR\n", 0)
test_command("curl -d login=toto1 -d passwd=titi1 -d submit=OKK '" + day_on_server_location + "/ex01/create.php'", "ERROR\n", 0)
test_command("curl -d login=login -d passwd=password '" + day_on_server_location + "/ex01/create.php'", "ERROR\n", 0)
exitcode, out, err = execcom("curl -v '" + day_on_server_location + "/ex01/index.html'")
exitcode, out, err = run_command("curl -v '" + day_on_server_location + "/ex01/index.html'")
test_boolean('method="POST"' in out or 'method="post"' in out, "correct method")
execcom("rm -rf " + expanduser(location_of_private))
run_command("rm -rf " + expanduser(location_of_private))
print("")

# ex02
print("Tests for ex02:")
execcom("rm -rf " + expanduser(location_of_private))
run_command("rm -rf " + expanduser(location_of_private))
test_command("curl -d login=x -d passwd=21 -d submit=OK '" + day_on_server_location + "/ex01/create.php'", "OK\n", 0)
password_file = location_of_private + "/passwd"
test_boolean('a:1:{' == get_file_contents(location_of_private + "/passwd")[:5]
Expand All @@ -130,29 +130,29 @@
test_command("curl -d login=x -d oldpw=21 -d newpw=42 -d submit=OK '" + day_on_server_location + "/ex02/modif.php'", "ERROR\n", 0) # wrong password
test_command("curl -d login=x -d oldpw=42 -d newpw= -d submit=OK '" + day_on_server_location + "/ex02/modif.php'", "ERROR\n", 0) # blank new password

exitcode, out, err = execcom("curl -v '" + day_on_server_location + "/ex02/index.html'")
exitcode, out, err = run_command("curl -v '" + day_on_server_location + "/ex02/index.html'")
test_boolean('method="POST"' in out or 'method="post"' in out, "correct method")
execcom("rm -rf " + expanduser(location_of_private))
run_command("rm -rf " + expanduser(location_of_private))
print("")

# ex03
print("Tests for ex03:")
execcom("rm -rf " + expanduser(location_of_private))
run_command("rm -rf " + expanduser(location_of_private))
test_command("curl -d login=toto -d passwd=titi -d submit=OK '" + day_on_server_location + "/ex01/create.php'", "OK\n", 0)
password_file = location_of_private + "/passwd"
test_boolean('a:1:{' == get_file_contents(location_of_private + "/passwd")[:5]
, "begin part of serialized file (" + password_file + ")")
test_command("curl '" + day_on_server_location + "/ex03/login.php?login=toto&passwd=titi'", "OK\n", 0) # check login.php: correct

execcom("rm -rf " + expanduser(location_of_private))
execcom("curl -d login=toto -d passwd=titi -d submit=OK '" + day_on_server_location + "/ex01/create.php'")
run_command("rm -rf " + expanduser(location_of_private))
run_command("curl -d login=toto -d passwd=titi -d submit=OK '" + day_on_server_location + "/ex01/create.php'")
test_command("curl -c cook.txt '" + day_on_server_location + "/ex03/login.php?login=toto&passwd=titi'", "OK\n", 0)
test_command("curl -b cook.txt '" + day_on_server_location + "/ex03/whoami.php'", "toto\n", 0)
test_command("curl -b cook.txt '" + day_on_server_location + "/ex03/logout.php'", "", 0)
test_command("curl -b cook.txt '" + day_on_server_location + "/ex03/whoami.php'", "ERROR\n", 0)

execcom("rm -f cook.txt")
run_command("rm -f cook.txt")

# END OF TESTS END OF TESTS END OF TESTS END OF TESTS END OF TESTS

print_final_results();
print_final_results()
8 changes: 4 additions & 4 deletions unit-tests/test_d06.zsh
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/bin/zsh


#### ▼▼▼▼ Please insert global path to your day and resources folders below ▼▼▼▼ ####
WORK_D='/Users/vbrazas/.Trash/d06/'
# WORK_D='/Users/vbrazas/projects/php_piscine/d06/'
RES_D='/Users/vbrazas/projects/php_piscine/resources/d06/'
WORK_D="$HOME/.Trash/d06/"
# WORK_D="$HOME/projects/php_piscine/d06/"
RES_D="$HOME/projects/php_piscine/resources/d06/"


# To use Single_checker© you need to be in the folder of the direct exersize
Expand All @@ -24,6 +23,7 @@ if [[ $1 ]]; then
sleep 2
less diffs.out
else

rm -f main.out my.out diffs.out
fi
exit 1;
Expand Down
8 changes: 4 additions & 4 deletions unit-tests/test_d07.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from helper import *

# for expanding the ~ in filenames; checking if a file exists
# for expanding the ~ in filenames checking if a file exists
# expanduser, isfile, isdir, chdir
import os

day_location = "/Users/vbrazas/projects/php_piscine/d07/"
resources = "resources_d07/"
day_location = "/Users/vbrazas/.Trash/vbrazas2/"
resources = "/Users/vbrazas/projects/php_piscine/unit-tests/resources_d07/"
tester_dir = os.getcwd()

# START OF TESTS START OF TESTS START OF TESTS START OF TESTS
Expand Down Expand Up @@ -37,7 +37,7 @@
Fighter.class.php
UnholyFactory.class.php
"""
test_boolean((after_grep == answer[:len(after_grep)]), "correct files");
test_boolean((after_grep == answer[:len(after_grep)]), "correct files")


# ex00
Expand Down

0 comments on commit ea7dc24

Please sign in to comment.