示例#1
0
 def testDoesNotMatchIfTheWrongExceptionTypeIsRaised(self):
     self.assert_does_not_match('Wrong exception', raises(IOError),
                                calling(raise_exception))
     expected_message = "AssertionError('(){}',) of type <%s> was raised instead" % \
                        ("class 'AssertionError'" if six.PY3 else "type 'exceptions.AssertionError'")
     self.assert_mismatch_description(expected_message, raises(TypeError),
                                      calling(raise_exception))
示例#2
0
 def testDoesNotMatchIfTheWrongExceptionTypeIsRaisedPy37(self):
     self.assert_does_not_match("Wrong exception", raises(IOError),
                                calling(raise_exception))
     expected_message = (
         "AssertionError('(){}') of type <class 'AssertionError'> was raised instead"
     )
     self.assert_mismatch_description(expected_message, raises(TypeError),
                                      calling(raise_exception))
示例#3
0
    def testMatchesRegularExpressionToStringifiedException(self):
        self.assert_matches('Regex',
                            raises(AssertionError, "(3, 1, 4)"),
                            calling(raise_exception).with_args(3,1,4))

        self.assert_matches('Regex',
                            raises(AssertionError, "([\d, ]+)"),
                            calling(raise_exception).with_args(3,1,4))
示例#4
0
def test_minimal_cors():
    srv = cloudant.get_server(auth=(USER, USER))
    origin = "http://baz.com"
    db_path = "/" + SHARED_DB
    allowed_methods = "POST"
    with srv.user_context(USER, USER, owner=OWNER):
        assert_that(
            calling(srv.res.options).with_args(""),
            raises(HTTPError)
        )
        db_options_resp = srv.res.options("", headers={
            "Origin": origin,
            "Access-Control-Request-Method": "POST"
        })
        assert_that(
            db_options_resp,
            has_header("Access-Control-Allow-Origin", val=origin)
        )
        assert_that(
            db_options_resp,
            has_header("Access-Control-Allow-Methods", val=allowed_methods)
        )
        assert_that(
            db_options_resp,
            is_not(has_header("Access-Control-Allow-Credentials"))
        )
        assert_that(
            srv.res.get("", headers={"Origin": origin}),
            has_header("Access-Control-Allow-Origin", val=origin)
        )
        assert_that(
            calling(srv.res.get).with_args("/_all_dbs",
                headers={"Origin": origin}),
            raises(HTTPError)
        )
        db_get_resp = srv.res.get(db_path, headers={"Origin": origin})
        assert_that(
            db_get_resp,
            has_header("Access-Control-Allow-Origin", val=origin)
        )
        assert_that(
            db_get_resp,
            is_not(has_header("Access-Control-Allow-Credentials"))
        )
        assert_that(
            db_get_resp,
            has_header("Access-Control-Expose-Headers", val=EXPECTED_HEADERS)
        )
        assert_that(
            srv.res.post(db_path, headers={"Origin":origin}, data="{}").json(),
            has_key("ok")
        )
        # NOTE: This request would not work from the browser, as it's not
        # included in the allowed methods
        assert_that(
            srv.res.get(db_path+"/_all_docs", headers={"Origin":origin}).json(),
            has_key("rows")
        )
示例#5
0
def test_cors():
    srv = cloudant.get_server(auth=(USER, USER))
    origin = "http://example.com"
    db_path = "/" + SHARED_DB
    allowed_methods = "CONNECT, COPY, DELETE, GET, HEAD, OPTIONS, POST, PUT, TRACE"
    with srv.user_context(USER, USER, owner=OWNER):
        assert_that(
            calling(srv.res.options).with_args(""),
            raises(HTTPError)
        )
        db_options_resp = srv.res.options("", headers={
            "Origin": origin,
            "Access-Control-Request-Method": "GET"
        })
        assert_that(
            db_options_resp,
            has_header("Access-Control-Allow-Origin", val=origin)
        )
        assert_that(
            db_options_resp,
            has_header("Access-Control-Allow-Methods", val=allowed_methods)
        )
        assert_that(
            db_options_resp,
            has_header("Access-Control-Allow-Credentials", val="true")
        )
        assert_that(
            srv.res.get("", headers={"Origin": origin}),
            has_header("Access-Control-Allow-Origin", val=origin)
        )
        assert_that(
            calling(srv.res.get).with_args("/_all_dbs",
                headers={"Origin": origin}),
            raises(HTTPError)
        )
        db_get_resp = srv.res.get(db_path, headers={"Origin": origin})
        assert_that(
            db_get_resp,
            has_header("Access-Control-Allow-Origin", val=origin)
        )
        assert_that(
            db_get_resp,
            has_header("Access-Control-Allow-Credentials", val="true")
        )
        assert_that(
            db_get_resp,
            has_header("Access-Control-Expose-Headers", val=EXPECTED_HEADERS)
        )
        assert_that(
            srv.res.post(db_path, headers={"Origin":origin}, data="{}").json(),
            has_key("ok")
        )
        assert_that(
            srv.res.get(db_path+"/_all_docs", headers={"Origin":origin}).json(),
            has_key("rows")
        )
示例#6
0
    def testMatchesRegularExpressionToStringifiedException(self):
        self.assert_matches(
            "Regex",
            raises(AssertionError, "(3, 1, 4)"),
            calling(raise_exception).with_args(3, 1, 4),
        )

        self.assert_matches(
            "Regex",
            raises(AssertionError, "([\d, ]+)"),
            calling(raise_exception).with_args(3, 1, 4),
        )
