def test_expect_never(self):
        self.client.expect(
            request(),
            response(),
            times(0)
        )

        self.client.verify_expectations()
    def test_count_stubbing(self):
        self.client.stub(request(), response(), times(1))

        result = requests.get(MOCK_SERVER_URL + "/path")
        self.assertEqual(result.status_code, 200)

        result = requests.get(MOCK_SERVER_URL + "/path")
        self.assertEqual(result.status_code, 404)
    def test_expect_once_not_called_fails(self):
        self.client.expect(
            request(),
            response(),
            times(1)
        )

        with self.assertRaises(AssertionError):
            self.client.verify_expectations()
 def test_expect_with_ttl(self):
     self.client.expect(
         request(),
         response(),
         times(1),
         seconds(10)
     )
     result = requests.get(MOCK_SERVER_URL + "/path")
     self.assertEqual(result.status_code, 200)
    def test_reset_should_clear_expectations(self):
        self.client.expect(
            request(),
            response(),
            times(1)
        )

        self.client.reset()
        self.client.verify_expectations()
    def test_expect_once_called_twice_fails(self):
        self.client.expect(
            request(),
            response(),
            times(1)
        )

        result = requests.get(MOCK_SERVER_URL + "/path")
        self.assertEqual(result.status_code, 200)

        result = requests.get(MOCK_SERVER_URL + "/path")
        self.assertEqual(result.status_code, 404)
    def test_expect_json_contains(self):
        self.client.expect(request(body=json_contains({"key": "value"})),
                           response(), times(1))

        result = requests.get(MOCK_SERVER_URL + "/path",
                              json={"key1": "value2"})
        self.assertEquals(result.status_code, 404)

        result = requests.get(MOCK_SERVER_URL + "/path",
                              json={
                                  "key1": "value2",
                                  "key": "value"
                              })
        self.assertEquals(result.status_code, 200)
Ejemplo n.º 8
0
 def test_verify_request_received_once(self):
     self.client.stub(request(), response())
     requests.get(MOCK_SERVER_URL)
     self.client.verify(request(), times(1))
Ejemplo n.º 9
0
 def test_verify_all_expectations(self):
     self.client.expect(request(), response(), times(1))
     requests.get(MOCK_SERVER_URL)
     self.client.verify_expectations()
Ejemplo n.º 10
0
 def test_verify_request_not_received_fail(self):
     with self.assertRaises(AssertionError):
         self.client.verify(request(), times(1))
Ejemplo n.º 11
0
 def test_verify_request_never_received(self):
     self.client.verify(request(), times(0))