Home > front end >  Why Python login interface automation pass to attend belt ()
Why Python login interface automation pass to attend belt ()

Time:09-16

Code is as follows, the meeting after running parameter error, and the data transfer is not found by print according to imagine himself a dictionary in the form of a show,
Actual: data1 {' user_name ': (' 12345678'), 'password' : (' 123456 ')}
Expectation: data1 {' user_name: 12345678 'and' password ', 123456 '}
Why tell a great god, genuflect is begged, how to correct the

# - * - coding: utf-8 - *
The import requests
The import unittest
The import json

Class Denglu (unittest. TestCase) : # define a class, class capitalize the first letter of oh

Def setUp (self) : # initialization
The self. The base_url='https://'
Print (" start ")

Def login (self, username, PSW) :
"' two parameters: the account: username, password: PSW '"'

Url="https://test-api.XXXXX.cn/api/v1/login/password" # request url
The content-type headers={" ", "application/Json"}
Data={
https://bbs.csdn.net/topics/"User_name" : the username,
"Password" : the PSW,
}
Print (data)
R=requests. Post (url=url, headers=headers, json=data)
Result1=r.s tatus_code
Result2=r.t ext
Print (" information ", result2)
# return r.j son ()
Return result1


Def test_get_success (self) :

The username='12345678',
PSW='123456',
Data1={
"User_name" : the username,
"Password" : the PSW,
}
Print (" data1 ", data1)
Result=self. Login (username, PSW)
# result=self. Login (" 12345678 ", "123456")
Print (result)
Self. AssertEqual (result, 200)
# print (result [' message '])


If __name__=="__main__" :
Unittest. The main ()




  • Related