Exemplo n.º 1
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
Exemplo n.º 2
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())
Exemplo n.º 3
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)
Exemplo n.º 4
0
class KeyBuilder(Builder):
    target = Key

    from_ = a_string
    using = lambda: one_of(UsingRegexBuilder().build(),
                           UsingXpathBuilder().build(),
                           UsingJsonpathBuilder().build())
    index = lambda: an_integer(1, 50)
Exemplo n.º 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())
    record_requests = a_boolean
Exemplo n.º 6
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
Exemplo n.º 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())
    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())
Exemplo n.º 8
0
class EmailMessageBuilder(Builder):
    to_ = [MimeEmailAddressBuilder().build() for _ in range(an_integer(1, 3))]
    cc_ = [MimeEmailAddressBuilder().build() for _ in range(an_integer(1, 3))]
    bcc_ = [MimeEmailAddressBuilder().build() for _ in range(an_integer(1, 3))]
    from_ = MimeEmailAddressBuilder
    subject = a_string
    body_text = a_string

    @method
    def with_to(self, *args):
        if args and isinstance(args[0], str):
            return self.with_to_(
                [MimeEmailAddress(args[0], nth(args, 1, None))])
        else:
            return self.with_to_(
                [MimeEmailAddress(t[0], nth(t, 1, None)) for t in args])

    @method
    def and_to(self, *args):
        return self.with_to(*args)

    @method
    def plus_to(self, address: str, name: Optional[str] = None):
        self.to_ += [MimeEmailAddress(address, name)]
        return self

    @method
    def with_cc(self, *args):
        if args and isinstance(args[0], str):
            return self.with_cc_(
                [MimeEmailAddress(args[0], nth(args, 1, None))])
        else:
            return self.with_cc_(
                [MimeEmailAddress(t[0], nth(t, 1, None)) for t in args])

    @method
    def and_cc(self, *args):
        return self.with_cc(*args)

    @method
    def plus_cc(self, address: str, name: Optional[str] = None):
        self.cc_ += [MimeEmailAddress(address, name)]
        return self

    @method
    def with_bcc(self, *args):
        if args and isinstance(args[0], str):
            return self.with_bcc_(
                [MimeEmailAddress(args[0], nth(args, 1, None))])
        else:
            return self.with_bcc_(
                [MimeEmailAddress(t[0], nth(t, 1, None)) for t in args])

    @method
    def and_bcc(self, *args):
        return self.with_bcc(*args)

    @method
    def plus_bcc(self, address: str, name: Optional[str] = None):
        self.bcc_ += [MimeEmailAddress(address, name)]
        return self

    @method
    def with_from(self, address: str, name: Optional[str] = None):
        return self.with_from_(MimeEmailAddress(name, address))

    @method
    def and_from(self, address: str, name: Optional[str] = None):
        return self.with_from(name, address)

    def build(self):
        message = MIMEText(self.body_text)
        message["To"] = ", ".join(
            email.utils.formataddr((r.name, r.address)) for r in self.to_)
        message["CC"] = ", ".join(
            email.utils.formataddr((r.name, r.address)) for r in self.cc_)
        message["BCC"] = ", ".join(
            email.utils.formataddr((r.name, r.address)) for r in self.bcc_)
        message["From"] = email.utils.formataddr(
            (self.from_.name, self.from_.address))
        message["Subject"] = self.subject
        return message
Exemplo n.º 9
0
class MimeEmailAddressBuilder(Builder):
    target = MimeEmailAddress

    address = EmailAddressBuilder
    name = lambda: " ".join(a_string() for _ in range(an_integer(1, 3)))
Exemplo n.º 10
0
class DateBuilder(Builder):
    target = datetime.date
    year = lambda: an_integer(1, 9999)
    month = lambda: an_integer(1, 12)
    day = lambda: an_integer(1, 28)
Exemplo n.º 11
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())