def test_pickle(self):
        original = JSONContainer(COMPLEX_OBJECT)

        e_headers = [('Content-Type', 'application/json')]
        self.assertEquals(original.get_headers(), e_headers)

        clone = pickle.loads(pickle.dumps(original))
        self.assertEquals(original, clone)
        self.assertEquals(clone.get_headers(), e_headers)

        original = JSONContainer(COMPLEX_OBJECT)
        original.set_header('Content-Type', 'application/vnd.w3af+json')

        e_headers = [('Content-Type', 'application/vnd.w3af+json')]
        self.assertEquals(original.get_headers(), e_headers)

        clone = pickle.loads(pickle.dumps(original))
        self.assertEquals(original, clone)
        self.assertEquals(clone.get_headers(), e_headers)

        original = JSONContainer(COMPLEX_OBJECT)
        original.set_header('X-Foo-Header', 'Bar')

        e_headers = [('Content-Type', 'application/json'), ('X-Foo-Header', 'Bar')]
        self.assertEquals(original.get_headers(), e_headers)

        clone = pickle.loads(pickle.dumps(original))
        self.assertEquals(original, clone)
        self.assertEquals(clone.get_headers(), e_headers)
Example #2
0
    def test_pickle(self):
        original = JSONContainer(COMPLEX_OBJECT)

        e_headers = [('Content-Type', 'application/json')]
        self.assertEquals(original.get_headers(), e_headers)

        clone = pickle.loads(pickle.dumps(original))
        self.assertEquals(original, clone)
        self.assertEquals(clone.get_headers(), e_headers)

        original = JSONContainer(COMPLEX_OBJECT)
        original.set_header('Content-Type', 'application/vnd.w3af+json')

        e_headers = [('Content-Type', 'application/vnd.w3af+json')]
        self.assertEquals(original.get_headers(), e_headers)

        clone = pickle.loads(pickle.dumps(original))
        self.assertEquals(original, clone)
        self.assertEquals(clone.get_headers(), e_headers)

        original = JSONContainer(COMPLEX_OBJECT)
        original.set_header('X-Foo-Header', 'Bar')

        e_headers = [('Content-Type', 'application/json'),
                     ('X-Foo-Header', 'Bar')]
        self.assertEquals(original.get_headers(), e_headers)

        clone = pickle.loads(pickle.dumps(original))
        self.assertEquals(original, clone)
        self.assertEquals(clone.get_headers(), e_headers)
    def test_wrong_headers(self):
        jcont = JSONContainer(COMPLEX_OBJECT)

        with self.assertRaises(TypeError):
            jcont.set_header(1, 'Foo')

        with self.assertRaises(TypeError):
            jcont.set_header('Foo', 1)

        with self.assertRaises(TypeError):
            JSONContainer(COMPLEX_OBJECT, 'Foo')

        with self.assertRaises(TypeError):
            JSONContainer(COMPLEX_OBJECT, [])
Example #4
0
    def test_wrong_headers(self):
        jcont = JSONContainer(COMPLEX_OBJECT)

        with self.assertRaises(TypeError):
            jcont.set_header(1, 'Foo')

        with self.assertRaises(TypeError):
            jcont.set_header('Foo', 1)

        with self.assertRaises(TypeError):
            JSONContainer(COMPLEX_OBJECT, 'Foo')

        with self.assertRaises(TypeError):
            JSONContainer(COMPLEX_OBJECT, [])
    def test_headers(self):
        jcont = JSONContainer(COMPLEX_OBJECT)

        e_headers = [('Content-Type', 'application/json')]
        self.assertEquals(jcont.get_headers(), e_headers)

        jcont.set_header('Content-Type', 'application/vnd.w3af+json')
        e_headers = [('Content-Type', 'application/vnd.w3af+json')]
        self.assertEquals(jcont.get_headers(), e_headers)

        jcont.set_header('X-Foo-Header', 'Bar')
        e_headers = [('Content-Type', 'application/vnd.w3af+json'), ('X-Foo-Header', 'Bar')]
        self.assertEquals(jcont.get_headers(), e_headers)

        headers = {'Content-Type': 'application/vnd.w3af+json', 'X-Foo-Header': 'Bar'}
        jcont = JSONContainer(COMPLEX_OBJECT, headers)

        e_headers = [('Content-Type', 'application/vnd.w3af+json'), ('X-Foo-Header', 'Bar')]
        self.assertEquals(jcont.get_headers(), e_headers)

        jcont.set_header('X-Foo-Header', '42')
        e_headers = [('Content-Type', 'application/vnd.w3af+json'), ('X-Foo-Header', '42')]
        self.assertEquals(jcont.get_headers(), e_headers)

        jcont = JSONContainer(COMPLEX_OBJECT, None)
        e_headers = [('Content-Type', 'application/json')]
        self.assertEquals(jcont.get_headers(), e_headers)
Example #6
0
    def test_headers(self):
        jcont = JSONContainer(COMPLEX_OBJECT)

        e_headers = [('Content-Type', 'application/json')]
        self.assertEquals(jcont.get_headers(), e_headers)

        jcont.set_header('Content-Type', 'application/vnd.w3af+json')
        e_headers = [('Content-Type', 'application/vnd.w3af+json')]
        self.assertEquals(jcont.get_headers(), e_headers)

        jcont.set_header('X-Foo-Header', 'Bar')
        e_headers = [('Content-Type', 'application/vnd.w3af+json'),
                     ('X-Foo-Header', 'Bar')]
        self.assertEquals(jcont.get_headers(), e_headers)

        headers = {
            'Content-Type': 'application/vnd.w3af+json',
            'X-Foo-Header': 'Bar'
        }
        jcont = JSONContainer(COMPLEX_OBJECT, headers)

        e_headers = [('Content-Type', 'application/vnd.w3af+json'),
                     ('X-Foo-Header', 'Bar')]
        self.assertEquals(jcont.get_headers(), e_headers)

        jcont.set_header('X-Foo-Header', '42')
        e_headers = [('Content-Type', 'application/vnd.w3af+json'),
                     ('X-Foo-Header', '42')]
        self.assertEquals(jcont.get_headers(), e_headers)

        jcont = JSONContainer(COMPLEX_OBJECT, None)
        e_headers = [('Content-Type', 'application/json')]
        self.assertEquals(jcont.get_headers(), e_headers)