コード例 #1
0
    def test_up(self):
        w = Wiremock(host="localhost", port=8080)
        w.delete_all_mappings()
        mapping = {
            "request": {
                "method": "GET",
                "url": "/some/thing/to/delete"
            },
            "response": {
                "status": 200,
                "body": "Hello world!",
                "headers": {
                    "Content-Type": "text/plain"
                },
                "chunkedDribbleDelay": {
                    "numberOfChunks": 5,
                    "totalDuration": 1000
                }
            }
        }
        id = w.add_mapping(mapping)

        stored_mapping = w.mapping_by_id(id)
        self.assertEqual(stored_mapping["id"], id)
        self.assertEqual(
            stored_mapping["response"]["chunkedDribbleDelay"]
            ["numberOfChunks"], 5)
        ids_up = w.up([{"method": "GET", "url": "/some/thing/to/delete"}])

        up_mapping = w.mapping_by_id(ids_up[0])
        self.assertFalse("chunkedDribbleDelay" in up_mapping["response"])
コード例 #2
0
 def test_random_delay(self):
     w = Wiremock(host="localhost", port=8080)
     w.delete_all_mappings()
     mapping = {
         "request": {
             "method": "GET",
             "url": "/some/thing/to/delete"
         },
         "response": {
             "status": 200,
             "body": "Hello world!",
             "headers": {
                 "Content-Type": "text/plain"
             }
         }
     }
     id = w.add_mapping(mapping)
     delayed = w.random_delay(filter=mapping['request'],
                              delayDistribution={
                                  "type": "lognormal",
                                  "median": 80,
                                  "sigma": 0.4
                              })
     self.assertTrue(isinstance(delayed['id'], str))
     self.assertEqual(delayed['id'], id)
コード例 #3
0
    def test_chunked_dribble_delay(self):
        w = Wiremock(host="localhost", port=8080)
        w.delete_all_mappings()
        mapping = {
            "request": {
                "method": "GET",
                "url": "/some/thing/to/delete"
            },
            "response": {
                "status": 200,
                "body": "Hello world!",
                "headers": {
                    "Content-Type": "text/plain"
                }
            }
        }
        id = w.add_mapping(mapping)
        delayed = w.chunked_dribble_delay(mapping["request"], {
            "numberOfChunks": 5,
            "totalDuration": 1000
        })
        self.assertTrue(isinstance(delayed, dict))
        self.assertTrue(isinstance(delayed["id"], str))
        self.assertEqual(delayed["id"], id)

        map = w.mapping_by_id(delayed["id"])
        self.assertEqual(
            map["response"]["chunkedDribbleDelay"]["totalDuration"], 1000)
コード例 #4
0
 def test_mapping_by_request_exact_match(self):
     w = Wiremock(host="localhost", port=8080)
     w.delete_all_mappings()
     self.assertEqual(len(w.populate_from_dir('./tests/mappings')), 2)
     #         import pdb; pdb.set_trace()
     filter = {"method": "GET", "url": "/epg"}
     mapping = w.mapping_by_request_exact_match(filter)
     self.assertEqual(mapping['request'], filter)
コード例 #5
0
 def test_mapping_by_request(self):
     w = Wiremock(host="localhost", port=8080)
     w.delete_all_mappings()
     self.assertEqual(len(w.populate_from_dir('./tests/mappings')), 2)
     #         import pdb; pdb.set_trace()
     filter = {
         "method": "GET",
         "url": "/epg",
         "queryParameters": {
             "episode_title": {
                 "matches": "([a-z]*)"
             }
         }
     }
     mapping = w.mapping_by_request(filter)
     self.assertEqual(mapping['request'], filter)
コード例 #6
0
 def test_mapping_by_url_and_method(self):
     w = Wiremock(host="localhost", port=8080)
     w.delete_all_mappings()
     id = w.add_mapping({
         "request": {
             "method": "GET",
             "url": "/some/thing/to/delete"
         },
         "response": {
             "status": 200,
             "body": "Hello world!",
             "headers": {
                 "Content-Type": "text/plain"
             }
         }
     })
     mapping = w.mapping_by_url_and_method("/some/thing/to/delete", "GET")
     self.assertTrue(isinstance(mapping, dict))
     self.assertEqual(mapping["id"], id)
コード例 #7
0
 def test_mappings(self):
     w = Wiremock(host="localhost", port=8080)
     w.delete_all_mappings()
     w.add_mapping({
         "request": {
             "method": "GET",
             "url": "/some/thing/to/delete"
         },
         "response": {
             "status": 200,
             "body": "Hello world!",
             "headers": {
                 "Content-Type": "text/plain"
             }
         }
     })
     mappings = w.mappings()
     self.assertTrue(isinstance(mappings, list))
     self.assertEqual(len(mappings), 1)
コード例 #8
0
 def test_fixed_delay(self):
     #         import pdb; pdb.set_trace()
     w = Wiremock(host="localhost", port=8080)
     w.delete_all_mappings()
     mapping = {
         "request": {
             "method": "GET",
             "url": "/some/delay"
         },
         "response": {
             "status": 200,
             "body": "Hello world!",
             "headers": {
                 "Content-Type": "text/plain"
             }
         }
     }
     id = w.add_mapping(mapping)
     delayed = w.fixed_delay(mapping['request'], 10000)
     self.assertTrue(isinstance(delayed, dict))
     self.assertTrue(isinstance(delayed["id"], str))
     self.assertEqual(delayed["id"], id)
コード例 #9
0
 def test_populate_from_dir(self):
     w = Wiremock(host="localhost", port=8080)
     w.delete_all_mappings()
     self.assertEqual(len(w.populate_from_dir('./tests/mappings')), 2)
     mappings = w.mappings()
     self.assertEqual(len(mappings), 2)