如何调用基类为ResourceTestCase的派生类的方法

时间:2015-02-05 06:29:31

标签: django python-2.7 tastypie

我已经在 SomeClass 类中编写了一些tast案例,并且它的工作正常,对于这个测试用例,我使用了2个方法 anyMethod anotherMethod

from tastypie.test import ResourceTestCase
from members.models import Org

class SomeClass(ResourceTestCase):
    fixtures = ['anyfixture']
    def setUp(self):
        super(SomeClass, self).setUp()
        self.webmaster_username = 'webmaster@gm.com'
        self.webmaster_password = '123'
    def anyMethod():
        self.api_client.client.login(username=self.webmaster_username,
                                 password=self.webmaster_password)
    def anotherMethod(dataDump):
        self.anyMethod()

        self.response = self.api_client.post(self.get_detail_url, format='json', data=dataDump)
        #More steps in function

我想要的是,我有另一个名为 AnotherClass 的类,因为我想从 SomeClass 中调用方法 anotherMethod

from tastypie.test import ResourceTestCase
from members.models import Org

class AnotherClass(ResourceTestCase):
    fixtures = ['fixture23']
    def setUp(self):
        super(AnotherClass, self).setUp()
        self.admin_username = 'admin@gm.com'
        self.admin_password = '123'
        #here I Need to call method anotherMethod from class SomeClass.

1 个答案:

答案 0 :(得分:0)

你应该从SomeClass继承AnotherClass:

class AnotherClass(SomeClass):
    fixtures = ['fixture23']
    def setUp(self):
        super(AnotherClass, self).setUp()
        self.admin_username = 'admin@gm.com'
        self.admin_password = '123'
        self.anotherMethod(self.fixtures)