init: profile
This commit is contained in:
		@ -1,6 +1,7 @@
 | 
				
			|||||||
import requests
 | 
					import requests
 | 
				
			||||||
from requests import Response, Request, Session
 | 
					from requests import Response, Request, Session
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import Profile
 | 
				
			||||||
import Accounts
 | 
					import Accounts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import urls
 | 
					import urls
 | 
				
			||||||
@ -11,6 +12,7 @@ class Client:
 | 
				
			|||||||
        self.token: str = None
 | 
					        self.token: str = None
 | 
				
			||||||
        self.session: Session = Session()
 | 
					        self.session: Session = Session()
 | 
				
			||||||
        self.accounts: Account = Accounts.Account(self)
 | 
					        self.accounts: Account = Accounts.Account(self)
 | 
				
			||||||
 | 
					        self.profile = Profile.Profile
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def is_authentificate(self):
 | 
					    def is_authentificate(self):
 | 
				
			||||||
        return (not self.token is None)
 | 
					        return (not self.token is None)
 | 
				
			||||||
@ -28,3 +30,9 @@ class Client:
 | 
				
			|||||||
        response: Response = self.session.post(url, data = data, headers = dict(Referer=url))
 | 
					        response: Response = self.session.post(url, data = data, headers = dict(Referer=url))
 | 
				
			||||||
        self.token = response.cookies.get('csrftoken')
 | 
					        self.token = response.cookies.get('csrftoken')
 | 
				
			||||||
        return response
 | 
					        return response
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    def _get(self, uri: str):
 | 
				
			||||||
 | 
					        url: str = self.url + uri
 | 
				
			||||||
 | 
					        response: Response = self.session.get(url)
 | 
				
			||||||
 | 
					        self.token = response.cookies.get('csrftoken')
 | 
				
			||||||
 | 
					        return response
 | 
				
			||||||
							
								
								
									
										14
									
								
								src/Profile.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/Profile.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					import urls
 | 
				
			||||||
 | 
					import Client
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from requests import Response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Profile:
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    def __init__(self, client, user_id: int):
 | 
				
			||||||
 | 
					        response: Response = client._get(urls.profiles_page + str(user_id))
 | 
				
			||||||
 | 
					        if (response.content == b'Profile Not Found'):
 | 
				
			||||||
 | 
					            return None
 | 
				
			||||||
 | 
					        content: dict = eval(response.content)
 | 
				
			||||||
 | 
					        self.username = content['username']
 | 
				
			||||||
 | 
					        self.password = content['password']
 | 
				
			||||||
@ -35,6 +35,9 @@ def test_accounts_delete(client):
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    print()
 | 
					    print()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def test_profile_get(client):
 | 
				
			||||||
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def tests():
 | 
					def tests():
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    username = uuid4()
 | 
					    username = uuid4()
 | 
				
			||||||
@ -47,5 +50,7 @@ def tests():
 | 
				
			|||||||
    test_accounts_login(client, username, password)
 | 
					    test_accounts_login(client, username, password)
 | 
				
			||||||
    test_accounts_delete(client)
 | 
					    test_accounts_delete(client)
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    test_profile_get(client)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
    tests()
 | 
					    tests()
 | 
				
			||||||
@ -1,4 +1,9 @@
 | 
				
			|||||||
accounts: str = "api/accounts/"
 | 
					api: str = "api/"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					accounts: str = api + "accounts/"
 | 
				
			||||||
accounts_login: str = accounts + "login"
 | 
					accounts_login: str = accounts + "login"
 | 
				
			||||||
accounts_delete: str = accounts + "delete"
 | 
					accounts_delete: str = accounts + "delete"
 | 
				
			||||||
accounts_register: str = accounts + "register"
 | 
					accounts_register: str = accounts + "register"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					profiles: str = "profiles"
 | 
				
			||||||
 | 
					profiles_page: str = profiles
 | 
				
			||||||
		Reference in New Issue
	
	Block a user