#NEWLINE# def test_login( self ) : #NEWLINE# #INDENT# name = 'Josephine de Beauharnais' #NEWLINE# payload = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'email' : 'josephine@debeauharnais.fr' , #NEWLINE# 'password' : 'blackforest' , #NEWLINE# 'provider' : 'basic' , #NEWLINE# 'text' : 'Test login' , #NEWLINE# #UNINDENT# } #NEWLINE# response = self . app . post ( '/auth/signup' , data = json . dumps ( payload ) , headers = { #NEWLINE# #INDENT# 'Content-type' : 'application/json' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( data . status_code , 403 ) #NEWLINE# payload = { #NEWLINE# #INDENT# 'customer' : 'Bonaparte Industries' , #NEWLINE# 'match' : 'debeauharnais.fr' , #NEWLINE# #UNINDENT# } #NEWLINE# response = self . app . post ( '/customer' , data = json . dumps ( payload ) , headers = self . headers ) #NEWLINE# self . assertEqual ( response . status_code , 201 ) #NEWLINE# payload = { #NEWLINE# #INDENT# 'email' : 'josephine@debeauharnais.fr' , #NEWLINE# 'password' : 'blackforest' , #NEWLINE# #UNINDENT# } #NEWLINE# response = self . app . post ( '/auth/login' , data = json . dumps ( payload ) , headers = { #NEWLINE# #INDENT# 'Content-type' : 'application/json' , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( response . status_code , 200 ) #NEWLINE# data = json . loads ( response . data . decode ( 'utf-8' ) ) #NEWLINE# self . assertIn ( 'token' , data ) #NEWLINE# token = data [ 'token' ] #NEWLINE# headers = { #NEWLINE# #INDENT# 'Authorization' : ( 'Bearer ' + token ) , #NEWLINE# 'Content-type' : 'application/json' , #NEWLINE# #UNINDENT# } #NEWLINE# payload = { #NEWLINE# #INDENT# 'user' : 'customer-demo-key' , #NEWLINE# 'type' : 'read-only' , #NEWLINE# #UNINDENT# } #NEWLINE# response = self . app . post ( '/key' , data = json . dumps ( payload ) , headers = headers ) #NEWLINE# self . assertEqual ( response . status_code , 201 ) #NEWLINE# data = json . loads ( response . data . decode ( 'utf-8' ) ) #NEWLINE# self . assertIsNotNone ( data [ 'key' ] , 'Failed to create read-only key' ) #NEWLINE# customer_api_key = data [ 'key' ] #NEWLINE# response = self . app . get ( '/alerts' , headers = { #NEWLINE# #INDENT# 'Authorization' : ( 'Key ' + customer_api_key ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( response . status_code , 200 ) #NEWLINE# data = json . loads ( response . data . decode ( 'utf-8' ) ) #NEWLINE# self . assertIn ( 'total' , data ) #NEWLINE# response = self . app . delete ( ( '/key/' + customer_api_key ) , headers = { #NEWLINE# #INDENT# 'Authorization' : ( 'Key ' + customer_api_key ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertEqual ( response . status_code , 403 ) #NEWLINE# response = self . app . delete ( ( '/key/' + customer_api_key ) , headers = self . headers ) #NEWLINE# self . assertEqual ( response . status_code , 200 ) #NEWLINE# response = self . app . get ( '/users' , headers = self . headers ) #NEWLINE# self . assertEqual ( response . status_code , 200 ) #NEWLINE# data = json . loads ( response . data . decode ( 'utf-8' ) ) #NEWLINE# self . assertIn ( name , [ u [ 'name' ] for u in data [ 'users' ] ] ) #NEWLINE# user_id = [ u [ 'id' ] for u in data [ 'users' ] if ( u [ 'name' ] == name ) ] [ 0 ] #NEWLINE# response = self . app . delete ( ( '/user/' + user_id ) , headers = self . headers ) #NEWLINE# self . assertEqual ( response . status_code , 200 ) #NEWLINE# response = self . app . delete ( ( '/customer/' + 'Bonaparte Industries' ) , headers = self . headers ) #NEWLINE# self . assertEqual ( response . status_code , 200 )