Ejemplo n.º 1
0
def submit(
    session: Session,
    industry: str,
    keywords: List[str],
    *,
    separator: str = "|",
    send_as_data: bool = True,
    send_as_files: bool = False,
) -> Response:
    error = f"Can send data only as data or as files"
    assert (send_as_data
            and not send_as_files) or (send_as_files
                                       and not send_as_data), error
    headers = {"Referer": URL}
    data = {
        "input-autocomplete": f"{separator}".join(keywords),
        "expertise_products_services": f"{separator}".join(keywords),
    }
    url = urljoin(URL, industry + "/")
    if send_as_data and not send_as_files:
        return make_request(Method.POST,
                            url,
                            session=session,
                            headers=headers,
                            data=data)
    elif send_as_files and not send_as_data:
        return make_request(Method.POST,
                            url,
                            session=session,
                            headers=headers,
                            files=data)
Ejemplo n.º 2
0
def go_to(session: Session,
          *,
          term: str = None,
          page: int = None,
          sectors: list = None) -> Response:
    """Go to "FAS Find a Supplier" page.

    :param term: (optional) search term
    :param page: (optional) number of search result page
    :param sectors: (optional) a list of Industry sector filters
    """
    params = {}
    if term is not None:
        # remove words which make FAS return hundreds of result pages
        term = term.replace("LTD", "").replace("LIMITED", "")
        params.update({"q": term})
    if page is not None:
        params.update({"page": page})
    if sectors is not None:
        params.update({"sectors": sectors})
    headers = {"Referer": URLs.PROFILE_BUSINESS_PROFILE.absolute}
    return make_request(Method.GET,
                        URL,
                        session=session,
                        params=params,
                        headers=headers,
                        trim=False)
Ejemplo n.º 3
0
def submit(actor: Actor, company: Company) -> Response:
    session = actor.session

    if (
        "address" in company.companies_house_details
        and "postal_code" in company.companies_house_details["address"]
    ):
        postcode = company.companies_house_details["address"]["postal_code"]
        address = postcode_search(actor, postcode)["value"]
    else:
        postcode = random.choice(POSTCODES)
        address = postcode_search(actor, postcode)["value"]

    headers = {"Referer": URL}
    files = {
        "csrfmiddlewaretoken": actor.csrfmiddlewaretoken,
        "non_companies_house_enrolment_view-current_step": "address-search",
        "address-search-company_type": BUSINESS_CATEGORY[company.business_type],
        "address-search-company_name": company.title,
        "address-search-postal_code": postcode,
        "address-search-address": address.replace(",", "\n"),
        "address-search-sectors": random.choice(SECTORS),
        "address-search-website": "https://dit.automated.tests",
    }

    return make_request(
        Method.POST,
        URL,
        session=session,
        headers=headers,
        files=files,
        no_filename_in_multipart_form_data=True,
    )
Ejemplo n.º 4
0
def go_to(session: Session) -> Response:
    url = f"{URL}?next={URLs.DOMESTIC_LANDING_UK.absolute}"
    headers = {
        "referer":
        f"{URLs.SSO_LOGIN.absolute}?next={URLs.DOMESTIC_LANDING_UK.absolute}"
    }
    return make_request(Method.GET, url, session=session, headers=headers)
Ejemplo n.º 5
0
def submit(
    actor: Actor,
    action: str,
    *,
    password: str = None,
    password_again: str = None,
    referer: str = None,
) -> Response:
    session = actor.session
    url = urljoin(URLs.SSO_LANDING.absolute, action)
    profile_about = URLs.PROFILE_ABOUT.absolute

    data = {
        "action": "change password",
        "csrfmiddlewaretoken": actor.csrfmiddlewaretoken,
        "password1": password or actor.password,
        "password2": password_again or password or actor.password,
    }
    # Referer is the same as the final URL from the previous request
    query = f"?next={referer or profile_about}"
    referer = urljoin(url, query)
    headers = {"Referer": referer}

    response = make_request(Method.POST,
                            url,
                            session=session,
                            data=data,
                            headers=headers)

    return response
