Example #1
0
        def _inner(*args, **kwargs):
            if 'request' not in kwargs:
                raise ValueError('frozenfixture must have `request` argument')
            request = kwargs['request']
            parts = [
                os.path.dirname(func.__code__.co_filename), BASE_DATADIR,
                func.__module__, func.__name__
            ]
            # for x in (fixture_names or []):
            #     if callable(x):
            #         part = x(request)
            #     else:
            #         part = request.getfixturevalue(x)
            #     parts.append(part.__name__)
            #
            # destination = os.path.join(*parts) + '.fixture.json'
            seed = os.path.join(*parts)
            destination = fixture_name(seed, request)

            if not os.path.exists(destination) or os.environ.get(
                    'API_CHECKER_RESET'):
                mktree(os.path.dirname(destination))
                data = func(*args, **kwargs)
                dump_fixtures({func.__name__: data}, destination)
            return load_fixtures(destination)[func.__name__]
Example #2
0
 def _process_fixtures(self):
     """ store or retrieve test fixtures """
     fname = self.get_fixtures_filename()
     if os.path.exists(fname) and not os.environ.get('API_CHECKER_RESET'):
         self.__fixtures = load_fixtures(fname)
     else:
         self.__fixtures = self.get_fixtures()
         if self.__fixtures:
             dump_fixtures(self.__fixtures, fname)
Example #3
0
        def _inner(*args, **kwargs):
            if is_fixture and 'request' not in kwargs:
                raise ValueError('frozenfixture must have `request` argument')
            request = kwargs.get('request', None)
            parts = [os.path.dirname(func.__code__.co_filename),
                     BASE_DATADIR,
                     func.__module__,
                     func.__name__]
            seed = os.path.join(*parts)
            destination = fixture_name(seed, request)

            if not os.path.exists(destination) or os.environ.get('API_CHECKER_RESET'):
                mktree(os.path.dirname(destination))
                data = func(*args, **kwargs)
                dump_fixtures({func.__name__: data}, destination)
            return load_fixtures(destination)[func.__name__]
Example #4
0
def test_dump_fixtures_single(detail):
    stream = BytesIO()
    data = dump_fixtures({'d': detail}, stream)
    stream.seek(0)
    assert json.loads(stream.read())
    assert data['d']['master']['pk'] == detail.pk
    assert [e['pk'] for e in data['d']['deps']] == [detail.master.pk]
Example #5
0
def test_dump_fixtures_multiple(details):
    d1, d2 = details
    stream = BytesIO()
    data = dump_fixtures({'d': details}, stream)
    stream.seek(0)
    assert json.loads(stream.read())
    assert [e['pk'] for e in data['d']['master']] == [d1.pk, d2.pk]
    assert [e['pk'] for e in data['d']['deps']] == [d1.master.pk, d2.master.pk]
Example #6
0
        def _inner(*args, **kwargs):
            parts = [
                os.path.dirname(func.__code__.co_filename),
                BASE_DATADIR,
                func.__module__,
                func.__name__,
            ]
            if 'request' in kwargs:
                request = kwargs['request']
                viewset = request.getfixturevalue('viewset')
                parts.append(viewset.__name__)

            destination = os.path.join(*parts) + '.fixture.json'
            if os.path.exists(
                    destination) and not os.environ.get('API_CHECKER_RESET'):
                return load_fixtures(destination)[func.__name__]
            mktree(os.path.dirname(destination))
            data = func(*args, **kwargs)
            dump_fixtures({func.__name__: data}, destination)
            return data
Example #7
0
def test_load_fixtures_multiple(details):
    d1, d2 = details
    stream = BytesIO()
    dump_fixtures({'d': details}, stream)
    stream.seek(0)
    assert load_fixtures(stream) == {'d': list(details)}
Example #8
0
def test_load_fixtures_single(detail):
    stream = BytesIO()
    dump_fixtures({'d': detail}, stream)
    stream.seek(0)
    assert load_fixtures(stream) == {'d': detail}