How to use is_fixture method in Slash

Best Python code snippet using slash

api_checker.py

Source:api_checker.py Github

copy

Full Screen

1import datetime2import os3from functools import wraps4import pytest5from drf_api_checker.pytest import default_fixture_name6from drf_api_checker.recorder import BASE_DATADIR, Recorder7from rest_framework.response import Response8from rest_framework.test import APIClient9from tests.factories import UserFactory10def frozenfixture(fixture_name=default_fixture_name, is_fixture=True):11 def deco(func):12 from drf_api_checker.fs import mktree13 from drf_api_checker.utils import dump_fixtures, load_fixtures14 @wraps(func)15 def _inner(*args, **kwargs):16 if is_fixture and 'request' not in kwargs:17 raise ValueError('frozenfixture must have `request` argument')18 request = kwargs.get('request', None)19 parts = [os.path.dirname(func.__code__.co_filename),20 BASE_DATADIR,21 func.__module__,22 func.__name__]23 seed = os.path.join(*parts)24 destination = fixture_name(seed, request)25 if not os.path.exists(destination) or os.environ.get('API_CHECKER_RESET'):26 mktree(os.path.dirname(destination))27 data = func(*args, **kwargs)28 dump_fixtures({func.__name__: data}, destination)29 return load_fixtures(destination)[func.__name__]30 if is_fixture:31 return pytest.fixture(_inner)32 return _inner33 return deco34@frozenfixture(is_fixture=False)35def get_user():36 return UserFactory(is_superuser=True, username="user999")37class LastModifiedRecorder(Recorder):38 @property39 def client(self):40 user = get_user()41 client = APIClient()42 client.force_authenticate(user)43 return client44 def assert_modified(self, response: Response, stored: Response, path: str):45 value = response['modified']46 assert datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%S.%f%z')47 def assert_created(self, response: Response, stored: Response, path: str):48 value = response['created']49 assert datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%S.%f%z')50class ExpectedErrorRecorder(Recorder):...

Full Screen

Full Screen

fixture_parser.py

Source:fixture_parser.py Github

copy

Full Screen

1class fixture:2 _fixture = [ 'run keywords' ]3 def __init__(self, name, args):4 self.is_fixture = bool(name.lower() in self._fixture)5 self.args = list(args)6 self.name = name7 def parse(self):8 def run_keywords_parser(args):9 kw_list, arg_list, temp_list = [], [], []10 flag = True11 for arg in args:12 if flag:13 kw_list.append(arg)14 flag = False15 elif arg.lower() == 'and':16 arg_list.append(temp_list.copy())17 temp_list.clear()18 flag = True19 else:20 temp_list.append(arg)21 arg_list.append(temp_list.copy())22 return (kw_list, arg_list)23 if not self.is_fixture:24 return [ self.name ], self.args25 if self.name.lower() == 'run keywords':26 kw_lst, arg_lst = run_keywords_parser(self.args)27 return (kw_lst, arg_lst)28 raise Exception("Fixture keyword parsing error.")29if __name__ == "__main__":30 is_fixture = fixture('Run keywords', ['Log', 'A', 'AND', 'Log Source', 'AND', 'Log', 'B'])31 n_fixture = fixture('run keyword', ['A', 'B', 'C'])32 assert is_fixture.is_fixture == True33 assert n_fixture.is_fixture == False34 kw_list, arg_list = is_fixture.parse()35 assert kw_list == ['Log', 'Log Source', 'Log']36 assert arg_list == [['A'], [], ['B']]37 n_kw_list, n_arg_list = n_fixture.parse()38 assert n_kw_list == ['run keyword']...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful