add some User functions, move api tests from js to python

This commit is contained in:
arnaucube
2019-06-14 20:00:11 +02:00
parent 8f0d0fd5e0
commit be27edda88
13 changed files with 290 additions and 158 deletions

1
test/.gitignore vendored
View File

@@ -1 +0,0 @@
node_modules

56
test/package-lock.json generated
View File

@@ -1,56 +0,0 @@
{
"name": "gogame-test",
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"axios": {
"version": "0.19.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz",
"integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==",
"requires": {
"follow-redirects": "1.5.10",
"is-buffer": "^2.0.2"
}
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
}
},
"is-buffer": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
"integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"nan": {
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz",
"integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg=="
},
"sleep": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/sleep/-/sleep-6.1.0.tgz",
"integrity": "sha512-Z1x4JjJxsru75Tqn8F4tnOFeEu3HjtITTsumYUiuz54sGKdISgLCek9AUlXlVVrkhltRFhNUsJDJE76SFHTDIQ==",
"requires": {
"nan": "^2.13.2"
}
}
}
}

View File

@@ -1,22 +0,0 @@
{
"name": "gogame-test",
"version": "0.0.1",
"description": "",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/arnaucube/gogame.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/arnaucube/gogame/issues"
},
"homepage": "https://github.com/arnaucube/gogame#readme",
"dependencies": {
"axios": "^0.19.0"
}
}

View File

@@ -1,29 +0,0 @@
const axios = require('axios');
const url = 'http://127.0.0.1:5000';
// let newUser = {
// name: 'user00',
// password: 'user00password',
// email: 'user00@email.com'
// };
// axios.post(url + '/register', newUser)
// .then(function (res) {
// console.log(res.data);
// })
// .catch(function (error) {
// console.error(error.response.data);
// });
let user = {
email: 'user00@email.com',
password: 'user00password'
};
axios.post(url + '/login', user)
.then(function (res) {
console.log(res.data);
})
.catch(function (error) {
console.error(error.response.data);
});

42
test/test.py Normal file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env python3
"""Test endpoints for gogame
"""
import json
import requests
import provoj
import time
import subprocess
subprocess.check_call(["mongo", "gogame", "--eval", "'db.dropDatabase()'"])
time.sleep(1)
URL = "http://127.0.0.1:5000"
t = provoj.NewTest("gogame")
registerData = {
"name": "user00",
"password": "user00password",
"email": "user00@email.com",
}
r = requests.post(URL + "/register", json=registerData)
t.rStatus("post /register", r)
jsonR = r.json()
print(jsonR)
time.sleep(1)
loginData = {
"email": "user00@email.com",
"password": "user00password",
}
r = requests.post(URL + "/login", json=loginData)
t.rStatus("post /login", r)
jsonR = r.json()
print(jsonR)
t.printScores()