我想使用Django和Tastypie实现一个API,并尝试使用TDD。因为API中有几个资源,我想创建一个继承自ResourceTestCase的基类,只是覆盖POST或PUT方法,但是测试套件试图将Base类作为测试执行,这是一个错误。
基本上我这样做:
class BaseResource(ResourceTestCase):
username = 'admin'
password = 'password'
url = '/api/v1/'
def get_credentials(self):
return self.create_basic(username=self.username, password=self.password)
def test_list_resource(self):
resp = self.api_client.get(self.url, format = 'json', authentication=self.get_credentials())
self.assertValidJSONResponse(resp)
self.assertEqual(len(self.deserialize(resp)['objects']), self.l_res)
class SomeResourceTest(BaseResource):
fixtures = ['some_fixture.json']
def setUp(self):
super(SomeResourceTest, self).setUp()
self.url = '/api/v1/some/'
self.l_res = 2
如何排除Base类的测试?