1- from config .constants import *
2- import requests
31import json
4- from dotenv import load_dotenv
52import os
63
4+ import requests
5+ from dotenv import load_dotenv
6+
7+ from config .constants import URL
8+
9+
710class BasePage :
811 def __init__ (self , page = None ):
912 self .page = page
@@ -19,7 +22,7 @@ def validate_response_status(self, question_api=""):
1922 load_dotenv () # Ensure environment variables are loaded
2023 # URL of the API endpoint
2124 url = f"{ URL } /conversation"
22-
25+
2326 # Prepare headers
2427 headers = {
2528 "Content-Type" : "application/json" ,
@@ -34,61 +37,66 @@ def validate_response_status(self, question_api=""):
3437 "id" : "cb9e6c49-0e8c-5f3e-4928-57e55e26896f" ,
3538 "role" : "user" ,
3639 "content" : question_api , # Use the passed question
37- "date" : "2024-12-18T07:49:23.413Z"
40+ "date" : "2024-12-18T07:49:23.413Z" ,
3841 }
39- ]
42+ ],
4043 }
41-
42-
43- # Make the POST request
44- response = self .page .request .post (url , headers = headers ,data = json .dumps (payload ), timeout = 120000 )
45- assert response .status == 200 , "response code is " + str (response .status )+ " " + str (response .json ())
46-
47-
48-
44+
45+ # Make the POST request
46+ response = self .page .request .post (
47+ url , headers = headers , data = json .dumps (payload ), timeout = 120000
48+ )
49+ assert response .status == 200 , (
50+ "response code is " + str (response .status ) + " " + str (response .json ())
51+ )
52+
4953 def validate_draft_response_status (self , section_title , topic_text ):
5054 load_dotenv () # Ensure environment variables are loaded
51-
52- client_id = os .getenv (' client_id' )
53- client_secret = os .getenv (' client_secret' )
54- tenant_id = os .getenv (' tenant_id' )
55+
56+ client_id = os .getenv (" client_id" )
57+ client_secret = os .getenv (" client_secret" )
58+ tenant_id = os .getenv (" tenant_id" )
5559 token_url = f"https://login.microsoft.com/{ tenant_id } /oauth2/v2.0/token"
5660
5761 # URL for generating draft section
5862 url = f"{ URL } /draft_document/generate_section"
5963
6064 # Prepare data for token request
6165 data = {
62- ' grant_type' : ' client_credentials' ,
63- ' client_id' : client_id ,
64- ' client_secret' : client_secret ,
65- ' scope' : f' api://{ client_id } /.default'
66+ " grant_type" : " client_credentials" ,
67+ " client_id" : client_id ,
68+ " client_secret" : client_secret ,
69+ " scope" : f" api://{ client_id } /.default" ,
6670 }
6771
6872 try :
6973 # Request the token
7074 response = requests .post (token_url , data = data )
71-
75+
7276 if response .status_code == 200 :
7377 token_info = response .json ()
74- access_token = token_info [' access_token' ]
78+ access_token = token_info [" access_token" ]
7579 headers = {
76- ' Authorization' : f' Bearer { access_token } ' ,
77- "Content-Type" : "application/json"
80+ " Authorization" : f" Bearer { access_token } " ,
81+ "Content-Type" : "application/json" ,
7882 }
7983 payload = {
8084 "grantTopic" : topic_text ,
8185 "sectionContext" : "" ,
82- "sectionTitle" : section_title
86+ "sectionTitle" : section_title ,
8387 }
8488
8589 # Make the POST request for draft section generation
8690 response = requests .post (url , headers = headers , data = json .dumps (payload ))
8791
8892 # Check if the response status is not 200
8993 if response .status_code != 200 :
90- print (f"Error: { response .status_code } , Response Text: { response .text } " )
91- raise Exception (f"Request failed with status code { response .status_code } " )
94+ print (
95+ f"Error: { response .status_code } , Response Text: { response .text } "
96+ )
97+ raise Exception (
98+ f"Request failed with status code { response .status_code } "
99+ )
92100
93101 # Attempt to parse the response as JSON
94102 response_data = response .json ()
0 commit comments