2020-04-02 13:54:54 +02:00
|
|
|
import requests
|
|
|
|
|
2020-04-02 15:08:14 +02:00
|
|
|
from phpTest import PhpTest
|
|
|
|
|
|
|
|
class InstallTestCase(PhpTest):
|
2020-04-02 13:54:54 +02:00
|
|
|
|
|
|
|
def __init__(self, args):
|
|
|
|
super().__init__("test_install")
|
|
|
|
self.args = args
|
|
|
|
self.session = requests.Session()
|
|
|
|
|
|
|
|
def test_install(self):
|
|
|
|
|
|
|
|
# Test Connection
|
|
|
|
res = self.session.get(self.url)
|
|
|
|
self.assertEquals(200, res.status_code, self.httpError(res))
|
|
|
|
self.assertEquals([], self.getPhpErrors(res))
|
|
|
|
|
|
|
|
# Database Setup
|
|
|
|
res = self.session.post(self.url, data=vars(self.args))
|
|
|
|
self.assertEquals(200, res.status_code, self.httpError(res))
|
|
|
|
self.assertEquals([], self.getPhpErrors(res))
|
|
|
|
|
|
|
|
# Create User
|
|
|
|
|
|
|
|
# 1. Invalid username
|
|
|
|
for username in ["a", "a"*33]:
|
|
|
|
res = self.session.post(self.url, data={ "username": username, "password": "123456", "confirmPassword": "123456" })
|
|
|
|
self.assertEquals(200, res.status_code, self.httpError(res))
|
|
|
|
self.assertEquals([], self.getPhpErrors(res))
|
2020-04-02 15:08:14 +02:00
|
|
|
obj = self.getJson(res)
|
2020-04-02 13:54:54 +02:00
|
|
|
self.assertEquals(False, obj["success"])
|
|
|
|
self.assertEquals("The username should be between 5 and 32 characters long", obj["msg"])
|
|
|
|
|
|
|
|
# 2. Invalid password
|
2020-04-02 15:08:14 +02:00
|
|
|
res = self.session.post(self.url, data={ "username": PhpTest.ADMIN_USERNAME, "password": "1", "confirmPassword": "1" })
|
2020-04-02 13:54:54 +02:00
|
|
|
self.assertEquals(200, res.status_code, self.httpError(res))
|
|
|
|
self.assertEquals([], self.getPhpErrors(res))
|
2020-04-02 15:08:14 +02:00
|
|
|
obj = self.getJson(res)
|
2020-04-02 13:54:54 +02:00
|
|
|
self.assertEquals(False, obj["success"])
|
|
|
|
self.assertEquals("The password should be at least 6 characters long", obj["msg"])
|
|
|
|
|
|
|
|
# 3. Passwords do not match
|
2020-04-02 15:08:14 +02:00
|
|
|
res = self.session.post(self.url, data={ "username": PhpTest.ADMIN_USERNAME, "password": "1", "confirmPassword": "2" })
|
2020-04-02 13:54:54 +02:00
|
|
|
self.assertEquals(200, res.status_code, self.httpError(res))
|
|
|
|
self.assertEquals([], self.getPhpErrors(res))
|
2020-04-02 15:08:14 +02:00
|
|
|
obj = self.getJson(res)
|
2020-04-02 13:54:54 +02:00
|
|
|
self.assertEquals(False, obj["success"])
|
|
|
|
self.assertEquals("The given passwords do not match", obj["msg"])
|
|
|
|
|
|
|
|
# 4. User creation OK
|
2020-04-02 15:08:14 +02:00
|
|
|
res = self.session.post(self.url, data={ "username": PhpTest.ADMIN_USERNAME, "password": PhpTest.ADMIN_PASSWORD, "confirmPassword": PhpTest.ADMIN_PASSWORD })
|
2020-04-02 13:54:54 +02:00
|
|
|
self.assertEquals(200, res.status_code, self.httpError(res))
|
|
|
|
self.assertEquals([], self.getPhpErrors(res))
|
2020-04-02 15:08:14 +02:00
|
|
|
obj = self.getJson(res)
|
2020-04-02 13:54:54 +02:00
|
|
|
self.assertEquals(True, obj["success"])
|
|
|
|
|
|
|
|
# Mail: SKIP
|
|
|
|
res = self.session.post(self.url, data={ "skip": "true" })
|
|
|
|
self.assertEquals(200, res.status_code, self.httpError(res))
|
|
|
|
self.assertEquals([], self.getPhpErrors(res))
|
2020-04-02 15:08:14 +02:00
|
|
|
obj = self.getJson(res)
|
2020-04-02 13:54:54 +02:00
|
|
|
self.assertEquals(True, obj["success"])
|
|
|
|
|
|
|
|
# Creation successful:
|
|
|
|
res = self.session.get(self.url)
|
|
|
|
self.assertEquals(200, res.status_code, self.httpError(res))
|
|
|
|
self.assertEquals([], self.getPhpErrors(res))
|