Exemplo n.º 1
0
def update_acl_rule(role, scope_type, scope_value):
    """
    Метод обновляет правило в календаре

    Args:
        role (str): тип роли
        scope_type (str): тип пользователя
        scope_value (str): email к кому применияется правило
    Return:
        expected_model(ACLModel): модель правила
    """
    json_update = create_json_role(role, scope_type, scope_value)
    log_info("Create model from json (expected model)")
    expected_model = ACLModel()
    expected_model.init_acl_from_json(json_data=json_update)

    actual_response = AclApi().update(json_data=json_update, rule_id="user:{scope_value}".
                                      format(scope_value=scope_value))
    actual_status_code = HttpLib.get_response_status_code(actual_response)
    actual_json = HttpLib.get_response_json(actual_response)
    log_pretty_json(actual_json, "This is response json from server")
    assert (actual_status_code == status_code_200), \
        "Updating ACL rule Failed. The response status code not equal 200, current status code: {actual_code}". \
        format(actual_code=actual_status_code)
    return expected_model
Exemplo n.º 2
0
def insert_acl_rule(role, scope_type, scope_value):
    """
    Метод создает правило в календаре

    template
        Create Acl role  |  ${role}  |  ${scope_value}  |  ${scope_type}

    Args:
        role (str): тип роли
        scope_value (str): email к кому применить правило
        scope_type (str): тип пользователя
    Return:
        expected_model(ACLModel): модель правила
    """
    json_insert = create_json_role(role, scope_type, scope_value)
    log_info("Create model from json (expected model)")
    expected_model = ACLModel()
    expected_model.init_acl_from_json(json_data=json_insert)
    actual_response = AclApi().insert(json_insert)
    actual_status_code = HttpLib.get_response_status_code(actual_response)
    actual_json = HttpLib.get_response_json(actual_response)
    log_pretty_json(actual_json, "This is response json from server")
    assert (actual_status_code == status_code_200),\
        "Insert ACL rule Failed. The response status code not equal 200, current status code: {actual_code}".\
        format(actual_code=actual_status_code)
    return expected_model
Exemplo n.º 3
0
def untrash_thread(user_id, thread_id):
    """
    Args:
         user_id (str): user id
         thread_id (str): thread id
    """
    response = ThreadsApi().untrash_thread(user_id, thread_id)
    response_code = HttpLib.get_response_status_code(response)
    response_json = HttpLib.get_response_json(response)
    log_info("Move thread with id {thread_id} from trash".format(
        thread_id=thread_id))
    log_pretty_json(response_json, "This is json response")
    assert response_code == status_code_200, "Error while moving thread with {id} from trash".format(
        id=thread_id)
Exemplo n.º 4
0
    def modify_messages(self,
                        user_id,
                        message_id,
                        add_labels_list=None,
                        remove_label_list=None):
        """
        Modifies the labels on the specified message
        Args:
            user_id (str): The user's email address
            message_id(str): Message id
            add_labels_list(lust): List of added labels
            remove_label_list(list): List of remove labels
        Returns:
            response (requests.Response)
            model_array (массив MessageModel)
        """
        if remove_label_list is None:
            remove_label_list = []

        if add_labels_list is None:
            add_labels_list = []

        request_body = {
            "addLabelIds": add_labels_list,
            "removeLabelIds": remove_label_list
        }

        api = HttpLib(
            url="{host}/{api}/{user_id}/messages/{message_id}/modify".format(
                host=self.host,
                api=self.api,
                user_id=user_id,
                message_id=message_id),
            json=request_body)

        log_info("Modify messages URL: {url}, request: {json}".format(
            url=api.url, json=api.json))
        api.auth_to_google(client=client, scope=scope_mail)
        api.send_post()
        log_pretty_json(api.response.text, "Modify messages response")
        model = MessageModel().get_basic_message_from_json(
            api.get_response_json(api.response))

        return api.response, model
 def get_pop(self, user_id="me", oauth_client=client):
     """
     Send get request to Users.settings: getPop
     :param user_id: user email address for request
     :param oauth_client: client that should be authorized with oauth 2.0
     :return: response and status code
     """
     url = "{host}/{api}/{service}".format(
         host=self.host,
         api=self.api,
         service=url_getPop.format(userId=user_id))
     log_info("Get pop url is: {url}".format(url=url))
     http = HttpLib(url)
     http.auth_to_google(client=oauth_client, scope=scope_gmail_setting)
     http.send_get()
     log_pretty_json(http.get_response_json(http.response),
                     "Get pop response")
     return http.get_response_json(
         http.response), http.get_response_status_code(http.response)
Exemplo n.º 6
0
 def forwarding_list(self, user_id="me", client_id=client):
     """
     Build forwarding list request
     :param user_id: user email
     :param client_id: auth client
     :return: response, ForwardingModel object
     """
     forwarding = []
     url = "{host}/{api}/{user_id}/settings/forwardingAddresses".format(host=self.host,
                                                                        api=self.api,
                                                                        user_id=user_id)
     log_info(url)
     http = HttpLib(url=url)
     http.auth_to_google(client=client_id, scope=scope_settings_forwarding)
     http.send_get()
     log_pretty_json(http.response.text, "Forwarding list response")
     forwarding_items = get_value_from_json(http.get_response_json(http.response), 'forwardingAddresses')
     for item in forwarding_items:
         forwarding.append(ForwardingModel().create_model_from_json(item))
     return http.response, forwarding
