English 中文(简体)
2. 处理再处理和切合问题的建筑试验
原标题:building tests that deal with redis and cache_method decorator

So I m trying to build some tests f或 a project using redis but I have two methods giving me trouble.

这两种方法都使用<条码>@cache_method( dec或at或,并将产生一份类似于<条码>的失败报告。 Err或: [<ObjectName:e_name>] ! [<ObjectName:e_name>]。 测试既符合以下标准:

self.assertEquals(self.ObjectName.Method(), ObjectName.objects.none())

self.assertEquals(self.ObjectName.Method(), ObjectName.objects.filter(...))

If I use something like self.assertEquals(type(), type()) the test passes so I m at a complete loss.

我的考试班子认为:

class SimpleTest(TestCase):

    def setUp(self):
        self.reset_pool()
        self.cache = self.get_cache()
        self.cache.clear()

        ... setup a bunch of self.Object instances f或 the actual tests ...

    def reset_pool(self):
        if hasattr(self,  cache ):
            self.cache._client.connection_pool.disconnect()

    def get_cache(self, backend=None):
        if VERSION[0] == 1 and VERSION[1] < 3:
            cache = get_cache(backend 或  redis_cache.cache://127.0.0.1:6379?db=15 )
        elif VERSION[0] == 1 and VERSION[1] >= 3:
            cache = get_cache(backend 或  default )
        return cache

我如何能够通过这些测试?

问题回答

Does return return Me Me 如果我不怀疑这是你的问题。 <代码>ObjectName.objects.filter(......)将回复到QuerySet。 如果你的手法使别人回到别处,那么,自然就会失败。

更具体地说,ObjectName.objects.none()将退回django.db.models.query.Emtpy QuerySet和filter(>要么将django.db.models.query.EmptyQuerySet django.db.models.query.QuerySet ,视任何与过滤器匹配的情况而定。

So it seems somewhere you are trying to compare an ObjectName.method() that is either: a) not returning a QuerySet but something different -or- b) is returning QuerySet when an EmptyQuerySet is expected (such as when none() is called), or vice-versa.

由于我们不知道什么是<条码>。 反对Name.method() 是的,还是回报的,你需要研究这种/当时的方法,看看它正在恢复什么,以及可能的原因。

我希望你能够正确方向。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签