feat(tests): add functions used to randomly generate users
This commit is contained in:
parent
632c03a2b9
commit
00c2715a83
@ -19,6 +19,7 @@ services:
|
|||||||
- ./lumi2/static/images/base:/app/lumi2/static/images/base:ro
|
- ./lumi2/static/images/base:/app/lumi2/static/images/base:ro
|
||||||
- ./lumi2/static/images/default:/app/lumi2/static/images/default:ro
|
- ./lumi2/static/images/default:/app/lumi2/static/images/default:ro
|
||||||
- ./lumi2/templates/:/app/lumi2/templates/:ro
|
- ./lumi2/templates/:/app/lumi2/templates/:ro
|
||||||
|
- ./tests/fakedata.py/:/app/tests/fakedata.py:ro
|
||||||
ports:
|
ports:
|
||||||
- "8000:80"
|
- "8000:80"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
10
lumi2/static/js/user_tables.js
Normal file
10
lumi2/static/js/user_tables.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
$(function() {
|
||||||
|
$("table").tablesorter({
|
||||||
|
theme: 'bootstrap',
|
||||||
|
headerTemplate: '{content} {icon}',
|
||||||
|
cssIcon: 'bi-arrow-down-up',
|
||||||
|
cssIconNone: '',
|
||||||
|
cssIconAsc: 'bi-arrow-up',
|
||||||
|
cssIconDesc: 'bi-arrow-down',
|
||||||
|
});
|
||||||
|
});
|
@ -50,5 +50,5 @@
|
|||||||
<p class="text-muted">There are currently no users.</p>
|
<p class="text-muted">There are currently no users.</p>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<script src="{{ url_for('static', filename='js/tables.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/user_tables.js') }}"></script>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
@ -294,6 +294,7 @@ def user_delete(username: str):
|
|||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
ldap.delete_user(conn, user.username)
|
ldap.delete_user(conn, user.username)
|
||||||
|
# FIXME delete user's static image folder!!!
|
||||||
conn.unbind()
|
conn.unbind()
|
||||||
flash(f"The user '{user.username}' was deleted.")
|
flash(f"The user '{user.username}' was deleted.")
|
||||||
for groupname in deleted_groups:
|
for groupname in deleted_groups:
|
||||||
|
@ -147,7 +147,7 @@ class GroupResource(Resource):
|
|||||||
def get(self, groupname: str):
|
def get(self, groupname: str):
|
||||||
"""Retrieves the group specified by the groupname as a JSON object.
|
"""Retrieves the group specified by the groupname as a JSON object.
|
||||||
|
|
||||||
Attributes
|
Parameters
|
||||||
----------
|
----------
|
||||||
groupname : str
|
groupname : str
|
||||||
The name of the group to be retrieved.
|
The name of the group to be retrieved.
|
||||||
@ -266,3 +266,39 @@ class GroupResource(Resource):
|
|||||||
ldap.update_group(conn, group)
|
ldap.update_group(conn, group)
|
||||||
conn.unbind()
|
conn.unbind()
|
||||||
return {"username": username}, 200
|
return {"username": username}, 200
|
||||||
|
|
||||||
|
|
||||||
|
class GroupMemberResource(Resource):
|
||||||
|
"""This resource represents the member of a group.
|
||||||
|
|
||||||
|
In JSON, a GroupMember is represented as follows:
|
||||||
|
{
|
||||||
|
"username": "myuser"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
def post(self, groupname):
|
||||||
|
"""Adds the user specified in the POST data to the specified Group."""
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def delete(self, groupname):
|
||||||
|
"""Removes the user specified in the POST data from the specified Group.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
groupname : str
|
||||||
|
The name of the Group from which a member will be deleted.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
json : str , status : int
|
||||||
|
A JSON string and HTTP status code.
|
||||||
|
If the request was handled successfully, the POST-data is
|
||||||
|
replied to the client and HTTP code 200 is returned.
|
||||||
|
If a failure occurred while processing the request, an appropriate
|
||||||
|
error message and HTTP error code are returned.
|
||||||
|
"""
|
||||||
|
|
||||||
|
pass
|
||||||
|
@ -7,3 +7,5 @@ WTForms==3.0.1
|
|||||||
wtforms[email]==3.0.1
|
wtforms[email]==3.0.1
|
||||||
Flask-WTF==1.0.1
|
Flask-WTF==1.0.1
|
||||||
Flask-RESTful==0.3.9
|
Flask-RESTful==0.3.9
|
||||||
|
Faker==15.3.3
|
||||||
|
requests==2.28.1
|
||||||
|
37
tests/fakedata.py
Normal file
37
tests/fakedata.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
"""Generates fake user accounts."""
|
||||||
|
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from PIL import Image
|
||||||
|
from faker import Faker
|
||||||
|
|
||||||
|
from lumi2.usermodel import User
|
||||||
|
|
||||||
|
|
||||||
|
def get_random_avatar() -> Image.Image:
|
||||||
|
"""Returns a PIL JPEG Image of an AI-generated person."""
|
||||||
|
|
||||||
|
url = "https://thispersondoesnotexist.com/image"
|
||||||
|
response = requests.get(url)
|
||||||
|
if response.status_code != 200:
|
||||||
|
raise RuntimeError(
|
||||||
|
f"Request to '{url}' failed with code {response.status_code}."
|
||||||
|
)
|
||||||
|
|
||||||
|
return Image.open(BytesIO(response.content))
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_user() -> User:
|
||||||
|
"""Generates a randomized user object and returns it."""
|
||||||
|
|
||||||
|
faker = Faker()
|
||||||
|
|
||||||
|
return User(
|
||||||
|
faker.user_name(),
|
||||||
|
User.generate_password_hash(faker.password()),
|
||||||
|
faker.email(),
|
||||||
|
faker.first_name(),
|
||||||
|
faker.last_name(),
|
||||||
|
picture=get_random_avatar(),
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user