Beispiel #1
0
class ProxyBuilder(Builder):
    target = Proxy

    to = UrlBuilder
    wait = lambda: one_of(None, an_integer(1, 1000))
    inject_headers = lambda: one_of(None, {a_string(): a_string()})
    mode = lambda: one_of(*Proxy.Mode)
Beispiel #2
0
class HttpResponseBuilder(Builder):
    target = HttpResponse

    body = a_string
    status_code = lambda: one_of(*[s.value for s in http.HTTPStatus])
    headers = lambda: one_of(None, {a_string(): a_string()})
    mode = lambda: one_of(*Response.Mode)
Beispiel #3
0
class ResponseBuilder(Builder):
    target = Response

    wait = lambda: one_of(an_integer(1, 500), None)
    repeat = lambda: one_of(an_integer(2, 50), None)
    copy = lambda: one_of(None, CopyBuilder().build())
    decorate = lambda: one_of(None, a_string())
    lookup = lambda: one_of(None, LookupBuilder().build())
    shell_transform = lambda: one_of(None, a_string())
    http_response = HttpResponseBuilder
Beispiel #4
0
class HttpRequestBuilder(Builder):
    target = HttpRequest

    method = lambda: one_of(*Predicate.Method).name
    path = lambda: UrlBuilder().build().path
    query = lambda: {a_string(): a_string(), a_string(): a_string()}
    headers = lambda: {a_string(): a_string(), a_string(): a_string()}
    body = lambda: one_of(None, a_string())
Beispiel #5
0
class ImposterBuilder(Builder):
    target = Imposter

    stubs = lambda: [StubBuilder().build(), StubBuilder().build()]
    port = lambda: one_of(None, an_integer(1, 5000))
    protocol = one_of(*Imposter.Protocol)
    name = lambda: one_of(None, a_string())
    default_response = lambda: one_of(None, HttpResponseBuilder().build())
    record_requests = a_boolean
    mutual_auth = a_boolean
    key = lambda: one_of(None, a_string())
    cert = lambda: one_of(None, a_string())
Beispiel #6
0
class ResponseBuilder(Builder):
    target = Response

    body = a_string
    status_code = lambda: one_of(*[s.value for s in http.HTTPStatus])
    wait = lambda: one_of(an_integer(1, 500), None)
    repeat = lambda: one_of(an_integer(2, 50), None)
    headers = lambda: one_of(None, {a_string(): a_string()})
    mode = lambda: one_of(*Response.Mode)
    copy = lambda: one_of(None, CopyBuilder().build())
    decorate = lambda: one_of(None, a_string())
    lookup = lambda: one_of(None, LookupBuilder().build())
    shell_transform = lambda: one_of(None, a_string())
Beispiel #7
0
class ImposterBuilder(Builder):
    target = Imposter

    stubs = lambda: [StubBuilder().build(), StubBuilder().build()]
    port = lambda: one_of(None, an_integer(1, 5000))
    protocol = one_of(*Imposter.Protocol)
    name = lambda: one_of(None, a_string())
    record_requests = a_boolean
Beispiel #8
0
class PredicateBuilder(Builder):
    target = Predicate

    path = lambda: one_of(None, a_string())
    method = lambda: one_of(*Predicate.Method)
    query = lambda: one_of(None, {a_string(): a_string()})
    body = lambda: one_of(None, a_string())
    headers = lambda: one_of(None, {a_string(): a_string()})
    xpath = lambda: one_of(None, a_string())
    operator = lambda: one_of(*list(Predicate.Operator))
    case_sensitive = a_boolean
