【问题标题】:How to call a method of a derived class whose base class is ResourceTestCase如何调用基类为 ResourceTestCase 的派生类的方法
【发布时间】:2015-04-04 22:18:02
【问题描述】:

我在 SomeClass 类中编写了一些测试用例,它的工作非常好,对于这个测试用例,我使用了 2 种方法 anyMethodanotherMethod

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.

【问题讨论】:

    标签: django python-2.7 tastypie


    【解决方案1】:

    你应该从 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)
    

    【讨论】:

      猜你喜欢
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      • 1970-01-01
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-23
      相关资源
      最近更新 更多