Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta editor #19

Merged
merged 13 commits into from
Jun 29, 2024
40 changes: 32 additions & 8 deletions App/home.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
from flask import request, render_template, session, redirect, flash
from flask import request, render_template, session, redirect, flash, url_for
from App.utils import bdd, utils, cloudflare
import bcrypt
import json


def index():
return render_template('home/index.html')

def parametres_generaux(devlobdd):
if request.method == 'POST':
form_data = request.form.to_dict(flat=False) # Convert ImmutableMultiDict to regular dict
print(form_data)
devlobdd.boom_boom(form_data, session['ja_id'])
return render_template('home/parametres_generaux.html', data=devlobdd.get_site_by_ja(session['ja_id']))


def editeur():
json_site = json.loads(open(f"tmp/{session['ja_id']}/site.json").read())
print(json_site)

if request.method == "POST":
form = request.form.to_dict()
with open(f"tmp/{session['ja_id']}/site.json", "w") as f:
json.dump(form, f)
json_site = json.loads(open(f"tmp/{session['ja_id']}/site.json").read())

return render_template("editor/v1/editeur.html", data=json_site)

def v1():
if 'email' not in session:
return redirect(url_for('route_connexion'))

json_site = json.loads(open(f"tmp/{session['ja_id']}/site.json").read())
print(json_site)

if request.method == "POST":
form = request.form.to_dict()
with open(f"tmp/{session['ja_id']}/site.json", "w") as f:
json.dump(form, f)
print(form)

return render_template("editor/v1/editeur.html", data=json_site)



def parametres_theme(devlobdd):
if request.method == 'POST':
Expand Down
2 changes: 1 addition & 1 deletion App/pof.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ def proof_of_concept():
json.dump(form, f)
print(form)

return render_template("pof.html", data=json_site)
return render_template("editor/pof.html", data=json_site)
13 changes: 13 additions & 0 deletions conftest.py → App/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
import pytest
from devloapp import app
import os


app.which = "devlotest"
os.system("rm -rf ~/PycharmProjects/devloweb/devlotest.db")
os.system("rm -rf ~/PycharmProjects/devloweb/App/tests/devlotest.db")


@pytest.fixture
def client():
with app.test_client() as client:
yield client


def pytest_addoption(parser):
Expand Down
45 changes: 45 additions & 0 deletions App/tests/test_editeur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json
from test_inscription import devlobdd, req_connection, req_code_verif


def setup_account(client, devlobdd):
devlobdd.delete_ja("[email protected]")
client.post('/inscription', data={
"email": "[email protected]",
"ja_id": "JA-8166",
"password": "jesuisunebananeavecdespouvoirsmagiques" # +12 caractères
})
code = devlobdd.get_code_via_jaid("8166")[1]
req_code_verif(client, "JA-8166", code)
req_connection(client, "[email protected]", "jesuisunebananeavecdespouvoirsmagiques")


def test_editor_access_without_account(client):
response = client.get('/home/editeur')
assert response.status_code == 302


def test_good_editor_access(client, devlobdd):
setup_account(client, devlobdd)
response = client.get('/home/editeur')

assert response.status_code == 200

def test_modify_site(client, devlobdd):
with client.session_transaction() as c:
c["ja_id"] = "8166"
c["email"] = "[email protected]"
c["ip"] = "127.0.0.1"
c["avatar"] = "https://gravatar.com/avatar/8166.png?d=mp"

response = client.post('/editeur/pof', data={
"titre": "test",
"valeur1": "test",
"valider": ""
})

json_site = json.loads(open(f"tmp/8166/site.json").read())

assert response.status_code == 200
assert json_site["titre"] == "test"
assert json_site["valeur1"] == "test"
Loading