fixture

How do you put a file in a fixture in Django?

前提是你 提交于 2020-01-11 19:51:29
问题 I can easily fill the field of a FileField or ImageField in a Django fixture with a file name, but that file doesn't exist and when I try to test my application it fails because that file doesn't exist. How do I correctly populate a FileField or Imagefield in a Django fixture so that the file itself is available too? 回答1: I'm afraid the short answer is that you can't do this using the FileField or ImageField classes; they just store a file path and have no real concept of the file's actual

CakePHP 3.x - fixtures import does not load data

守給你的承諾、 提交于 2019-12-24 03:27:26
问题 I am trying to import fixtures in my CakePHP 3.x plugin. When I launch the tests, I always get the error : UserManager\Test\TestCase\Controller\UsersControllerTest::testProfile exception 'Cake\Datasource\Exception\RecordNotFoundException' with message 'Record not found in table "users" Here is UsersFixture.php : namespace UserManager\Test\Fixture; use Cake\TestSuite\Fixture\TestFixture; class UsersFixture extends TestFixture { public $import = ['table' => 'users']; } My test fails because it

Is it possible to run tear down fixture only after all params runs?

吃可爱长大的小学妹 提交于 2019-12-20 03:33:32
问题 For instance if you have: @pytest.mark.parametrize('lang', ["EN", "FR"]) def test_whats_hot_quick_links_are_displayed(self, lang): # Do something here and i have this teardown fixture in conftest: @pytest.fixture(scope='function', autouse=True) def teardown_function(request): def execute_at_the_end(): logging.info("Ending Test Case...") database.clear() request.addfinalizer(execute_at_the_end) So how can i make the teardown function execute only after both EN and FR test runs are executed

Rails doesn't generate created_at for fixture

半城伤御伤魂 提交于 2019-12-18 08:52:45
问题 I have a model Question with "question_id", "elapsed_time", "allowed_time" and "status" as its fields and a controller named Reporting that receive JSON containing questions and save it. ("question_id" is not related to any of my models) So far there is no problem. Until I try to run some tests. I've an error when Rails is trying to load my Question's fixture : ActiveRecord::StatementInvalid: SQLite3::ConstraintException: questions.created_at may not be NULL: INSERT INTO "questions " Here's

How to load sql fixture in Django for User model?

烈酒焚心 提交于 2019-12-17 22:21:54
问题 Does anyone knows how to load initial data for auth.User using sql fixtures? For my models, I just got have a < modelname >.sql file in a folder named sql that syncdb does it's job beautifully. But I have no clue how to do it for the auth.User model. I've googled it, but with no success. Thanks in advance, Aldo 回答1: For SQL fixtures, you'd have to specifically have insert statements for the auth tables. You can find the schema of the auth tables with the command python manage.py sql auth .

Importing data from scanned text into Django as YAML fixture or SQL

╄→尐↘猪︶ㄣ 提交于 2019-12-11 09:06:49
问题 I'm setting up a simple Django app -- a quiz. The questions and answers come from printed sample tests that have been scanned, OCR'd and parsed. I've parsed them into Python objects like so: class Quiz(object): def __init__(self, name): self.name = name self.questions = {} class Question(object): def __init__(self, text): self.text = text self.answers = {} class Answer(object): def __init__(self, text, value= -1.0, explanation=""): self.text = text self.value = value self.explanation =

Why would a pytest factory as fixture be used over a factory function?

不羁的心 提交于 2019-12-07 17:55:25
问题 In the py.test docs it describes declaring factory methods as fixtures, like-so: @pytest.fixture def make_foo(): def __make_foo(name): foo = Foo() foo.name = name return foo return __make_foo What are the benefits/tradeoffs of doing this over just defining a make_foo function and using that? I don't understand why it is a fixture. 回答1: Actually, the most important advantage is being able to use other fixtures, and make the dependency injection of pytest work for you. The other advantage is

Django - Foreign Keys in Fixtures

白昼怎懂夜的黑 提交于 2019-12-06 18:30:01
问题 I have a fixture of "User" objects (just the default Django auth ones), and am trying to create a fixture of "Profile" objects. Each profile has a one-to-one relation to a user object, and defines some more custom stuff for that user. As far as I can tell, the normal way of dealing with foreign keys in a fixture is to just hardcode the primary key of the foreign object into the fixture. Is there a way to avoid doing that? Basically, I'm trying to have something like '"user":username' in the

Why would a pytest factory as fixture be used over a factory function?

南楼画角 提交于 2019-12-05 21:07:32
In the py.test docs it describes declaring factory methods as fixtures, like-so: @pytest.fixture def make_foo(): def __make_foo(name): foo = Foo() foo.name = name return foo return __make_foo What are the benefits/tradeoffs of doing this over just defining a make_foo function and using that? I don't understand why it is a fixture. Actually, the most important advantage is being able to use other fixtures, and make the dependency injection of pytest work for you. The other advantage is allowing you to pass parameters to the factory, which would have to be static in a normal fixture. Look at

Django - Foreign Keys in Fixtures

百般思念 提交于 2019-12-04 23:46:47
I have a fixture of "User" objects (just the default Django auth ones), and am trying to create a fixture of "Profile" objects. Each profile has a one-to-one relation to a user object, and defines some more custom stuff for that user. As far as I can tell, the normal way of dealing with foreign keys in a fixture is to just hardcode the primary key of the foreign object into the fixture. Is there a way to avoid doing that? Basically, I'm trying to have something like '"user":username' in the fixture rather than '"user":pk'. Is there any way to do this? You're looking for "Natural Keys" https:/