Merge branch 'feature/tests/make_eng' into 'develop'
#70 | Test make engineer from work and control pages See merge request 2020-2021/online/s101/group-02/access_controller!68
This commit is contained in:
commit
881b6ffd55
@ -14,7 +14,6 @@ Including another URLconf
|
|||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth import views
|
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
|
|
||||||
from main.views import main_page, profile_page, CustomRegistrationView, CustomLoginView, registration_error
|
from main.views import main_page, profile_page, CustomRegistrationView, CustomLoginView, registration_error
|
||||||
|
85
fixtures/test_make_engineer.json
Normal file
85
fixtures/test_make_engineer.json
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"model": "auth.user",
|
||||||
|
"pk": 1,
|
||||||
|
"fields": {
|
||||||
|
"password": "pbkdf2_sha256$216000$gHBBCr1jBELf$ZkEDW3IEd8Wij7u8vkv+0Eze32CS01bcaYWhcD9OIC4=",
|
||||||
|
"last_login": null,
|
||||||
|
"is_superuser": true,
|
||||||
|
"username": "admin@gmail.com",
|
||||||
|
"first_name": "",
|
||||||
|
"last_name": "",
|
||||||
|
"email": "admin@gmail.com",
|
||||||
|
"is_staff": true,
|
||||||
|
"is_active": true,
|
||||||
|
"date_joined": "2021-03-10T16:38:56.303Z",
|
||||||
|
"groups": [],
|
||||||
|
"user_permissions": [33]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "main.userprofile",
|
||||||
|
"pk": 1,
|
||||||
|
"fields": {
|
||||||
|
"name": "ZendeskAdmin",
|
||||||
|
"user": 1,
|
||||||
|
"role": "admin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "auth.user",
|
||||||
|
"pk": 2,
|
||||||
|
"fields": {
|
||||||
|
"password": "pbkdf2_sha256$216000$5qLJgrm2Quq9$KDBNNymVZXkUx0HKBPFst2m83kLe0egPBnkW7KnkORU=",
|
||||||
|
"last_login": null,
|
||||||
|
"is_superuser": false,
|
||||||
|
"username": "123@test.ru",
|
||||||
|
"first_name": "",
|
||||||
|
"last_name": "",
|
||||||
|
"email": "123@test.ru",
|
||||||
|
"is_staff": false,
|
||||||
|
"is_active": true,
|
||||||
|
"date_joined": "2021-03-10T16:38:56.303Z",
|
||||||
|
"groups": [],
|
||||||
|
"user_permissions": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "main.userprofile",
|
||||||
|
"pk": 2,
|
||||||
|
"fields": {
|
||||||
|
"name": "UserForAccessTest",
|
||||||
|
"user": 2,
|
||||||
|
"role": "agent",
|
||||||
|
"custom_role_id": "360005209000"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "auth.user",
|
||||||
|
"pk": 3,
|
||||||
|
"fields": {
|
||||||
|
"password": "pbkdf2_sha256$216000$5qLJgrm2Quq9$KDBNNymVZXkUx0HKBPFst2m83kLe0egPBnkW7KnkORU=",
|
||||||
|
"last_login": null,
|
||||||
|
"is_superuser": false,
|
||||||
|
"username": "customer@example.com",
|
||||||
|
"first_name": "",
|
||||||
|
"last_name": "",
|
||||||
|
"email": "customer@example.com",
|
||||||
|
"is_staff": false,
|
||||||
|
"is_active": true,
|
||||||
|
"date_joined": "2021-04-15T16:38:56.303Z",
|
||||||
|
"groups": [],
|
||||||
|
"user_permissions": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model": "main.userprofile",
|
||||||
|
"pk": 3,
|
||||||
|
"fields": {
|
||||||
|
"name": "UserForAccessTest",
|
||||||
|
"user": 3,
|
||||||
|
"role": "agent",
|
||||||
|
"custom_role_id": "360005209000"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
@ -31,7 +31,7 @@ def update_role(user_profile: UserProfile, role: int, who_changes: User) -> None
|
|||||||
user_profile.custom_role_id = role
|
user_profile.custom_role_id = role
|
||||||
user_profile.save()
|
user_profile.save()
|
||||||
log(user_profile, who_changes.userprofile)
|
log(user_profile, who_changes.userprofile)
|
||||||
zendesk.admin.users.update(user)
|
zendesk.update_user(user)
|
||||||
|
|
||||||
|
|
||||||
def make_engineer(user_profile: UserProfile, who_changes: User) -> None:
|
def make_engineer(user_profile: UserProfile, who_changes: User) -> None:
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
|
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
||||||
|
|
||||||
<script src="{% static 'modules/notifications/dist/notifications.js' %}"></script>
|
|
||||||
<script src="{% static 'main/js/control.js'%}" type="text/babel"></script>
|
<script src="{% static 'main/js/control.js'%}" type="text/babel"></script>
|
||||||
<script src="{% static 'main/js/notifications.js' %}"></script>
|
<script src="{% static 'main/js/notifications.js' %}"></script> {# Для #}
|
||||||
|
<script src="{% static 'modules/notifications/dist/notifications.js' %}"></script> {# Уведомлений #}
|
||||||
{% endblock%}
|
{% endblock%}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container-md">
|
<div class="container-md">
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
from unittest.mock import patch
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
from django.test import TestCase, Client
|
from django.test import TestCase, Client
|
||||||
from django.urls import reverse
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
|
|
||||||
import access_controller.settings as sets
|
import access_controller.settings as sets
|
||||||
@ -81,3 +82,69 @@ class RegistrationTestCase(TestCase):
|
|||||||
user = User.objects.get(email=self.zendesk_admin_email)
|
user = User.objects.get(email=self.zendesk_admin_email)
|
||||||
self.assertEqual(user.userprofile.role, 'admin')
|
self.assertEqual(user.userprofile.role, 'admin')
|
||||||
self.assertTrue(user.has_perm('main.has_control_access'))
|
self.assertTrue(user.has_perm('main.has_control_access'))
|
||||||
|
|
||||||
|
|
||||||
|
class MakeEngineerTestCase(TestCase):
|
||||||
|
fixtures = ['fixtures/test_make_engineer.json']
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.light_agent = '123@test.ru'
|
||||||
|
self.admin = 'admin@gmail.com'
|
||||||
|
self.engineer = 'customer@example.com'
|
||||||
|
self.client = Client()
|
||||||
|
self.client.force_login(User.objects.get(email=self.light_agent))
|
||||||
|
self.admin_client = Client()
|
||||||
|
self.admin_client.force_login(User.objects.get(email=self.admin))
|
||||||
|
|
||||||
|
@patch('main.extra_func.zenpy')
|
||||||
|
def test_redirect(self, ZenpyMock):
|
||||||
|
user = User.objects.get(email=self.light_agent)
|
||||||
|
resp = self.client.post(reverse_lazy('work_become_engineer'))
|
||||||
|
self.assertRedirects(resp, reverse('work', args=[user.id]))
|
||||||
|
self.assertEqual(resp.status_code, 302)
|
||||||
|
|
||||||
|
@patch('main.extra_func.zenpy')
|
||||||
|
def test_light_agent_make_engineer(self, ZenpyMock):
|
||||||
|
self.client.post(reverse_lazy('work_become_engineer'))
|
||||||
|
self.assertEqual(ZenpyMock.update_user.call_args[0][0].custom_role_id, sets.ZENDESK_ROLES['engineer'])
|
||||||
|
|
||||||
|
@patch('main.extra_func.zenpy')
|
||||||
|
def test_admin_make_engineer(self, ZenpyMock):
|
||||||
|
self.admin_client.post(reverse_lazy('work_become_engineer'))
|
||||||
|
self.assertEqual(ZenpyMock.update_user.call_args[0][0].custom_role_id, sets.ZENDESK_ROLES['engineer'])
|
||||||
|
|
||||||
|
@patch('main.extra_func.zenpy')
|
||||||
|
def test_engineer_make_engineer(self, ZenpyMock):
|
||||||
|
client = Client()
|
||||||
|
client.force_login(User.objects.get(email=self.engineer))
|
||||||
|
client.post(reverse_lazy('work_become_engineer'))
|
||||||
|
self.assertEqual(ZenpyMock.update_user.call_args[0][0].custom_role_id, sets.ZENDESK_ROLES['engineer'])
|
||||||
|
|
||||||
|
@patch('main.extra_func.zenpy')
|
||||||
|
def test_control_page_make_one(self, ZenpyMock):
|
||||||
|
self.admin_client.post(
|
||||||
|
reverse_lazy('control'),
|
||||||
|
data={'users': [User.objects.get(email=self.light_agent).userprofile.id], 'engineer': 'engineer'}
|
||||||
|
)
|
||||||
|
call_list = ZenpyMock.update_user.call_args_list
|
||||||
|
mock_object = call_list[0][0][0]
|
||||||
|
self.assertEqual(len(call_list), 1)
|
||||||
|
self.assertEqual(mock_object.custom_role_id, sets.ZENDESK_ROLES['engineer'])
|
||||||
|
|
||||||
|
@patch('main.extra_func.zenpy')
|
||||||
|
def test_control_page_make_many(self, ZenpyMock):
|
||||||
|
self.admin_client.post(
|
||||||
|
reverse_lazy('control'),
|
||||||
|
data={
|
||||||
|
'users': [
|
||||||
|
User.objects.get(email=self.light_agent).userprofile.id,
|
||||||
|
User.objects.get(email=self.engineer).userprofile.id,
|
||||||
|
],
|
||||||
|
'engineer': 'engineer'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
call_list = ZenpyMock.update_user.call_args_list
|
||||||
|
mock_objects = list(call_list)
|
||||||
|
self.assertEqual(len(call_list), 2)
|
||||||
|
for obj in mock_objects:
|
||||||
|
self.assertEqual(obj[0][0].custom_role_id, sets.ZENDESK_ROLES['engineer'])
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from typing import Optional, Dict
|
from typing import Optional, Dict
|
||||||
|
|
||||||
from zenpy import Zenpy
|
from zenpy import Zenpy
|
||||||
from zenpy.lib.api_objects import User as ZenpyUser, Group as ZenpyGroup
|
from zenpy.lib.api_objects import User as ZenpyUser, Group as ZenpyGroup
|
||||||
from zenpy.lib.exception import APIException
|
from zenpy.lib.exception import APIException
|
||||||
@ -22,6 +21,14 @@ class ZendeskAdmin:
|
|||||||
self.buffer_group_id: int = self.get_group(ZENDESK_GROUPS['buffer']).id
|
self.buffer_group_id: int = self.get_group(ZENDESK_GROUPS['buffer']).id
|
||||||
self.solved_tickets_user_id: int = self.get_user(SOLVED_TICKETS_EMAIL).id
|
self.solved_tickets_user_id: int = self.get_user(SOLVED_TICKETS_EMAIL).id
|
||||||
|
|
||||||
|
def update_user(self, user: ZenpyUser) -> bool:
|
||||||
|
"""
|
||||||
|
Функция сохраняет изменение пользователя в Zendesk.
|
||||||
|
|
||||||
|
:param user: Пользователь с изменёнными данными
|
||||||
|
"""
|
||||||
|
self.admin.users.update(user)
|
||||||
|
|
||||||
def check_user(self, email: str) -> bool:
|
def check_user(self, email: str) -> bool:
|
||||||
"""
|
"""
|
||||||
Функция осуществляет проверку существования пользователя в Zendesk по email.
|
Функция осуществляет проверку существования пользователя в Zendesk по email.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user