Fix tests
This commit is contained in:
parent
866f6c8083
commit
d88745f46b
11 changed files with 35 additions and 116 deletions
|
@ -1,11 +0,0 @@
|
||||||
{% extends "base.html" %}
|
|
||||||
{% load i18n %}
|
|
||||||
{% block title %}{{ block.super }} - {% translate "Welcome" %}{% endblock title %}
|
|
||||||
{% block page_title %}{% translate "Welcome to our customer self service" %}{% endblock page_title %}
|
|
||||||
{% block content %}
|
|
||||||
<p>{% url 'customer_dashboard' slug=user.username as dashboard_url %}
|
|
||||||
{% blocktranslate with full_name=user.get_full_name trimmed %}
|
|
||||||
Hello {{ full_name }},<br/>
|
|
||||||
You can visit your <a href="{{ dashboard_url }}">Dashboard</a> to view and modify your hosting options.
|
|
||||||
{% endblocktranslate %}</p>
|
|
||||||
{% endblock content %}
|
|
|
@ -1,9 +1,9 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% block title %}{{ block.super }} - {% blocktranslate with full_name=dashboard_user.get_full_name trimmed %}
|
{% block title %}{{ block.super }} - {% blocktranslate with full_name=request.user.get_full_name trimmed %}
|
||||||
Dashboard for {{ full_name }}
|
Dashboard for {{ full_name }}
|
||||||
{% endblocktranslate %}{% endblock title %}
|
{% endblocktranslate %}{% endblock title %}
|
||||||
{% block page_title %}{% blocktranslate with full_name=dashboard_user.get_full_name trimmed %}
|
{% block page_title %}{% blocktranslate with full_name=request.user.get_full_name trimmed %}
|
||||||
Dashboard for {{ full_name }}
|
Dashboard for {{ full_name }}
|
||||||
{% endblocktranslate %}{% endblock page_title %}
|
{% endblocktranslate %}{% endblock page_title %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
{% translate "This user has no hosting packages assigned yet." %}{% endif %}</p>
|
{% translate "This user has no hosting packages assigned yet." %}{% endif %}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if user.is_staff %}
|
{% if user.is_staff %}
|
||||||
<a href="{% url "create_customer_hosting_package" user=object.username %}"
|
<a href="{% url "create_customer_hosting_package" user=request.user.username %}"
|
||||||
class="btn btn-primary">{% translate "Add hosting package" %}</a>
|
class="btn btn-primary">{% translate "Add hosting package" %}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Tests for :py:mod:`dashboard.views`.
|
Tests for :py:mod:`dashboard.views`.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from django import http
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
@ -13,65 +13,35 @@ TEST_USER = "test"
|
||||||
TEST_PASSWORD = "secret"
|
TEST_PASSWORD = "secret"
|
||||||
|
|
||||||
|
|
||||||
class IndexViewTest(TestCase):
|
|
||||||
def test_index_view_anonymous(self):
|
|
||||||
response = self.client.get(reverse("dashboard"))
|
|
||||||
self.assertRedirects(response, "/accounts/login/?next=/")
|
|
||||||
|
|
||||||
def test_index_view(self):
|
|
||||||
user = User.objects.create(username=TEST_USER)
|
|
||||||
user.set_password(TEST_PASSWORD)
|
|
||||||
user.save()
|
|
||||||
|
|
||||||
self.client.login(username=TEST_USER, password=TEST_PASSWORD)
|
|
||||||
|
|
||||||
response = self.client.get(reverse("dashboard"))
|
|
||||||
self.assertEqual(response.status_code, 200)
|
|
||||||
self.assertTemplateUsed(response, "dashboard/index.html")
|
|
||||||
|
|
||||||
|
|
||||||
class UserDashboardViewTest(TestCase):
|
class UserDashboardViewTest(TestCase):
|
||||||
def _create_test_user(self):
|
def _create_test_user(self):
|
||||||
self.user = User.objects.create(username=TEST_USER)
|
self.user = User.objects.create(username=TEST_USER)
|
||||||
self.user.set_password(TEST_PASSWORD)
|
self.user.set_password(TEST_PASSWORD)
|
||||||
self.user.save()
|
self.user.save()
|
||||||
|
|
||||||
def test_user_dashboard_view_no_user(self):
|
|
||||||
response = self.client.get(
|
|
||||||
reverse("customer_dashboard", kwargs={"slug": TEST_USER})
|
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, 404)
|
|
||||||
|
|
||||||
def test_user_dashboard_view_anonymous(self):
|
def test_user_dashboard_view_anonymous(self):
|
||||||
User.objects.create(username=TEST_USER)
|
User.objects.create(username=TEST_USER)
|
||||||
response = self.client.get(
|
response = self.client.get(reverse("customer_dashboard"))
|
||||||
reverse("customer_dashboard", kwargs={"slug": TEST_USER})
|
self.assertEqual(response.status_code, 302)
|
||||||
)
|
self.assertRedirects(response, "/accounts/login/?next=/")
|
||||||
self.assertEqual(response.status_code, 403)
|
|
||||||
|
|
||||||
def test_user_dashboard_view_logged_in_ok(self):
|
def test_user_dashboard_view_logged_in_ok(self):
|
||||||
self._create_test_user()
|
self._create_test_user()
|
||||||
self.assertTrue(self.client.login(username=TEST_USER, password=TEST_PASSWORD))
|
self.assertTrue(self.client.login(username=TEST_USER, password=TEST_PASSWORD))
|
||||||
response = self.client.get(
|
response = self.client.get(reverse("customer_dashboard"))
|
||||||
reverse("customer_dashboard", kwargs={"slug": TEST_USER})
|
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_user_dashboard_view_logged_in_template(self):
|
def test_user_dashboard_view_logged_in_template(self):
|
||||||
self._create_test_user()
|
self._create_test_user()
|
||||||
self.assertTrue(self.client.login(username=TEST_USER, password=TEST_PASSWORD))
|
self.assertTrue(self.client.login(username=TEST_USER, password=TEST_PASSWORD))
|
||||||
response = self.client.get(
|
response = self.client.get(
|
||||||
reverse("customer_dashboard", kwargs={"slug": TEST_USER})
|
reverse("customer_dashboard")
|
||||||
)
|
)
|
||||||
self.assertTemplateUsed(response, "dashboard/user_dashboard.html")
|
self.assertTemplateUsed(response, "dashboard/user_dashboard.html")
|
||||||
|
|
||||||
def test_user_dashboard_view_logged_in_context_fresh(self):
|
def test_user_dashboard_view_logged_in_context_fresh(self):
|
||||||
self._create_test_user()
|
self._create_test_user()
|
||||||
self.assertTrue(self.client.login(username=TEST_USER, password=TEST_PASSWORD))
|
self.assertTrue(self.client.login(username=TEST_USER, password=TEST_PASSWORD))
|
||||||
response = self.client.get(
|
response = self.client.get(reverse("customer_dashboard"))
|
||||||
reverse("customer_dashboard", kwargs={"slug": TEST_USER})
|
|
||||||
)
|
|
||||||
self.assertIn("dashboard_user", response.context)
|
|
||||||
self.assertEqual(self.user, response.context["dashboard_user"])
|
|
||||||
self.assertIn("hosting_packages", response.context)
|
self.assertIn("hosting_packages", response.context)
|
||||||
self.assertEqual(len(response.context["hosting_packages"]), 0)
|
self.assertEqual(len(response.context["hosting_packages"]), 0)
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from django.urls import re_path
|
from django.urls import path
|
||||||
|
|
||||||
from .views import IndexView, UserDashboardView
|
from .views import UserDashboardView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
re_path(r"^$", IndexView.as_view(), name="dashboard"),
|
path("", UserDashboardView.as_view(), name="customer_dashboard"),
|
||||||
re_path(
|
|
||||||
r"^user/(?P<slug>[\w0-9@.+-_]+)/$",
|
|
||||||
UserDashboardView.as_view(),
|
|
||||||
name="customer_dashboard",
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -11,41 +11,17 @@ from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
||||||
from hostingpackages.models import CustomerHostingPackage
|
from hostingpackages.models import CustomerHostingPackage
|
||||||
|
|
||||||
|
|
||||||
class IndexView(LoginRequiredMixin, TemplateView):
|
class UserDashboardView(LoginRequiredMixin, TemplateView):
|
||||||
"""
|
|
||||||
This is the dashboard view.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
template_name = "dashboard/index.html"
|
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
if not request.user.is_anonymous:
|
|
||||||
return redirect("customer_dashboard", slug=request.user.username)
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class UserDashboardView(StaffOrSelfLoginRequiredMixin, DetailView):
|
|
||||||
"""
|
"""
|
||||||
This is the user dashboard view.
|
This is the user dashboard view.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
model = get_user_model()
|
|
||||||
context_object_name = "dashboard_user"
|
|
||||||
slug_field = "username"
|
|
||||||
template_name = "dashboard/user_dashboard.html"
|
template_name = "dashboard/user_dashboard.html"
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(UserDashboardView, self).get_context_data(**kwargs)
|
context = super(UserDashboardView, self).get_context_data(**kwargs)
|
||||||
context["hosting_packages"] = CustomerHostingPackage.objects.filter(
|
context["hosting_packages"] = CustomerHostingPackage.objects.filter(
|
||||||
customer=self.object
|
customer=self.request.user
|
||||||
)
|
)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_customer_object(self):
|
|
||||||
"""
|
|
||||||
Returns the customer object.
|
|
||||||
|
|
||||||
"""
|
|
||||||
return self.get_object()
|
|
||||||
|
|
|
@ -56,15 +56,6 @@ class NavigationContextProcessorTest(TestCase):
|
||||||
self._check_static_urls(response.context)
|
self._check_static_urls(response.context)
|
||||||
self.assertEqual(response.context["active_item"], "contact")
|
self.assertEqual(response.context["active_item"], "contact")
|
||||||
|
|
||||||
def test_hostingpackage_page_context(self):
|
|
||||||
User.objects.create_user("test", password="test")
|
|
||||||
self.client.login(username="test", password="test")
|
|
||||||
response = self.client.get(reverse("hosting_packages", kwargs={"user": "test"}))
|
|
||||||
for item in self.EXPECTED_ITEMS:
|
|
||||||
self.assertIn(item, response.context)
|
|
||||||
self._check_static_urls(response.context)
|
|
||||||
self.assertEqual(response.context["active_item"], "hostingpackage")
|
|
||||||
|
|
||||||
def _test_page_context_by_viewmodule(self, viewmodule, expecteditem):
|
def _test_page_context_by_viewmodule(self, viewmodule, expecteditem):
|
||||||
request = HttpRequest()
|
request = HttpRequest()
|
||||||
request.resolver_match = MagicMock()
|
request.resolver_match = MagicMock()
|
||||||
|
|
|
@ -21,9 +21,8 @@
|
||||||
{% for package in customerhostingpackage_list %}
|
{% for package in customerhostingpackage_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ package.get_absolute_url }}">{{ package.name }}</a></td>
|
<td><a href="{{ package.get_absolute_url }}">{{ package.name }}</a></td>
|
||||||
<td>
|
<td>{{ package.customer }}</td>
|
||||||
<a href="{% url 'customer_dashboard' slug=package.customer.username %}">{{ package.customer }}</a>
|
<td>{{ package.osuser.username }}</td>
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
{% with diskspace=package.get_disk_space %}
|
{% with diskspace=package.get_disk_space %}
|
||||||
<span title="{% blocktranslate trimmed %}
|
<span title="{% blocktranslate trimmed %}
|
||||||
|
@ -40,7 +39,6 @@
|
||||||
{% include "userdbs/snippets/db_type.html" with db_type=dbtype.db_type %}
|
{% include "userdbs/snippets/db_type.html" with db_type=dbtype.db_type %}
|
||||||
{% if not forloop.last %} / {% endif %}
|
{% if not forloop.last %} / {% endif %}
|
||||||
{% endfor %}</td>
|
{% endfor %}</td>
|
||||||
<td>{{ package.osuser.username }}</td>
|
|
||||||
<td>{{ package.created }}</td>
|
<td>{{ package.created }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -212,7 +212,7 @@ class GroupTest(TestCaseWithCeleryTasks):
|
||||||
group.delete()
|
group.delete()
|
||||||
self.assertEqual(len(Group.objects.all()), 0)
|
self.assertEqual(len(Group.objects.all()), 0)
|
||||||
self.assertEqual(len(TaskResult.objects.all()), 2)
|
self.assertEqual(len(TaskResult.objects.all()), 2)
|
||||||
tr = TaskResult.objects.first()
|
tr = TaskResult.objects.order_by("created").first()
|
||||||
self.assertEqual(tr.creator, "handle_group_created")
|
self.assertEqual(tr.creator, "handle_group_created")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class FetchTaskResultsCommandTest(TestCase):
|
||||||
aresult.state = "PENDING"
|
aresult.state = "PENDING"
|
||||||
aresult.ready.return_value = False
|
aresult.ready.return_value = False
|
||||||
|
|
||||||
Command().handle()
|
Command().handle(verbosity=0)
|
||||||
|
|
||||||
tr = TaskResult.objects.get(task_id=TEST_TASK_UUID)
|
tr = TaskResult.objects.get(task_id=TEST_TASK_UUID)
|
||||||
self.assertTrue(asyncresult.called_with(TEST_TASK_UUID))
|
self.assertTrue(asyncresult.called_with(TEST_TASK_UUID))
|
||||||
|
@ -55,7 +55,7 @@ class FetchTaskResultsCommandTest(TestCase):
|
||||||
aresult.ready.return_value = True
|
aresult.ready.return_value = True
|
||||||
aresult.get.return_value = TEST_TASK_RESULT
|
aresult.get.return_value = TEST_TASK_RESULT
|
||||||
|
|
||||||
Command().handle()
|
Command().handle(verbosity=0)
|
||||||
|
|
||||||
tr = TaskResult.objects.get(task_id=TEST_TASK_UUID)
|
tr = TaskResult.objects.get(task_id=TEST_TASK_UUID)
|
||||||
self.assertTrue(asyncresult.called_with(TEST_TASK_UUID))
|
self.assertTrue(asyncresult.called_with(TEST_TASK_UUID))
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<body>
|
<body>
|
||||||
<nav class="navbar navbar-expand-lg sticky-top navbar-dark bg-dark">
|
<nav class="navbar navbar-expand-lg sticky-top navbar-dark bg-dark">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a class="navbar-brand" href="{% url 'dashboard' %}" title="{% translate "Dashboard" %}">gnuviechadmin</a>
|
<a class="navbar-brand" href="{% url "customer_dashboard" %}" title="{% translate "Dashboard" %}">gnuviechadmin</a>
|
||||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent"
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent"
|
||||||
aria-controls="navbarContent" aria-expanded="false" aria-label="{% translate "Toggle navigation" %}">
|
aria-controls="navbarContent" aria-expanded="false" aria-label="{% translate "Toggle navigation" %}">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
{% user_display user as user_display %}
|
{% user_display user as user_display %}
|
||||||
{% url 'customer_dashboard' slug=user.username as profile_url %}
|
{% url "customer_dashboard" as profile_url %}
|
||||||
{% if user.is_impersonate %}
|
{% if user.is_impersonate %}
|
||||||
{% user_display user.impersonator as impersonator_display %}
|
{% user_display user.impersonator as impersonator_display %}
|
||||||
{% url 'impersonate-stop' as stop_impersonation_url %}
|
{% url 'impersonate-stop' as stop_impersonation_url %}
|
||||||
|
|
|
@ -94,7 +94,7 @@ class DatabaseUserManagerTest(TestCaseWithCeleryTasks):
|
||||||
self.assertEqual(dbu.name, "{user}db01".format(user=self.osuser.username))
|
self.assertEqual(dbu.name, "{user}db01".format(user=self.osuser.username))
|
||||||
self.assertEqual(dbu.osuser, self.osuser)
|
self.assertEqual(dbu.osuser, self.osuser)
|
||||||
self.assertEqual(dbu.db_type, DB_TYPES.mysql)
|
self.assertEqual(dbu.db_type, DB_TYPES.mysql)
|
||||||
taskres = TaskResult.objects.all()
|
taskres = TaskResult.objects.order_by("created").all()
|
||||||
self.assertEqual(len(taskres), 4)
|
self.assertEqual(len(taskres), 4)
|
||||||
self.assertEqual(taskres[0].creator, "handle_dbuser_created")
|
self.assertEqual(taskres[0].creator, "handle_dbuser_created")
|
||||||
self.assertEqual(taskres[0].notes, "mysql user creation")
|
self.assertEqual(taskres[0].notes, "mysql user creation")
|
||||||
|
@ -154,7 +154,7 @@ class DatabaseUserTest(TestCaseWithCeleryTasks):
|
||||||
dbid = db.id
|
dbid = db.id
|
||||||
self.dbu.delete()
|
self.dbu.delete()
|
||||||
self.assertFalse(UserDatabase.objects.filter(id=dbid).exists())
|
self.assertFalse(UserDatabase.objects.filter(id=dbid).exists())
|
||||||
taskres = TaskResult.objects.all()
|
taskres = TaskResult.objects.order_by("created").all()
|
||||||
self.assertEqual(len(taskres), 3)
|
self.assertEqual(len(taskres), 3)
|
||||||
self.assertEqual(taskres[0].creator, "handle_userdb_created")
|
self.assertEqual(taskres[0].creator, "handle_userdb_created")
|
||||||
self.assertEqual(taskres[0].notes, "pgsql database creation")
|
self.assertEqual(taskres[0].notes, "pgsql database creation")
|
||||||
|
@ -187,7 +187,7 @@ class UserDatabaseManagerTest(TestCaseWithCeleryTasks):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
db.db_user.name, "{user}db01".format(user=self.osuser.username)
|
db.db_user.name, "{user}db01".format(user=self.osuser.username)
|
||||||
)
|
)
|
||||||
taskres = TaskResult.objects.all()
|
taskres = TaskResult.objects.order_by("created").all()
|
||||||
self.assertEqual(len(taskres), 2)
|
self.assertEqual(len(taskres), 2)
|
||||||
self.assertEqual(taskres[0].creator, "handle_dbuser_created")
|
self.assertEqual(taskres[0].creator, "handle_dbuser_created")
|
||||||
self.assertEqual(taskres[0].notes, "mysql user creation")
|
self.assertEqual(taskres[0].notes, "mysql user creation")
|
||||||
|
@ -202,7 +202,7 @@ class UserDatabaseManagerTest(TestCaseWithCeleryTasks):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
db.db_user.name, "{user}db01".format(user=self.osuser.username)
|
db.db_user.name, "{user}db01".format(user=self.osuser.username)
|
||||||
)
|
)
|
||||||
taskres = TaskResult.objects.all()
|
taskres = TaskResult.objects.order_by("created").all()
|
||||||
self.assertEqual(len(taskres), 2)
|
self.assertEqual(len(taskres), 2)
|
||||||
self.assertEqual(taskres[0].creator, "handle_dbuser_created")
|
self.assertEqual(taskres[0].creator, "handle_dbuser_created")
|
||||||
self.assertEqual(taskres[0].notes, "pgsql user creation")
|
self.assertEqual(taskres[0].notes, "pgsql user creation")
|
||||||
|
@ -267,20 +267,20 @@ class UserDatabaseTest(TestCaseWithCeleryTasks):
|
||||||
|
|
||||||
def test___str__(self):
|
def test___str__(self):
|
||||||
customer = Customer.objects.create_user(username="testcustomer")
|
customer = Customer.objects.create_user(username="testcustomer")
|
||||||
osuser = User.objects.create_user(customer=customer)
|
os_user = User.objects.create_user(customer=customer)
|
||||||
db = UserDatabase.objects.create_userdatabase_with_user(DB_TYPES.pgsql, osuser)
|
db = UserDatabase.objects.create_userdatabase_with_user(DB_TYPES.pgsql, os_user)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
str(db),
|
str(db),
|
||||||
"{user}db01 ({dbuser})".format(user=osuser.username, dbuser=db.db_user),
|
"{user}db01 ({dbuser})".format(user=os_user.username, dbuser=db.db_user),
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_delete_mysql_db(self):
|
def test_delete_mysql_db(self):
|
||||||
customer = Customer.objects.create_user(username="testcustomer")
|
customer = Customer.objects.create_user(username="testcustomer")
|
||||||
osuser = User.objects.create_user(customer=customer)
|
os_user = User.objects.create_user(customer=customer)
|
||||||
TaskResult.objects.all().delete()
|
TaskResult.objects.all().delete()
|
||||||
db = UserDatabase.objects.create_userdatabase_with_user(DB_TYPES.mysql, osuser)
|
db = UserDatabase.objects.create_userdatabase_with_user(DB_TYPES.mysql, os_user)
|
||||||
db.delete()
|
db.delete()
|
||||||
taskres = TaskResult.objects.all()
|
task_result = TaskResult.objects.order_by("created").all()
|
||||||
self.assertEqual(len(taskres), 3)
|
self.assertEqual(len(task_result), 3)
|
||||||
self.assertEqual(taskres[2].creator, "handle_userdb_deleted")
|
self.assertEqual(task_result[2].creator, "handle_userdb_deleted")
|
||||||
self.assertEqual(taskres[2].notes, "mysql database deletion")
|
self.assertEqual(task_result[2].notes, "mysql database deletion")
|
||||||
|
|
Loading…
Reference in a new issue