base.py 1.14 KB
Newer Older
1
2
3
4
5
6
import copy
import logging
import re

from django.core.serializers.json import Deserializer

7
from core.tests import BaseTest as CoreBaseTest
8

9
10

class TestBase(CoreBaseTest):
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    logger = logging.getLogger('representatives')

    _exclude = ('id', '_state', 'created', 'updated', 'fingerprint')
    _exclude_re = (re.compile(r'^_.*_cache$'),)

    def assertObjectsFromFixture(self, fixture):
        missing = []

        with open(fixture, 'r') as f:
            for obj in Deserializer(f.read()):
                compare = copy.copy(obj.object.__dict__)

                for field in self._exclude:
                    if field in compare:
                        compare.pop(field)

Nicolas Joyard's avatar
Fix QA    
Nicolas Joyard committed
27
                for r in self._exclude_re:
28
                    for field in compare.keys():
Nicolas Joyard's avatar
Fix QA    
Nicolas Joyard committed
29
                        if r.match(field):
30
31
32
33
34
35
36
37
38
39
                            compare.pop(field)

                try:
                    type(obj.object).objects.get(**compare)
                except:
                    self.logger.warn(
                        'MISSING %s\n   %s' % (type(obj.object), compare))
                    missing.append(compare)

        assert len(missing) is 0