<jupyter_start><jupyter_text>authenticate> Handles authentication for the client<jupyter_code># export
import requests

from yx_motor.api import API


class Authenticate:
    "Class for handling authenticate API actions"

    def __init__(self, api: API):
        self.api = api
        self.base_endpoint = "authenticate/"

    def authenticate(self, login_email: str, login_pwd: str) -> requests.Response:
        payload = {"email": login_email, "password": <PASSWORD>}
        response = self.api.post(url=self.base_endpoint, json=payload)
        if response.status_code == 200:
            self.api.jar.update(response.cookies)
            self.api.is_authenticated = True
        return response

    def logout(self):
        logout_endpoint = f"{self.base_endpoint}logout"
        response = self.api.post(url=logout_endpoint)
        if response.status_code == 204:
            self.api.jar.update(response.cookies)
            self.api.is_authenticated = False
        return response
#hide

#Unit test code for get_vfs_inputs
from unittest.mock import Mock

from nbdev.showdoc import *
show_doc(Authenticate.authenticate)<jupyter_output><empty_output><jupyter_text>authenticate receives a login_email and login_pwd from client and attempts to authenticate against the AAH Server.It automatically tests if the response is successful, and updates the cookie jar with the auth token for downstream use.<jupyter_code>#hide
api = Mock()
api.post = Mock()
api.post.return_value = Mock()
api.post().status_code = 200
authenticate = Authenticate(api)
response = authenticate.authenticate('<EMAIL>', '<PASSWORD>_password')
response.status_code
#hide
assert(response.status_code == 200)
from nbdev.showdoc import *
show_doc(Authenticate.logout)<jupyter_output><empty_output><jupyter_text>logout will end the current session and confirm that a logout was completed successfully. This will render any existing cookies invalid, and also clear out the cookie jar.<jupyter_code>#hide
api = Mock()
api.post = Mock()
api.post.return_value = Mock()
api.post().status_code = 204
#hide
authenticate = Authenticate(api)
authenticate.authenticate(
    login_email='login_email', login_pwd='<PASSWORD>'
)
response = authenticate.logout()
response.status_code
#hide
assert(response.status_code == 204)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09529969814575248, 'fraction_numerical': 0.007761966364812419, 'mean_word_length': 4.55023923444976, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '382215', 'license': 'Apache-2.0', 'n_tokens_mistral': 735, 'n_tokens_neox': 692, 'n_words': 182, 'path': '04_authenticate.ipynb', 'repo_name': 'Jesse-Clarkayx/yx_motor', 'size': '2326'}