|
@@ -0,0 +1,157 @@
|
|
|
|
+import json
|
|
|
|
+import requests
|
|
|
|
+import config
|
|
|
|
+import ast
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#Функция обращения к апи и получение токена
|
|
|
|
+def requestGetToken(url) -> str:
|
|
|
|
+ login = "11111111111"
|
|
|
|
+ password = "Sharix!"
|
|
|
|
+ #url = "https://user.sharix-app.org/auth/token/login/"
|
|
|
|
+ data = {
|
|
|
|
+ "password":password,
|
|
|
|
+ "phone_number":login
|
|
|
|
+ }
|
|
|
|
+ response = requests.post(url,json=data)
|
|
|
|
+ result = response.json()
|
|
|
|
+ return result['auth_token']
|
|
|
|
+#Функция обращения к апи и получение токена
|
|
|
|
+
|
|
|
|
+def msg_to_text(jsonstring):
|
|
|
|
+ jsonObj = json.loads(jsonstring)
|
|
|
|
+ u = jsonObj
|
|
|
|
+ return u
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def createUser(username, phone, password, url) -> str:
|
|
|
|
+ data = {
|
|
|
|
+ "username": username,
|
|
|
|
+ "phone_number": phone,
|
|
|
|
+ "password": password
|
|
|
|
+ }
|
|
|
|
+ response = requests.post(url, json=data)
|
|
|
|
+ result = response.json()
|
|
|
|
+ return result
|
|
|
|
+#Функция обращения к апи и получение списка пользователей
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def requestGetListUser(token):
|
|
|
|
+ headers = {'Authorization': f'Token {token}'}
|
|
|
|
+ url = 'http://testopen.sharix-app.org/api/v1/platform/sharix-users/'
|
|
|
|
+ response = requests.get(url, headers=headers)
|
|
|
|
+
|
|
|
|
+ return response
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class Ticket(object):
|
|
|
|
+ def __init__(self, id, name, group):
|
|
|
|
+ self.id = id
|
|
|
|
+ self.name = name
|
|
|
|
+ self.group = group
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def __str__(self):
|
|
|
|
+ return "{0}, {1}, {2},\n".format(self.id, self.name, self.group)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def requestGetList(auth_token, url):
|
|
|
|
+ headers = {'Authorization': f'Token {auth_token}'}
|
|
|
|
+ response = requests.get(url, headers=headers)
|
|
|
|
+ #response = requests.get(config.API_URL+"/dbsynce/api/orders/", headers=headers)
|
|
|
|
+ tickettext=response.json()
|
|
|
|
+ startlist = []
|
|
|
|
+
|
|
|
|
+ if not tickettext:
|
|
|
|
+ print("Empty array")
|
|
|
|
+ else:
|
|
|
|
+ for i in tickettext:
|
|
|
|
+ print (i, "PROCESSING")
|
|
|
|
+ try:
|
|
|
|
+ ticket = Ticket(**i)
|
|
|
|
+ print(i, "Ticket ", ticket)
|
|
|
|
+ startlist.append(ticket)
|
|
|
|
+ except Exception as ex:
|
|
|
|
+ print(ex)
|
|
|
|
+ print (startlist)
|
|
|
|
+ return startlist
|
|
|
|
+
|
|
|
|
+class Ticket_user(object):
|
|
|
|
+ def __init__(self, id, status, title, ticket_type, created_at, updated_at, due_date, priority, created_by, assigned_to):
|
|
|
|
+ self.id = id
|
|
|
|
+ self.status = status
|
|
|
|
+ self.title = title
|
|
|
|
+ self.ticket_type = ticket_type
|
|
|
|
+ self.created_at = created_at
|
|
|
|
+ self.updated_at = updated_at
|
|
|
|
+ self.due_date = due_date
|
|
|
|
+ self.priority = priority
|
|
|
|
+ self.created_by = created_by
|
|
|
|
+ self.assigned_to = assigned_to
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def __str__(self):
|
|
|
|
+ return "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}\n".format(
|
|
|
|
+ self.id, self.status, self.title, self.ticket_type, self.created_at,
|
|
|
|
+ self.updated_at, self.due_date, self.priority,
|
|
|
|
+ self.created_by, self.assigned_to
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+def requestGetTicket_user(auth_token, url):
|
|
|
|
+ headers = {'Authorization': f'Token {auth_token}'}
|
|
|
|
+ response = requests.get(url, headers=headers)
|
|
|
|
+
|
|
|
|
+ #response = requests.get(config.API_URL+"/dbsynce/api/orders/", headers=headers)
|
|
|
|
+ tickettext=response.json()
|
|
|
|
+ startlist = []
|
|
|
|
+ if not tickettext:
|
|
|
|
+ print("Empty array")
|
|
|
|
+ else:
|
|
|
|
+ for i in tickettext:
|
|
|
|
+ try:
|
|
|
|
+ ticket = Ticket_user(**i)
|
|
|
|
+ startlist.append(ticket)
|
|
|
|
+ except Exception as ex:
|
|
|
|
+ print(ex)
|
|
|
|
+ print (startlist)
|
|
|
|
+ return startlist
|
|
|
|
+
|
|
|
|
+def requestPatchTicketUser(token,url, data):
|
|
|
|
+ headers = {'Authorization': f'Token {token}'}
|
|
|
|
+ response = requests.patch(url, json=data, headers=headers)
|
|
|
|
+ return response
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def change_groups(auth_token, url,group):
|
|
|
|
+ headers = {
|
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
|
+ 'Authorization': f'Token {auth_token}'
|
|
|
|
+ }
|
|
|
|
+ response = requests.get(url, headers=headers)
|
|
|
|
+ user_data = response.json()
|
|
|
|
+ current_groups = user_data.get('groups', [])
|
|
|
|
+ updated_groups = list(set([group]+current_groups))
|
|
|
|
+ data = {'groups': updated_groups}
|
|
|
|
+ print(data)
|
|
|
|
+ response = requests.put(url, json=data, headers=headers)
|
|
|
|
+ print(url)
|
|
|
|
+ print(user_data)
|
|
|
|
+ return response
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def change_status_company(auth_token, url,id_metaservice):
|
|
|
|
+ headers = {
|
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
|
+ 'Authorization': f'Token {auth_token}'
|
|
|
|
+ }
|
|
|
|
+ response = requests.get(url, headers=headers)
|
|
|
|
+ user_data = response.json()
|
|
|
|
+ print(user_data)
|
|
|
|
+ current_metaservice = user_data.get('id_metaservice', [])
|
|
|
|
+ repsonse = requests.put(config.API_URL+f"dbsynce/api/company/{id_metaservice}", json=data, headers=headers)
|
|
|
|
+ return response
|