views.py:
def handbook_cpu_add(request):
...
models.py:
class CPU(models.Model):
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
test.py:
def test_add_comparison_url(self):
helper.handbook_add_comparison_url(self, 'cpu')
helper.py:
def handbook_add_comparison_url(self, item):
found = resolve('/hardware/handbook/' + item + '/add/')
t = 'handbook_' + item + '_add'
self.assertEqual(found.func, t)
如何将变量't'从'string'类型转换为'handbook_cpu_add'类型?
答案 0 :(得分:3)
你正在考虑这个问题。您不需要将字符串转换为函数或视图,您只需从函数中获取名称并将其与您的字符串进行比较:
self.assertEqual(found.func.__name__, t)
答案 1 :(得分:0)