コード例 #1
0
    def test_ignores_other_transactions(self):
        sock = patch_socket(self)
        self.patch_recv(sock, 1)
        self.patch_offer_packet()
        other_transaction_id = factory.getRandomBytes(4)

        self.assertEqual(set(), receive_offers(other_transaction_id))
コード例 #2
0
ファイル: test_fields.py プロジェクト: cloudbase/maas
 def test_emits_base64(self):
     # Piston hooks onto an __emittable__() method, if present.
     # Bin() returns a base-64 encoded string so that it can be
     # transmitted in JSON.
     self.assertEqual(b"", Bin(b"").__emittable__())
     example_bytes = factory.getRandomBytes()
     self.assertEqual(b64encode(example_bytes),
                      Bin(example_bytes).__emittable__())
コード例 #3
0
 def patch_offer_packet(self):
     """Patch a mock `DHCPOfferPacket`."""
     transaction_id = factory.getRandomBytes(4)
     packet = mock.MagicMock()
     packet.transaction_ID = transaction_id
     packet.dhcp_server_ID = factory.getRandomIPAddress()
     self.patch(detect_module, 'DHCPOfferPacket').return_value = packet
     return packet
コード例 #4
0
ファイル: test_fields.py プロジェクト: cloudbase/maas
 def test_emits_base64(self):
     # Piston hooks onto an __emittable__() method, if present.
     # Bin() returns a base-64 encoded string so that it can be
     # transmitted in JSON.
     self.assertEqual(b"", Bin(b"").__emittable__())
     example_bytes = factory.getRandomBytes()
     self.assertEqual(
         b64encode(example_bytes),
         Bin(example_bytes).__emittable__())
コード例 #5
0
    def test_propagates_errors_other_than_timeout(self):
        class InducedError(Exception):
            """Deliberately induced error for testing."""

        sock = patch_socket(self)
        sock.recv = mock.MagicMock(side_effect=InducedError)

        self.assertRaises(InducedError, receive_offers,
                          factory.getRandomBytes(4))
コード例 #6
0
    def patch_recv(self, sock, num_packets=0):
        """Patch up socket's `recv` to return `num_packets` arbitrary packets.

        After that, further calls to `recv` will raise a timeout.
        """
        packets = [factory.getRandomBytes() for _ in range(num_packets)]
        receiver = FakePacketReceiver(packets)
        self.patch(sock, 'recv', receiver)
        return receiver
コード例 #7
0
ファイル: test_tags.py プロジェクト: cloudbase/maas
 def test_merge_with_all_invalid_details(self):
     xml = self.do_merge_details({
         "lshw": b"<gibber></ish>",
         "foom": b"<not>well</formed>",
         "zoom": b"<>" + factory.getRandomBytes(),
         "oops": None,
     })
     expected = """\
         <list xmlns:foom="foom" xmlns:lshw="lshw"
               xmlns:oops="oops" xmlns:zoom="zoom"/>
     """
     self.assertThat(xml, EqualsXML(expected))
     # The error is logged however.
     self.assertDocTestMatches(
         """\
         Invalid foom details: ...
         Invalid lshw details: ...
         Invalid zoom details: ...
         """, self.logger.output)
コード例 #8
0
ファイル: test_tags.py プロジェクト: cloudbase/maas
 def test_merge_with_all_invalid_details(self):
     # merge_details() differs from merge_details_cleanly() in that
     # it first attempts to use the lshw details as the root #
     # element. If they're invalid the log message is therefore
     # printed first.
     xml = self.do_merge_details({
         "lshw": b"<gibber></ish>",
         "foom": b"<not>well</formed>",
         "zoom": b"<>" + factory.getRandomBytes(),
         "oops": None,
     })
     expected = """\
         <list xmlns:foom="foom" xmlns:lshw="lshw"
               xmlns:oops="oops" xmlns:zoom="zoom"/>
     """
     self.assertThat(xml, EqualsXML(expected))
     # The error is logged however.
     self.assertDocTestMatches(
         """\
         Invalid lshw details: ...
         Invalid foom details: ...
         Invalid zoom details: ...
         """, self.logger.output)
コード例 #9
0
ファイル: test_tags.py プロジェクト: cloudbase/maas
 def test_process_OK_response_with_other_content(self):
     data = factory.getRandomBytes()
     response = make_response(httplib.OK, data, "application/octet-stream")
     self.assertEqual(data, tags.process_response(response))