Skip to content

Commit 42818af

Browse files
Merge branch 'development' into 'master'
Fix test and front errors See merge request hosting/api!37
2 parents 978384d + c09834e commit 42818af

File tree

9 files changed

+84
-16
lines changed

9 files changed

+84
-16
lines changed

backend/proxmox_api/db/db_functions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@ def get_user_list(user_id=None, searchItem = None): # filter is for the user nam
3535
return User.query.filter_by(id=user_id).first()
3636
elif searchItem is not None:
3737
search = "%{}%".format(searchItem)
38-
print("db search : ", search)
3938
start = time.time()
4039
filtered = User.query.filter(User.id.like(search)).all()
41-
print("db search time : ", time.time() - start)
4240
return filtered
4341

4442
else :

backend/proxmox_api/proxmox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def create_vm(name, vm_type, user_id, password="no", vm_user="", main_ssh_key="n
275275

276276

277277
if node[1] != 201:
278-
return node
278+
return {"error": "Impossible to find an available server"}, 500
279279
else:
280280
node = node[0]["server"]
281281

backend/test/conftest.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#
1616
@pytest.fixture()
1717
def init_user_database():
18+
if configuration.ENV != "DEV":
19+
raise Exception("You must set the environnement to DEV to run the tests")
1820
app = util.create_app()
1921
db = SQLAlchemy()
2022
db.init_app(app.app)
@@ -25,6 +27,8 @@ def init_user_database():
2527
db.create_all()
2628
# List of test users
2729
test_users = [
30+
{"id": "user-1", "freezeState": "0.0", "lastNotificationDate": None},
31+
{"id": "user-2", "freezeState": "0.0", "lastNotificationDate": None},
2832
{"id": "valid-user", "freezeState": "0.0", "lastNotificationDate": None},
2933
{"id": "expired-user-1", "freezeState": "1.0", "lastNotificationDate": None},
3034
{"id": "expired-user-2", "freezeState": "2.0", "lastNotificationDate": None},
@@ -59,18 +63,18 @@ def create_post_model(user):
5963

6064
@pytest.fixture()
6165
def init_vm_database():
66+
if configuration.ENV != "DEV":
67+
raise Exception("You must set the environnement to DEV to run the tests")
6268
app = util.create_app()
6369
db = SQLAlchemy()
6470
db.init_app(app.app)
6571
with app.app.app_context():
66-
db.session.query(model.Vm).delete()
67-
db.session.query(model.User).delete()
72+
try:
73+
db.session.query(model.Vm).delete()
74+
except:
75+
print("No VM to delete")
6876
db.create_all()
69-
# List of test users
70-
test_users = [
71-
{"id": "user-1", "freezeState": "0.0", "lastNotificationDate": None},
72-
{"id": "user-2", "freezeState": "0.0", "lastNotificationDate": None},
73-
]
77+
7478
# List of test VM
7579
test_vms = [
7680
{"id" : 1, "userId" : "user-1", "type":"bare", "ip" : None, "mac" : None,"needToBeRestored" : False},
@@ -88,12 +92,9 @@ def create_vm_model(vms):
8892
return model.Vm(**vms)
8993

9094
# Create a list of objects
91-
mapped_users = map(create_user_model, test_users)
92-
t_users = list(mapped_users)
9395
mapped_vms = map(create_vm_model, test_vms)
9496
t_vms = list(mapped_vms)
9597

96-
db.session.add_all(t_users)
9798
db.session.add_all(t_vms)
9899

99100
# Commit the changes for the users

backend/test/integration/test_vm_life.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def fake_set_new_vm_ip(next_vmid, node):
5252

5353

5454
body,status = proxmox.create_vm("INTEGRATION-TEST-VM", "bare_vm", "valid-user", password="1A#aaaaaaaaa", vm_user="user", main_ssh_key="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKWkpOTUuLKpZEQT2CmEsgZwZzegitYCx/8vHICvv261 fake@key")
55-
assert status == 201
55+
assert status == 201
5656
start_time = time.time()
5757
configuration_state = "creating"
5858
while time.time() - start_time <= 600 and configuration_state == "creating": # timeout after 10min

backend/test/test-vm-creation-form.py

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import pytest
2+
from proxmox_api import proxmox
3+
from test.conftest import *
4+
from proxmox_api.db import db_functions
5+
6+
7+
8+
9+
def test_creation_for_new_user(monkeypatch,init_user_database, init_vm_database, proxmoxAPI):
10+
"""Test case for creation of VM by a new user
11+
The creation does not concern proxmox
12+
"""
13+
14+
node = "wammu"
15+
16+
def fake_next_available_vmid():
17+
return "999"
18+
19+
def fake_set_new_vm_ip(next_vmid, node):
20+
return "127.0.0.1"
21+
22+
def fake_load_balance_server():
23+
return {'server' :'wammu'},201
24+
25+
def fake_proxmox_clone_vm(name, newid,target, full):
26+
return True
27+
28+
def fake_vm_config(vmid, node, password, vm_user,main_ssh_key, ip):
29+
return True
30+
31+
def fake_check_update_cotisation(user_id):
32+
return {"freezeState": "1"}, 200
33+
34+
35+
36+
app = util.create_app()
37+
db = SQLAlchemy()
38+
db.init_app(app.app)
39+
with app.app.app_context():
40+
# Mocking
41+
monkeypatch.setattr(proxmox, 'next_available_vmid', fake_next_available_vmid)
42+
monkeypatch.setattr(proxmox, 'set_new_vm_ip', fake_set_new_vm_ip)
43+
monkeypatch.setattr(proxmoxAPI.nodes("wammu").qemu(10003).clone, 'create', fake_proxmox_clone_vm)
44+
monkeypatch.setattr(proxmox, 'load_balance_server', fake_load_balance_server)
45+
monkeypatch.setattr(proxmox, 'config_vm', fake_vm_config)
46+
monkeypatch.setattr(proxmox, 'check_update_cotisation', fake_check_update_cotisation)
47+
48+
userId = "new-user6"
49+
body,status = proxmox.create_vm("INTEGRATION-TEST-VM", "bare_vm", userId, password="1A#aaaaaaaaa", vm_user="user", main_ssh_key="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKWkpOTUuLKpZEQT2CmEsgZwZzegitYCx/8vHICvv261 fake@key")
50+
assert status == 201
51+
userVms = db_functions.get_vm_list(user_id=userId)
52+
assert len(userVms) == 1
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+

frontend/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<router-outlet *ngIf="(validToken$ | async) || router.url === this.cookie.get('lang')+'/manual' || router.url === this.cookie.get('lang')+'/legal'; else landing"></router-outlet>
44
<ng-template #landing>
55
<div class="text-center">
6-
<img id="logo" class="mb-3" style="height: 150px" src="assets/images/minet.png">
6+
<img id="logo" class="mb-3" style="height: 150px" src="assets/images/minet_light_noel.png">
77
<div class="alert alert-success" role="alert">
88
<p>Welcome to MiNET's new hosting service. It is still in beta, please report any problem
99
to our <a href="mailto:[email protected]"> webmaster</a>.</p>

frontend/src/app/navbar/navbar.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<a class="navbar-brand" [routerLink]="['/']">
33
<img src="../../assets/images/logo.png" height="30" style="margin-right: 10px"/>
44
MiNET Hosting
5+
<span class="badge bg-secondary">Beta Publique </span>
56
</a>
67
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav"
78
aria-expanded="false" aria-label="Toggle navigation">
138 KB
Loading

0 commit comments

Comments
 (0)