Ejemplo n.º 6
0
def go_to(session: Session) -> Response:
    """Go to "Edit Company's Online Profiles" page.

    This requires:
     * Supplier to be logged in
    """
    headers = {"Referer": URLs.PROFILE_BUSINESS_PROFILE.absolute}
    return make_request(Method.GET, URL, session=session, headers=headers)
Ejemplo n.º 7
0
def go_to(session: Session, *, next: str = None, referer: str = None) -> Response:
    referer = referer or URLs.FAB_LANDING.absolute
    if next:
        url = urljoin(URL, f"?next={next}")
    else:
        url = URL
    headers = {"Referer": referer}
    return make_request(Method.GET, url, session=session, headers=headers)
Ejemplo n.º 8
0
def submit(session: Session, summary: str, description: str) -> Response:
    headers = {"Referer": URL}
    data = {"summary": summary, "description": description}
    return make_request(Method.POST,
                        URL,
                        session=session,
                        headers=headers,
                        data=data)
Ejemplo n.º 9
0
def submit(session: Session, industry: str) -> Response:
    headers = {"Referer": URL}
    data = {"choice": industry}
    return make_request(Method.POST,
                        URL,
                        session=session,
                        headers=headers,
                        data=data)
Ejemplo n.º 10
0
def postcode_search(actor: Actor, postcode: str) -> dict:
    session = actor.session
    headers = {"Accept": "application/json"}
    url = URLs.PROFILE_API_POSTCODE_SEARCH.absolute_template.format(postcode=postcode)
    response = make_request(Method.GET, url, session=session, headers=headers)
    error = f"Expected 200 OK but got {response.status_code} from {response.url}"
    assert response.status_code == 200, error
    logging.debug(f"Found addresses for postcode: '{postcode}': {response.json()}")
    return random.choice(response.json())
Ejemplo n.º 11
0
def go_to(session: Session, *, next_param: str = None) -> Response:
    fab_landing = URLs.FAB_LANDING.absolute
    params = {"next": next_param or fab_landing}
    headers = {"Referer": URLs.PROFILE_BUSINESS_PROFILE.absolute}
    return make_request(Method.GET,
                        URL,
                        session=session,
                        params=params,
                        headers=headers)
Ejemplo n.º 12
0
def submit(session: Session, token: str, case_study: CaseStudy) -> Response:
    """Submit the form with basic case study data."""
    data = prepare_form_data(token, case_study)
    headers = {"Referer": URL}
    response = make_request(
        Method.POST, URL, session=session, headers=headers, data=data
    )
    logging.debug("Supplier successfully submitted basic case study data: %s", data)
    return response
Ejemplo n.º 13
0
def submit(actor: Actor) -> Response:
    session = actor.session
    data = {}
    return make_request(
        Method.POST,
        URL,
        session=session,
        files=data,
        no_filename_in_multipart_form_data=True,
    )
Ejemplo n.º 14
0
def go_to(session: Session, *, set_next_page: bool = True) -> Response:
    fab_landing = URLs.FAB_LANDING.absolute
    params = {"next": fab_landing}
    headers = {"Referer": fab_landing}
    if not set_next_page:
        params = None
    return make_request(Method.GET,
                        URL,
                        session=session,
                        params=params,
                        headers=headers)
def submit(session: Session, *, unpublish: bool = False) -> Response:
    """Submit the form with verification code."""
    headers = {"Referer": URL}
    data = {"is_published_find_a_supplier": "on"} if not unpublish else {}
    return make_request(
        Method.POST,
        URL,
        session=session,
        headers=headers,
        files=data,
        no_filename_in_multipart_form_data=True,
    )
Ejemplo n.º 16
0
def submit(
    session: Session, token: str, verification_code: str, *, referer: str = None
) -> Response:
    """Submit the form with verification code."""
    if referer is None:
        referer = URLs.PROFILE_BUSINESS_PROFILE.absolute
    headers = {"Referer": referer}
    data = {
        "csrfmiddlewaretoken": token,
        "company_address_verification_view-current_step": "address",
        "address-code": verification_code,
    }
    return make_request(Method.POST, URL, session=session, headers=headers, data=data)
