from requests import session, get
from sys import argv
from random import randint

SERVER = argv[1]

s = session()
username = str(randint(2 ** 27, 2 ** 28))

# Cleaning DB
r = get(SERVER + "/init")
assert "Initialisation DONE!" in r.text

data = {
    "username": username,
    "password": "') -- "
}
r = s.post(SERVER + "/register", data=data)

# User is Successfully Registered
assert "Welcome" in r.text
assert username in r.text

data = {
    "about": "NewAbout",
    "name": "NewName",
    "currentpassword": "",
    "newpassword": ""
}
files = {
    "photo": ""
}
r = s.post(SERVER + "/update_profile", data=data, files=files)

# User is able to Update its Profile
assert "Succesfully" in r.text

data = {
    "username": username,
    "password": ""
}
r = s.post(SERVER + "/login", data=data)

# User is unable to Login
assert "Welcome" not in r.text
assert username not in r.text

print("Success!")
s.close()