示例#7
0
def test_no_cors():
    srv = cloudant.get_server(auth=(USER, USER))
    origin = "http://random-no-cors-domain.com"
    db_path = "/" + SHARED_DB
    with srv.user_context(USER, USER, owner=OWNER):
        assert_that(
            calling(srv.res.options).with_args(""),
            raises(HTTPError)
        )
        assert_that(
            calling(srv.res.options).with_args("", headers={"Origin": origin}),
            raises(HTTPError)
        )
        assert_that(
            srv.res.get("", headers={"Origin": origin}),
            is_not(has_header("Access-Control-Allow-Origin"))
        )
        assert_that(
            calling(srv.res.get).with_args("/_all_dbs",
                headers={"Origin": origin}),
            raises(HTTPError)
        )
        db_get_resp = srv.res.get(db_path, headers={"Origin": origin})
        assert_that(
            db_get_resp,
            is_not(has_header("Access-Control-Allow-Origin"))
        )
        assert_that(
            db_get_resp,
            is_not(has_header("Access-Control-Allow-Credentials"))
        )
        assert_that(
            db_get_resp,
            is_not(has_header("Access-Control-Expose-Headers"))
        )
        assert_that(
            srv.res.post(db_path, headers={"Origin":origin}, data="{}").json(),
            has_key("ok")
        )
        assert_that(
            srv.res.get(db_path+"/_all_docs", headers={"Origin":origin}).json(),
            has_key("rows")
        )
示例#8
0
    def test_delete_order(self):
        new_order = Order().create()

        retreived_order = self.order_store.retrieve(new_order.id)
        assert_that(retreived_order, is_(equal_to(new_order)))

        new_order.delete()
        assert_that(
            calling(self.order_store.retrieve).with_args(identifier=new_order.id),
            raises(ModelNotFoundError),
        )
def test_unshared_db():
    srv = cloudant.get_server(auth=(USER, USER))
    headers = {
        "Origin": ORIGIN,
        "Access-Control-Request-Method": "GET"
    }
    db_path = "/" + SHARED_DB

    with srv.user_context(OWNER, OWNER):
        db = srv.db(SHARED_DB)
        db.reset()
        db.set_security(UNSHARED_SECURITY_DOC)

    with srv.user_context(USER, USER, owner=OWNER):
        assert_that(
            calling(srv.res.options).with_args(db_path),
            raises(HTTPError)
        )
        assert_that(
            calling(srv.res.options).with_args(db_path, headers=headers),
            raises(HTTPError)
        )
示例#10
0
 def testMatchesIfFunctionRaisesASubclassOfTheExpectedBaseException(self):
     self.assert_matches("Subclassed BasedException", raises(BaseException),
                         calling(raise_baseException))
示例#11
0
 def testDoesNotMatchTypeErrorIfActualIsNotCallable(self):
     self.assert_does_not_match("Not callable", raises(TypeError), 23)
示例#12
0
 def testMatchesIfFunctionRaisesTheExactExceptionExpected(self):
     self.assert_matches("Right exception", raises(AssertionError),
                         calling(raise_exception))
示例#13
0
def test_gives_correct_message_when_wrapped_with_is_not(expected_message):
    assert_mismatch_description(expected_message, not_(raises(AssertionError)),
                                calling(raise_exception))
示例#14
0
 def testMatchesIfFunctionRaisesTheExactExceptionExpected(self):
     self.assert_matches('Right exception',
                         raises(AssertionError),
                         calling(raise_exception))
示例#15
0
 def testDoesNotMatchExceptionIfRegularExpressionDoesNotMatch(self):
     self.assert_does_not_match('Bad regex',
                                raises(AssertionError, "Phrase not found"),
                                calling(raise_exception))
示例#16
0
 def testDoesNotMatchIfFunctionDoesNotRaiseException(self):
     self.assert_does_not_match('No exception',
                         raises(ValueError),
                         calling(no_exception))
示例#17
0
 def testMatchesIfFunctionRaisesASubclassOfTheExpectedException(self):
     self.assert_matches('Subclassed Exception',
                         raises(Exception),
                         calling(raise_exception))
示例#18
0
 def testDoesNotMatchTypeErrorIfActualIsNotCallable(self):
     self.assert_does_not_match('Not callable',
                                raises(TypeError),
                                23)
示例#19
0
 def testDoesNotMatchIfFunctionDoesNotRaiseException(self):
     self.assert_does_not_match("No exception", raises(ValueError),
                                calling(no_exception))
示例#20
0
 def testDoesNotMatchExceptionIfRegularExpressionDoesNotMatch(self):
     self.assert_does_not_match("Bad regex",
                                raises(AssertionError, "Phrase not found"),
                                calling(raise_exception))
 def testMatchesIfFunctionRaisesASubclassOfTheExpectedException(self):
     self.assert_matches('Subclassed Exception', raises(Exception),
                         calling(raise_exception))
示例#22
0
 def testDescribeMismatchWillCallItemIfNotTheOriginalMatch(self):
     function = Callable()
     matcher = raises(AssertionError)
     matcher.describe_mismatch(function, object())
     self.assertTrue(function.called)
示例#23
0
 def testDescribeMismatchWillCallItemIfNotTheOriginalMatch(self):
     function = Callable()
     matcher = raises(AssertionError)
     matcher.describe_mismatch(function, object())
     self.assertTrue(function.called)