def test_has_unbound_variables(self): base = '/{id}/{pk}/sdf' template = TemplatedString(base) self.assertTrue(template.has_unbound_variables()) base = '/sdf' template = TemplatedString(base) self.assertFalse(template.has_unbound_variables())
def test_init(self): base = '/blah/' template = TemplatedString(base) self.assertEqual(len(template.param_dict), 0) base = '/{id}/{pk}/sdf' template = TemplatedString(base) self.assertEqual(len(template.param_dict), 2) self.assertEqual(template.param_dict['id'], '{id}') self.assertEqual(template.param_dict['pk'], '{pk}')
def test_bind(self): base = '/{id}/{pk}/sdf' template = TemplatedString(base) template2 = template.bind(id=1) self.assertEqual(template2.base, '/1/{pk}/sdf') self.assertDictEqual(template2.param_dict, {'pk': '{pk}'}) template3 = template2.bind(id=1) self.assertEqual(template3.base, '/1/{pk}/sdf') self.assertDictEqual(template3.param_dict, {'pk': '{pk}'}) template4 = template3.bind(pk=2) self.assertEqual(template4.base, '/1/2/sdf') self.assertDictEqual(template4.param_dict, {}) template5 = template4.bind(who='asdknf', cares=23) self.assertEqual(template5.base, '/1/2/sdf') self.assertDictEqual(template5.param_dict, {})
def test_as_string(self): base = '/{id}/{pk}/sdf' template = TemplatedString(base) self.assertEqual(base, template.as_string())
def test_unbound_variables(self): base = '/{id}/{pk}/sdf' template = TemplatedString(base) for p in ['id', 'pk']: self.assertIn(p, template.unbound_variables())
def test_items(self): base = '/{id}/{pk}/sdf' template = TemplatedString(base) for p in [('id', '{id}'), ('pk', '{pk}')]: self.assertIn(p, template.items())