Exemplo n.º 7
0
def list_acl_rule():
    """
    Метод возвращает лист массив моделей календаря

    template
        List Acl Rule
    Return:
        actual_model(ACLModel): массив моделей правил
    """
    log_info("Get acl rules models array")
    actual_response, actual_model = AclApi().list()
    log_info("Assert status code")
    actual_status_code = actual_response.status_code
    actual_json = HttpLib.get_response_json(actual_response)
    log_pretty_json(actual_json, "This is response json from server")
    assert (actual_status_code == status_code_200), \
        "Getting ACL rules list failed. The response status code not equal 200, current status code: {actual_code}". \
        format(actual_code=actual_status_code)

    return actual_model
Exemplo n.º 8
0
def get_send_as_list(user_id):
    """
    Modify the specified send-as alias
    Args:
        user_id (str): user id
    Returns:
        model (SendAsModel): the list of models are getting from the server
    """
    response, model = SettingsSendAsApi().get_send_as_list(user_id=user_id)
    response_code = HttpLib.get_response_status_code(response)
    response_json = HttpLib.get_response_json(response)
    log_info(
        "Get send-as alias for user_id = {user}. Response model = {model}".
        format(user=user_id, model=model))
    log_pretty_json(
        response_json, "This is response json: {response_json}".format(
            response_json=response_json))
    assert response_code == status_code_200, \
        "Get send-as alias error: status code = {actual}, expected status code = {expected}". \
        format(actual=response_code, expected=status_code_200)
    return model
Exemplo n.º 9
0
def get_acl_rule(scope_value):
    """
       Метод получает правило в календаре по id правила

       template
           get_acl_rule_response_model   ${scope_value}

       Args:
           scope_value (str): email к кому применияется правило
       Return:
           actual_model(ACLModel): модель правила
    """

    actual_response, actual_model = AclApi().get("user:{scope_value}".format(scope_value=scope_value))
    actual_status_code = HttpLib.get_response_status_code(actual_response)
    actual_json = HttpLib.get_response_json(actual_response)
    log_pretty_json(actual_json, "This is response json from server")
    assert (actual_status_code == status_code_200),\
        "Get ACL rule Failed. The response status code not equal 200, current status code: {actual_code}".\
        format(actual_code=actual_status_code)
    return actual_model
 def update_imap(self, imap_model, user_id="me", oauth_client=client):
     """
     Send put request to Users.settings: getVacation
     :param imap_model: Imap Model object
     :param user_id: user email address for request
     :param oauth_client: client that should be authorized with oauth 2.0
     :return: response and status code
     """
     url = "{host}/{api}/{service}".format(
         host=self.host,
         api=self.api,
         service=url_getImap.format(userId=user_id))
     log_info("Update imap url is: {url}".format(url=url))
     body = imap_model.create_json_from_model()
     http = HttpLib(url, json=body)
     http.auth_to_google(client=oauth_client, scope=scope_gmail_setting)
     http.send_put()
     log_pretty_json(http.get_response_json(http.response),
                     "Update imap response")
     return http.get_response_json(
         http.response), http.get_response_status_code(http.response)
Exemplo n.º 11
0
def get_profile(user_id):
    """
    Args:
        user_id (str): user id
    Returns:
        model (UsersModel): the model is getting from the server
    """
    response, model = UserApi().get_profile(user_id)
    response_code = HttpLib.get_response_status_code(response)
    response_json = HttpLib.get_response_json(response)
    log_info(
        "Get profile for user_id = {user}. Response model = {model}".format(
            user=user_id, model=model))
    log_pretty_json(
        response_json, "This is response json: {response_json}".format(
            response_json=response_json))
    assert response_code == status_code_200, \
        "Get profile error: status code = {actual}, expected status code = {expected}". \
        format(actual=response_code,
               expected=status_code_200)
    return model
Exemplo n.º 12
0
def get_history_list(user_id, start_history_id):
    """
    Get history list
    Args:
            user_id (str): user id
            start_history_id (str): specified startHistoryId for request
    Returns:
            model (HistoryModel): the model is getting from the server
    """
    response, model = HistoryApi().get_history_list(
        user_id=user_id, start_history_id=start_history_id)
    response_code = HttpLib.get_response_status_code(response)
    response_json = HttpLib.get_response_json(response)
    log_info("Get history list for  = {user}. Response model = {model}".format(
        user=user_id, model=model))
    log_pretty_json(
        response_json, "This is response json: {response_json}".format(
            response_json=response_json))
    assert response_code == status_code_200, \
        "Get history list error: status code = {actual}, expected status code = {expected}". \
        format(actual=response_code, expected=status_code_200)
    return response_json, model
Exemplo n.º 13
0
 def get_history_list(self, user_id, start_history_id):
     """
     Gets the history list
     Args:
          user_id (str): user id
          start_history_id (str): specified startHistoryId for request
     Returns:
          response (requests.Response)
          model (HistoryModel): the model is getting from the server
     """
     url = "{host}/{api}/{user_id}/history".format(host=self.host,
                                                   api=self.api,
                                                   user_id=user_id)
     params = {'startHistoryId': start_history_id}
     api = HttpLib(url=url, header=self.header, params=params)
     api.auth_to_google(client=client, scope=scope_mail)
     api.send_get()
     response = api.response
     log_pretty_json(api.get_response_json(response),
                     "This is response json from server")
     model = HistoryModel().get_history_model_from_json(
         api.get_response_json(response))
     log_info(model)
     return response, model