def submit(actor: Actor) -> Response:
    """Verify your identity with a physical letter."""
    headers = {"Referer": URL}
    data = {
        "csrfmiddlewaretoken": actor.csrfmiddlewaretoken,
        "send_verification_letter_view-current_step": "address",
        "address-postal_full_name": actor.alias,
        "address-address_confirmed": "on",
    }
    response = make_request(
        Method.POST, URL, session=actor.session, headers=headers, data=data
    )
    return response
Ejemplo n.º 18
0
def logout(session: Session,
           token: str,
           *,
           next_param: str = None) -> Response:
    fab_landing = URLs.FAB_LANDING.absolute
    data = {"csrfmiddlewaretoken": token, "next": next_param or fab_landing}
    query = f"?next={fab_landing}"
    headers = {"Referer": urljoin(URL, query)}
    return make_request(Method.POST,
                        URL,
                        session=session,
                        headers=headers,
                        data=data)
Ejemplo n.º 19
0
def go_to(session: Session, *, case_number: int = None) -> Response:
    """Go to "Add Case Study" basic - page.

    This requires:
     * Supplier to be logged in
    """
    if case_number:
        url = EDIT_URL.format(case_number=case_number)
    else:
        url = URL
    headers = {"Referer": URLs.PROFILE_BUSINESS_PROFILE.absolute}
    response = make_request(Method.GET, url, session=session, headers=headers)
    logging.debug("Supplier is on the Add Case Study - Basic page")
    return response
def submit(actor: Actor) -> Response:
    session = actor.session
    headers = {"Referer": URL}
    data = {
        "csrfmiddlewaretoken": actor.csrfmiddlewaretoken,
        "non_companies_house_enrolment_view-current_step": "user-account",
        "user-account-email": actor.email,
        "user-account-password": actor.password,
        "user-account-password_confirmed": actor.password,
        "user-account-terms_agreed": "on",
        "user-account-remote_password_error": None,
        "g-recaptcha-response": "test mode",
    }

    return make_request(Method.POST, URL, session=session, headers=headers, data=data)
Ejemplo n.º 21
0
def submit(actor: Actor, business_type: BusinessType) -> Response:
    session = actor.session
    headers = {"Referer": URLs.PROFILE_ENROL_SELECT_BUSINESS_TYPE.absolute}
    data = {
        "csrfmiddlewaretoken": actor.csrfmiddlewaretoken,
        "choice": BUSINESS_TYPES[business_type],
    }

    return make_request(
        Method.POST,
        URL,
        session=session,
        headers=headers,
        files=data,
        no_filename_in_multipart_form_data=True,
    )
Ejemplo n.º 22
0
def upload(session: Session, file_path: str) -> Response:
    headers = {"Referer": URLs.PROFILE_UPLOAD_LOGO.absolute}
    data = {"company_profile_logo_edit_view-current_step": "logo"}
    with open(file_path, "rb") as f:
        picture = f.read()
    mime = mimetypes.MimeTypes().guess_type(file_path)[0]
    files = {"logo": (os.path.basename(file_path), picture, mime)}
    response = make_request(
        Method.POST,
        URL,
        session=session,
        headers=headers,
        data=data,
        files=files,
        trim=True,
    )
    return response
def confirm(session: Session, csrf_middleware_token: str,
            link: str) -> Response:
    # in order to be redirected to the correct URL we have `unquote`
    # the form_action_value
    start = link.index("=") + 1
    invite_key = link[start:]
    headers = {"Referer": link}
    data = {
        "csrfmiddlewaretoken": csrf_middleware_token,
        "invite_key": invite_key
    }

    return make_request(Method.POST,
                        link,
                        session=session,
                        headers=headers,
                        data=data)
