add customer_users_table_view

This commit is contained in:
Andreas Zweili 2019-12-30 11:17:24 +01:00
parent 1b48ded52d
commit dac5e2744a
4 changed files with 79 additions and 1 deletions

View File

@ -98,3 +98,14 @@ class ComputerLicensesTable(tables.Table):
class Meta:
template_name = 'django_tables2/semantic.html'
model = ComputerLicense
class UsersTable(tables.Table):
id = tables.Column(visible=False)
customer = tables.Column('Customer', linkify=True)
ad_groups = tables.ManyToManyColumn()
mail_groups = tables.ManyToManyColumn()
class Meta:
template_name = 'django_tables2/semantic.html'
model = User

View File

@ -0,0 +1,6 @@
{% extends "inventory/base.html" %}
{% load render_table from django_tables2 %}
{% block section_title %}Users{% endblock %}
{% block content %}
{% render_table users %}
{% endblock %}

View File

@ -0,0 +1,58 @@
import pytest
from django.test import Client
from mixer.backend.django import mixer
import helper
from inventory.models import Customer
pytestmark = pytest.mark.django_db
def test_customer_user_table_not_logged_in():
response = Client().get('/customer/1/users/')
assert response.status_code == 302 and 'login' in response.url
def test_customer_user_table(create_admin_user):
fixture = create_admin_user()
customer = fixture['customer']
client = Client()
client.login(username="novartis-admin", password="password")
user = mixer.blend('inventory.User', customer=mixer.SELECT)
response = client.get('/customer/' + str(customer.id) + '/users/')
assert (response.status_code == 200
and helper.in_content(response, user))
def test_customer_user_table_no_user(create_admin_user):
fixture = create_admin_user()
customer = fixture['customer']
client = Client()
client.login(username="novartis-admin", password="password")
response = client.get('/customer/' + str(customer.id) + '/users/')
assert (response.status_code == 200
and helper.not_in_content(response, "Novartis PC"))
def test_customer_user_table_no_permission(create_admin_user):
create_admin_user()
customer = Customer.objects.create(name='Nestle')
client = Client()
client.login(username="novartis-admin", password="password")
mixer.blend('inventory.User', customer=customer)
response = client.get('/customer/' + str(customer.id) + '/users/')
assert response.status_code == 403
def test_customer_user_table_multiple_users(create_admin_user):
fixture = create_admin_user()
customer = fixture['customer']
client = Client()
client.login(username="novartis-admin", password="password")
user1 = mixer.blend('inventory.User', customer=mixer.SELECT)
user2 = mixer.blend('inventory.User', customer=mixer.SELECT)
response = client.get('/customer/' + str(customer.id) + '/users/')
assert (response.status_code == 200
and helper.in_content(response, user1)
and helper.in_content(response, user2))

View File

@ -39,6 +39,7 @@ from .tables import DevicesTable
from .tables import NetDetailTable
from .tables import NetsTable
from .tables import UserLicensesTable
from .tables import UsersTable
@login_required
@ -172,4 +173,6 @@ def licenses_table_view(request, pk):
@login_required
@customer_view_permission
def users_table_view(request, pk):
pass
table = UsersTable(User.objects.filter(customer=pk))
RequestConfig(request).configure(table)
return render(request, 'inventory/user_list.html', {'users': table})