Esempio n. 1
0
    def test_iter_bound_tokens(self):
        dc = KeyValueContainer([(u'a', ['1']), (u'b', ['2', '3'])])
        dcc_tokens = [(dcc, t) for dcc, t in dc.iter_bound_tokens()]

        EXPECTED_TOKENS = [('a', '1'), ('b', '2'), ('b', '3')]
        token_data = [(t.get_name(), t.get_value()) for dcc, t in dcc_tokens]
        self.assertEqual(EXPECTED_TOKENS, token_data)

        for dcc, _ in dcc_tokens:
            self.assertIsInstance(dcc, KeyValueContainer)
            self.assertEquals(dcc, dc)

        self.assertEqual(str(dcc), 'a=1&b=2&b=3')

        only_dcc = [dcc for dcc, t in dcc_tokens]
        dcc = only_dcc[0]
        token = dcc.get_token()
        token.set_value('5')
        self.assertEqual(str(dcc), 'a=5&b=2&b=3')

        dcc = only_dcc[1]
        token = dcc.get_token()
        token.set_value('5')
        self.assertEqual(str(dcc), 'a=1&b=5&b=3')

        dcc = only_dcc[2]
        token = dcc.get_token()
        token.set_value('5')
        self.assertEqual(str(dcc), 'a=1&b=2&b=5')
Esempio n. 2
0
    def test_iter_bound_tokens(self):
        dc = KeyValueContainer([(u'a', ['1']), (u'b', ['2', '3'])])
        dcc_tokens = [(dcc, t) for dcc, t in dc.iter_bound_tokens()]

        EXPECTED_TOKENS = [('a', '1'), ('b', '2'), ('b', '3')]
        token_data = [(t.get_name(), t.get_value()) for dcc, t in dcc_tokens]
        self.assertEqual(EXPECTED_TOKENS, token_data)

        for dcc, _ in dcc_tokens:
            self.assertIsInstance(dcc, KeyValueContainer)
            self.assertEquals(dcc, dc)

        self.assertEqual(str(dcc), 'a=1&b=2&b=3')

        only_dcc = [dcc for dcc, t in dcc_tokens]
        dcc = only_dcc[0]
        token = dcc.get_token()
        token.set_value('5')
        self.assertEqual(str(dcc), 'a=5&b=2&b=3')

        dcc = only_dcc[1]
        token = dcc.get_token()
        token.set_value('5')
        self.assertEqual(str(dcc), 'a=1&b=5&b=3')

        dcc = only_dcc[2]
        token = dcc.get_token()
        token.set_value('5')
        self.assertEqual(str(dcc), 'a=1&b=2&b=5')
Esempio n. 3
0
    def test_double_data_token_wrap(self):
        dc = KeyValueContainer([(u'a', ['1']), (u'b', ['c', '3'])])
        dc.set_token(('b', 1))

        for dcc, token in dc.iter_bound_tokens():
            self.assertIsInstance(token, DataToken)
            self.assertIsInstance(token.get_value(), basestring)
Esempio n. 4
0
    def test_double_data_token_wrap(self):
        dc = KeyValueContainer([(u'a', ['1']), (u'b', ['c', '3'])])
        dc.set_token(('b', 1))

        for dcc, token in dc.iter_bound_tokens():
            self.assertIsInstance(token, DataToken)
            self.assertIsInstance(token.get_value(), basestring)