Пример #1
0
    def test_render_PUT_missing_fqdn(self):
        malformedentry = dict(self.expectedentry)
        del malformedentry['fqdn']

        body = json.dumps(malformedentry, indent=2, sort_keys=True)

        self.m_request.content.read.return_value = body

        # Execute the code under test:
        retval = self.ur.render_PUT(self.m_request)

        # Verifications:
        self.assertEqual(server.NOT_DONE_YET, retval)

        # Verify that m_db was not modified (or accessed) in any way:
        self.assertEqual(
            self.m_db.mock_calls,
            [])

        # Verify that a 400 response was sent:
        self.assertEqual(
            self.m_request.mock_calls,
            [call.content.read(),
             call.sendJsonErrorMessage("Missing 'fqdn' field."),
             ])
Пример #2
0
    def test_render_GET_bad_args(self):
        vector = [
            ({}, "Missing 'policy' parameter."),
            ({"policy": ["a", "b"]}, "Multiple 'policy' parameters unsupported."),
            ({"policy": ["best"]}, "Only 'policy=all' parameter supported."),
            ({"policy": ["all"], "format": ["a", "b"]}, "Multiple 'format' parameters unsupported."),
            ({"policy": ["all"], "format": ["foo"]}, "Only 'format=json' parameter supported."),
        ]

        for (args, errmsg) in vector:
            m_db = MagicMock()
            m_request = MagicMock()
            m_request.args = args

            lsr = lookup.LookupSimulatorResource(m_db)
            retval = lsr.render_GET(m_request)

            # Verifications:
            self.assertEqual(server.NOT_DONE_YET, retval)

            # Verify that a 400 response was sent:
            self.assertEqual(m_request.mock_calls, [call.sendJsonErrorMessage(errmsg)])

            # Verify that db was not touched:
            self.assertEqual(m_db.mock_calls, [])
Пример #3
0
    def test_render_PUT_malformed_JSON(self):
        self.m_request.content.read.return_value = self.entryjson[:-1] # Mangled with slice.

        # Execute the code under test:
        retval = self.ur.render_PUT(self.m_request)

        # Verifications:
        self.assertEqual(server.NOT_DONE_YET, retval)

        # Verify that m_db was not modified (or accessed) in any way:
        self.assertEqual(
            self.m_db.mock_calls,
            [])

        # Verify that a 400 response was sent:
        self.assertEqual(
            self.m_request.mock_calls,
            [call.content.read(),
             call.sendJsonErrorMessage('Malformed JSON body.'),
             ])
Пример #4
0
    def test_render_GET_bad_args(self):
        vector = [
            ({}, "Missing 'policy' parameter."),
            ({
                'policy': ['a', 'b']
            }, "Multiple 'policy' parameters unsupported."),
            ({
                'policy': ['best']
            }, "Only 'policy=all' parameter supported."),
            ({
                'policy': ['all'],
                'format': ['a', 'b']
            }, "Multiple 'format' parameters unsupported."),
            ({
                'policy': ['all'],
                'format': ['foo']
            }, "Only 'format=json' parameter supported."),
        ]

        for (args, errmsg) in vector:
            m_db = MagicMock()
            m_request = MagicMock()
            m_request.args = args

            lsr = lookup.LookupSimulatorResource(m_db)
            retval = lsr.render_GET(m_request)

            # Verifications:
            self.assertEqual(server.NOT_DONE_YET, retval)

            # Verify that a 400 response was sent:
            self.assertEqual(m_request.mock_calls,
                             [call.sendJsonErrorMessage(errmsg)])

            # Verify that db was not touched:
            self.assertEqual(m_db.mock_calls, [])