fixtures

Django: Create fixtures without specifying a primary key?

拟墨画扇 提交于 2019-11-28 17:09:57
One of the things that bugs me about Django fixtures is that you've got to specify every model's primary key. Is there any way to create fixtures without having to specify a primary key for each row? Use "pk: null" instead of "pk: 1" (or whatever), which will result in the PK being set to None, and when the object is saved a primary key will be assigned. This works for YAML at least, I'm guessing you're using that if you are creating by hand. You should have a look at Natural Keys if you're wiling to add relation without using pk's https://docs.djangoproject.com/en/dev/ref/django-admin/

What are fixtures in programming?

狂风中的少年 提交于 2019-11-28 13:52:27
问题 I heard this term many times before (when talking about programming) but couldn't find any explanation what does it mean. Any good articles or explanations? I didn't find anything worth mentioning. 回答1: I think you're referring to test fixtures: The purpose of a test fixture is to ensure that there is a well known and fixed environment in which tests are run so that results are repeatable. Some people call this the test context. Examples of fixtures: - Loading a database with a specific,

League fixture generator in python [duplicate]

我的梦境 提交于 2019-11-28 11:44:35
This question already has an answer here: Generating natural schedule for a sports league 2 answers I would like to write a League Fixture generator in python, but I can't. Here is the details: There is a dynamic list of teams like teams = ["Team1", "Team2", "Team3", "Team4"] . How can I generate a fixture_weekx list from the teams list? For example: fixture_week1 = ["Team1", "Team2", "Team3", "Team4"] fixture_week2 = ["Team1", "Team3", "Team2", "Team4"] fixture_week2 = ["Team1", "Team4", "Team2", "Team3"] #Return matches: fixture_week1 = ["Team2", "Team1", "Team4", "Team3"] fixture_week2 = [

Using factory_girl in Rails with associations that have unique constraints. Getting duplicate errors

戏子无情 提交于 2019-11-28 03:23:34
I'm working with a Rails 2.2 project working to update it. I'm replacing existing fixtures with factories (using factory_girl) and have had some issues. The problem is with models that represent tables with lookup data. When I create a Cart with two products that have the same product type, each created product is re-creating the same product type. This errors from a unique validation on the ProductType model. Problem Demonstration This is from a unit test where I create a Cart and put it together in pieces. I had to do this to get around the problem. This still demonstrates the problem though

Do fixtures trigger model callbacks?

大城市里の小女人 提交于 2019-11-27 22:07:06
Say I have a User model with the following code in User.rb: before_create :create_dependencies after_create :build_inbox And I also have a users.yml file with a bunch of user fixtures defined in it. When I run rake db:fixtures:load, it doesn't appear to trigger the callbacks. Is this how it is expected to work? If so, why did they design it this way? Is there a way to force the triggering of the callbacks when loading fixtures? Is this how it is expected to work? If so, why did they design it this way? Yes, fixtures do not use callbacks. I'm assuming this is for performance reasons. It is

Symfony 3.4.0 Could not find any fixture services to load

本小妞迷上赌 提交于 2019-11-27 17:20:34
问题 I am using Symfony 3.4.0, I try to load fixtures with: php bin/console doctrine:fixtures:load An error occurred while creating the data, what's wrong? 回答1: This command looks for all services tagged with doctrine.fixture.orm . There is two ways to fix this problem. First one: any class that implements ORMFixtureInterface will automatically be registered with this tag. <?php namespace AppBundle\DataFixtures\ORM; use Doctrine\Bundle\FixturesBundle\ORMFixtureInterface; use Doctrine\Common

Rails Fixtures not loading with rspec

冷暖自知 提交于 2019-11-27 14:30:29
问题 So, I'm trying to learn the rspec BDD testing framework in the context of a rails project. The problem I'm having is that I can't, for the life of me, get my fixtures to load properly in rspec descriptions. Disclaimer: Yes, there are better things than fixtures to use. I'm trying to learn one thing at a time, here (specifically rspec) before I go play with associated tools like factory-girl, mocha, auto-test, etc. As such, I'm trying to get the dead-simple, if clunky, fixtures working. Anyway

Django: Create fixtures without specifying a primary key?

那年仲夏 提交于 2019-11-27 10:14:40
问题 One of the things that bugs me about Django fixtures is that you've got to specify every model's primary key. Is there any way to create fixtures without having to specify a primary key for each row? 回答1: Use "pk: null" instead of "pk: 1" (or whatever), which will result in the PK being set to None, and when the object is saved a primary key will be assigned. This works for YAML at least, I'm guessing you're using that if you are creating by hand. 回答2: You should have a look at Natural Keys

League fixture generator in python [duplicate]

ぐ巨炮叔叔 提交于 2019-11-27 06:26:10
问题 This question already has an answer here: Generating natural schedule for a sports league 2 answers I would like to write a League Fixture generator in python, but I can't. Here is the details: There is a dynamic list of teams like teams = ["Team1", "Team2", "Team3", "Team4"] . How can I generate a fixture_weekx list from the teams list? For example: fixture_week1 = ["Team1", "Team2", "Team3", "Team4"] fixture_week2 = ["Team1", "Team3", "Team2", "Team4"] fixture_week2 = ["Team1", "Team4",

Pass a parameter to a fixture function

坚强是说给别人听的谎言 提交于 2019-11-27 06:06:23
I am using py.test to test some DLL code wrapped in a python class MyTester. For validating purpose I need to log some test data during the tests and do more processing afterwards. As I have many test_... files I want to reuse the tester object creation (instance of MyTester) for most of my tests. As the tester object is the one which got the references to the DLL's variables and functions I need to pass a list of the DLL's variables to the tester object for each of the test files (variables to be logged are the same for a test_... file). The content of the list is shall be used to log the