generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from Arquisoft/pepito
Pepito
- Loading branch information
Showing
15 changed files
with
478 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import tkinter as tk | ||
from tkinter import scrolledtext, messagebox | ||
import requests | ||
import json | ||
|
||
# Define the domain constant | ||
DOMAIN = "http://158.179.216.208:8000" | ||
|
||
# Global variable to store the auth token | ||
auth_token = None | ||
|
||
def format_json_display(json_text): | ||
try: | ||
parsed = json.loads(json_text) | ||
formatted_json = json.dumps(parsed, indent=4) | ||
return formatted_json | ||
except json.JSONDecodeError: | ||
return json_text # return original text if it's not JSON | ||
|
||
def login(): | ||
global auth_token | ||
try: | ||
# Getting username and password from the GUI | ||
username = username_entry.get() | ||
password = password_entry.get() | ||
|
||
# Sending POST request to login | ||
response = requests.post(f"{DOMAIN}/login", json={"username": username, "password": password}) | ||
if response.status_code == 200: | ||
auth_token = response.json().get('token') | ||
response_display.config(state=tk.NORMAL) | ||
response_display.delete('1.0', tk.END) | ||
response_display.insert(tk.END, "Login Successful!\n") | ||
response_display.config(state=tk.DISABLED) | ||
else: | ||
raise Exception("Login failed with status code: " + str(response.status_code)) | ||
except Exception as e: | ||
messagebox.showerror("Login Error", str(e)) | ||
|
||
def send_post_request(): | ||
global auth_token | ||
try: | ||
# Extracting and preparing JSON data from the text field | ||
json_data = json_input.get("1.0", tk.END) | ||
json_payload = json.loads(json_data) | ||
|
||
# Sending POST request | ||
headers = {"Authorization": f"Bearer {auth_token}"} | ||
response = requests.post(f"{DOMAIN}/admin/addGroups", json=json_payload, headers=headers) | ||
response_display.config(state=tk.NORMAL) | ||
response_display.delete('1.0', tk.END) | ||
response_display.insert(tk.END, f"POST Response:\n{format_json_display(response.text)}\n") | ||
response_display.config(state=tk.DISABLED) | ||
except Exception as e: | ||
messagebox.showerror("Request Error", str(e)) | ||
|
||
def send_get_groups_request(): | ||
global auth_token | ||
try: | ||
# Sending GET request | ||
headers = {"Authorization": f"Bearer {auth_token}"} | ||
response = requests.get(f"{DOMAIN}/admin/groups", headers=headers) | ||
response_display.config(state=tk.NORMAL) | ||
response_display.delete('1.0', tk.END) | ||
response_display.insert(tk.END, f"Groups Data:\n{format_json_display(response.text)}\n") | ||
response_display.config(state=tk.DISABLED) | ||
except Exception as e: | ||
messagebox.showerror("Request Error", str(e)) | ||
|
||
def send_remove_group_request(): | ||
global auth_token | ||
try: | ||
group_id = group_id_entry.get() | ||
url = f"{DOMAIN}/admin/removeGroup/{group_id}" | ||
|
||
# Sending GET request | ||
headers = {"Authorization": f"Bearer {auth_token}"} | ||
response = requests.get(url, headers=headers) | ||
response_display.config(state=tk.NORMAL) | ||
response_display.delete('1.0', tk.END) | ||
response_display.insert(tk.END, f"Remove Group Response:\n{format_json_display(response.text)}\n") | ||
response_display.config(state=tk.DISABLED) | ||
except Exception as e: | ||
messagebox.showerror("Request Error", str(e)) | ||
|
||
def send_gen_request(): | ||
global auth_token | ||
try: | ||
# Sending GET request | ||
headers = {"Authorization": f"Bearer {auth_token}"} | ||
response = requests.get(f"{DOMAIN}/admin/gen", headers=headers) | ||
response_display.config(state=tk.NORMAL) | ||
response_display.delete('1.0', tk.END) | ||
response_display.insert(tk.END, f"Gen Response:\n{format_json_display(response.text)}\n") | ||
response_display.config(state=tk.DISABLED) | ||
except Exception as e: | ||
messagebox.showerror("Request Error", str(e)) | ||
|
||
def main(): | ||
global json_input, response_display, group_id_entry, username_entry, password_entry | ||
|
||
# Setting up the main window | ||
root = tk.Tk() | ||
root.title("jordiPanel Admin") | ||
root.geometry("600x700") # Set the window size | ||
|
||
# Login Frame | ||
login_frame = tk.Frame(root, padx=10, pady=10) | ||
login_frame.pack(pady=(10, 0)) | ||
tk.Label(login_frame, text="Username:").pack(side=tk.LEFT) | ||
username_entry = tk.Entry(login_frame) | ||
username_entry.pack(side=tk.LEFT, padx=(0, 10)) | ||
tk.Label(login_frame, text="Password:").pack(side=tk.LEFT) | ||
password_entry = tk.Entry(login_frame, show="*") | ||
password_entry.pack(side=tk.LEFT, padx=(0, 10)) | ||
login_button = tk.Button(login_frame, text="Login", command=login) | ||
login_button.pack(side=tk.LEFT) | ||
|
||
|
||
# Data Input Frame | ||
data_frame = tk.Frame(root, padx=10, pady=10) | ||
data_frame.pack(pady=(10, 0)) | ||
tk.Label(data_frame, text="JSON Data:").pack() | ||
json_input = scrolledtext.ScrolledText(data_frame, height=10, width=70) | ||
json_input.pack() | ||
|
||
# Operations Frame | ||
operations_frame = tk.Frame(root, padx=10, pady=10) | ||
operations_frame.pack(pady=(10, 0)) | ||
post_button = tk.Button(operations_frame, text="Add Groups", command=send_post_request) | ||
post_button.pack(side=tk.LEFT, padx=5) | ||
get_groups_button = tk.Button(operations_frame, text="Get Groups", command=send_get_groups_request) | ||
get_groups_button.pack(side=tk.LEFT, padx=5) | ||
group_id_entry = tk.Entry(operations_frame, width=20) | ||
group_id_entry.pack(side=tk.LEFT, padx=5) | ||
remove_group_button = tk.Button(operations_frame, text="Remove Group", command=send_remove_group_request) | ||
remove_group_button.pack(side=tk.LEFT, padx=5) | ||
gen_button = tk.Button(operations_frame, text="Generate", command=send_gen_request) | ||
gen_button.pack(side=tk.LEFT, padx=5) | ||
|
||
# Response Display Area | ||
response_display = scrolledtext.ScrolledText(root, height=20, width=70, bg="light grey") | ||
response_display.pack(pady=(10, 0)) | ||
response_display.config(state=tk.DISABLED) | ||
|
||
root.mainloop() | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
[ | ||
{ | ||
"groupId": "capitals", | ||
"questionItem": "Q6256", | ||
"answer": "P36", | ||
"statements": [ | ||
"The capital of <QuestionItem> is...", | ||
"What is the capital of <QuestionItem>?", | ||
"Select the capital of <QuestionItem>" | ||
], | ||
"categories": [ | ||
"capitals", | ||
"geography" | ||
] | ||
}, | ||
{ | ||
"groupId": "continent", | ||
"questionItem": "Q6256", | ||
"answer": "P30", | ||
"statements": [ | ||
"The continent of <QuestionItem> is...", | ||
"What is the continent of <QuestionItem>?", | ||
"Select the continent of <QuestionItem>" | ||
], | ||
"categories": [ | ||
"continent", | ||
"geography" | ||
] | ||
}, | ||
{ | ||
"groupId": "languages", | ||
"questionItem": "Q6256", | ||
"answer": "P37", | ||
"statements": [ | ||
"The language spoken in <QuestionItem> is...", | ||
"What is the language spoken in <QuestionItem>?", | ||
"Select the language spoken in <QuestionItem>" | ||
], | ||
"categories": [ | ||
"languages", | ||
"geography" | ||
] | ||
}, | ||
{ | ||
"groupId": "population", | ||
"questionItem": "Q6256", | ||
"answer": "P1082", | ||
"statements": [ | ||
"The population of <QuestionItem> is...", | ||
"What is the population of <QuestionItem>", | ||
"Select the population of <QuestionItem>" | ||
], | ||
"categories": [ | ||
"population", | ||
"geography" | ||
], | ||
"plainText": true, | ||
"filter": "FILTER(LANG(?question) = 'en')" | ||
}, | ||
{ | ||
"groupId": "area", | ||
"questionItem": "Q6256", | ||
"answer": "P2046", | ||
"statements": [ | ||
"The area of <QuestionItem> is...", | ||
"What is the area of <QuestionItem>", | ||
"Select the area of <QuestionItem>" | ||
], | ||
"categories": [ | ||
"area", | ||
"geography" | ||
], | ||
"plainText": true, | ||
"filter": "FILTER(LANG(?question) = 'en')" | ||
}, | ||
{ | ||
"groupId": "gdp", | ||
"questionItem": "Q6256", | ||
"answer": "P2131", | ||
"statements": [ | ||
"The GDP of <QuestionItem> is...", | ||
"What is the GDP of <QuestionItem>", | ||
"Select the GDP of <QuestionItem>" | ||
], | ||
"categories": [ | ||
"gdp", | ||
"geography" | ||
], | ||
"plainText": true, | ||
"filter": "FILTER(LANG(?question) = 'en')" | ||
}, | ||
{ | ||
"groupId": "currency", | ||
"questionItem": "Q6256", | ||
"answer": "P38", | ||
"statements": [ | ||
"The currency of <QuestionItem> is...", | ||
"What is the currency of <QuestionItem>", | ||
"Select the currency of <QuestionItem>" | ||
], | ||
"categories": [ | ||
"currency", | ||
"geography", | ||
"economy" | ||
] | ||
}, | ||
{ | ||
"groupId": "president", | ||
"questionItem": "Q6256", | ||
"answer": "P35", | ||
"statements": [ | ||
"The president of <QuestionItem> is...", | ||
"Who is the president of <QuestionItem>", | ||
"Select the president of <QuestionItem>" | ||
], | ||
"categories": [ | ||
"president", | ||
"geography", | ||
"politics" | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# -*- coding: utf-8 -*- | ||
|
||
import json | ||
import requests | ||
|
||
""" | ||
Template File | ||
:author Álvaro García Fdez: | ||
:version 2024-04-25: | ||
""" | ||
|
||
|
||
|
||
def main(): | ||
data = None | ||
with open('groups.json') as f: | ||
data = json.load(f) | ||
response = requests.post('http://localhost:8003/addGroups', json=data) | ||
print(response.status_code) | ||
print(response.text) | ||
|
||
requests.get('http://localhost:8003/gen') | ||
pass | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import '@testing-library/jest-dom'; | ||
import { fireEvent, screen } from "@testing-library/react"; | ||
import React from "react"; | ||
import InfoSnackBar from "../../views/components/InfoSnackBar"; | ||
import { customRender } from "../utils/customRenderer"; | ||
|
||
const render = customRender(); | ||
|
||
describe("InfoSnackBar component", () => { | ||
test("renders snackbar with provided info message", () => { | ||
const infoMsg = "important info"; | ||
const setMsg = jest.fn(); | ||
|
||
render(<InfoSnackBar msg={infoMsg} setMsg={setMsg} />); | ||
expect(screen.getByRole("alert")).toBeInTheDocument(); | ||
expect(screen.getByText(`Info: ${infoMsg}`)).toBeInTheDocument(); | ||
expect(screen.getByLabelText("close")).toBeInTheDocument(); | ||
fireEvent.click(screen.getByLabelText("close")); | ||
expect(setMsg).toHaveBeenCalledWith(""); | ||
}); | ||
|
||
test("does not render Snackbar when no info message provided", () => { | ||
const setMsg = jest.fn(); | ||
|
||
render(<InfoSnackBar msg="" setMsg={setMsg} />); | ||
expect(screen.queryByRole("alert")).not.toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.