Beispiel #9
0
def test_email(mock_server):
    # Given
    imposter = smtp_imposter()

    # TODO - make brunns-builders more realistic, so we don't have to do this here.'
    to_email = email.utils.formataddr(
        ((" ".join(a_string() for _ in range(randint(1, 3)))), (EmailBuilder().build()))
    )
    from_email = ", ".join(
        email.utils.formataddr(
            ((" ".join(a_string() for _ in range(randint(1, 3)))), EmailBuilder().build())
        )
        for _ in range(randint(1, 5))
    )
    body_text = a_string()
    message = (
        EmailMessageBuilder()
        .with_to_email(to_email)
        .with_from_email(from_email)
        .with_body_text(body_text)
        .build()
        .as_string()
    )

    with mock_server(imposter) as s:
        logger.debug("server: %s", s)

        # When
        server = smtplib.SMTP()
        server.connect(host=imposter.host, port=imposter.port)
        try:
            server.sendmail(to_email, [from_email], message)
        finally:
            server.quit()

        # Then
        assert_that(imposter, email_sent(body_text=body_text))
Beispiel #10
0
class UrlBuilder(Builder):
    target = furl

    scheme = lambda: one_of("http", "https", "tcp", None)
    username = a_string
    password = a_string
    host = DomainBuilder
    port = lambda: an_integer(1, 65535)
    path = lambda: [a_string(), a_string()]
    query = lambda: {a_string(): a_string(), a_string(): a_string()}
    fragment = a_string
Beispiel #11
0
def test_email(mock_server):
    # Given
    imposter = smtp_imposter()

    from_email = EmailAddressBuilder().build()
    to_email = EmailAddressBuilder().build()
    body_text = a_string()

    message = (EmailMessageBuilder().with_to(to_email).and_from(
        from_email).and_body_text(body_text).build().as_string())

    with mock_server(imposter) as s:
        logger.debug("server: %s", s)

        # When
        server = smtplib.SMTP()
        server.connect(host=imposter.host, port=imposter.port)
        try:
            server.sendmail(to_email, [from_email], message)
        finally:
            server.quit()

        # Then
        assert_that(imposter, email_sent(body_text=body_text))
Beispiel #12
0
class InjectionResponseBuilder(Builder):
    target = InjectionResponse
    inject = a_string()
Beispiel #13
0
class InjectionPredicateBuilder(Builder):
    target = InjectionPredicate
    inject = a_string()
Beispiel #14
0
class ResponseBuilder(Builder):
    target = Response

    body = a_string
    status_code = lambda: one_of(
        200,
        201,
        202,
        203,
        204,
        205,
        206,
        207,
        208,
        226,
        300,
        301,
        302,
        303,
        304,
        305,
        307,
        308,
        400,
        401,
        402,
        403,
        404,
        405,
        406,
        407,
        408,
        409,
        410,
        411,
        412,
        413,
        414,
        415,
        416,
        417,
        418,
        421,
        422,
        423,
        424,
        426,
        428,
        429,
        431,
        444,
        451,
        499,
        500,
        501,
        502,
        503,
        504,
        505,
        506,
        507,
        508,
        510,
        511,
        599,
    )
    wait = lambda: one_of(an_integer(1, 500), None)
    repeat = lambda: one_of(an_integer(2, 50), None)
    headers = lambda: one_of(None, {a_string(): a_string()})
    mode = lambda: one_of(*Response.Mode)
    copy = lambda: one_of(None, CopyBuilder().build())
    decorate = lambda: one_of(None, a_string())
    lookup = lambda: one_of(None, LookupBuilder().build())
    shell_transform = lambda: one_of(None, a_string())
Beispiel #15
0
class DomainBuilder(Builder):
    subdomain = lambda: a_string(characters=string.ascii_lowercase)
    tld = lambda: one_of("com", "net", "dev", "co.uk", "gov.uk", "ng")

    def build(self):
        return "{0}.{1}".format(self.subdomain, self.tld)
Beispiel #16
0
class MimeEmailAddressBuilder(Builder):
    target = MimeEmailAddress

    address = EmailAddressBuilder
    name = lambda: " ".join(a_string() for _ in range(an_integer(1, 3)))
Beispiel #17
0
class PathBuilder(Builder):
    target = Path
    args = lambda: [a_string(), a_string()]