Ejemplo n.º 24
0
def confirm(actor: Actor, form_action_value: str) -> Response:
    """Confirm the email address provided by the Supplier.

    :param form_action_value: form action from SSO Confirm your email page
    """
    session = actor.session
    # in order to be redirected to the correct URL we have `unquote`
    # the form_action_value
    url = urljoin(URLs.SSO_LANDING.absolute, unquote(form_action_value))
    headers = {"Referer": url}
    data = {"csrfmiddlewaretoken": actor.csrfmiddlewaretoken}

    return make_request(Method.POST,
                        url,
                        session=session,
                        headers=headers,
                        data=data)
def submit(actor: Actor):
    session = actor.session
    headers = {"Referer": URL}
    data = {
        "non_companies_house_enrolment_view-current_step": "personal-details",
        "csrfmiddlewaretoken": actor.csrfmiddlewaretoken,
        "personal-details-given_name": "AUTOMATED",
        "personal-details-family_name": "TESTS",
        "personal-details-job_title": "AUTOMATED TESTS",
        "personal-details-phone_number:": "0987654321",
        "personal-details-confirmed_is_company_representative": "on",
    }

    return make_request(Method.POST,
                        URL,
                        session=session,
                        headers=headers,
                        data=data)
def submit(actor: Actor, company: Company) -> Response:
    session = actor.session
    headers = {"Referer": URL}
    data = {
        "csrfmiddlewaretoken": actor.csrfmiddlewaretoken,
        "companies_house_enrolment_view-current_step": "company-search",
        "company-search-company_name": company.title,
        "company-search-company_number": company.number,
    }

    return make_request(
        Method.POST,
        URL,
        session=session,
        headers=headers,
        files=data,
        no_filename_in_multipart_form_data=True,
    )
Ejemplo n.º 27
0
def submit(actor: Actor) -> Response:
    session = actor.session
    assert actor.email_confirmation_code
    headers = {"Referer": URL}
    data = {
        "csrfmiddlewaretoken": actor.csrfmiddlewaretoken,
        "non_companies_house_enrolment_view-current_step": "verification",
        "verification-code": actor.email_confirmation_code,
    }

    return make_request(
        Method.POST,
        URL,
        session=session,
        headers=headers,
        files=data,
        no_filename_in_multipart_form_data=True,
    )
Ejemplo n.º 28
0
def submit(session: Session, message: Message or Feedback, company_number: str):
    full_url = URL.format(company_number=company_number)
    headers = {"Referer": URL.format(company_number=company_number)}
    data = {
        "body": message.body,
        "company_name": message.company_name,
        "country": message.country,
        "email_address": message.email_address,
        "family_name": message.family_name,
        "given_name": message.given_name,
        "g-recaptcha-response": message.g_recaptcha_response,
        "sector": message.sector,
        "subject": message.subject,
        "terms": message.terms,
    }
    return make_request(
        Method.POST, full_url, session=session, headers=headers, data=data
    )
Ejemplo n.º 29
0
def submit(actor: Actor, company: Company) -> Response:
    session = actor.session
    headers = {"Referer": URL}
    data = {
        "csrfmiddlewaretoken": actor.csrfmiddlewaretoken,
        "companies_house_enrolment_view-current_step": "business-details",
        "business-details-company_name": company.title,
        "business-details-sectors": company.sector or random.choice(SECTORS),
        "business-details-website": company.website,
    }

    return make_request(
        Method.POST,
        URL,
        session=session,
        headers=headers,
        files=data,
        no_filename_in_multipart_form_data=True,
    )
Ejemplo n.º 30
0
def submit(actor: Actor):
    session = actor.session
    headers = {"Referer": URL}
    data = {
        "csrfmiddlewaretoken": actor.csrfmiddlewaretoken,
        "individual_user_enrolment_view-current_step": "personal-details",
        "personal-details-given_name": actor.alias,
        "personal-details-family_name": "AUTOMATED TESTS",
        "personal-details-job_title": "DIT AUTOMATED TESTS",
        "personal-details-phone_number": "0987654321",
        "personal-details-terms_agreed": "on",
    }

    return make_request(
        Method.POST,
        URL,
        session=session,
        headers=headers,
        files=data,
        no_filename_in_multipart_form_data=True,
    )