Re: more testing questions
1) I've been using Factory Boy to create test data rather than fixtures. It is so much easier to ensure that I know exactly what data is available for a given test. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.
Re: more testing questions
On Mon, Jul 8, 2013 at 5:41 PM, Larry Martellwrote: > So if you don't use dump files, what do you do? Load data row by row > from within your test's setups? no, i mostly write the fixture data by hand. except when i need a series of records to cover a all (most?) combinations, then i generate those in the shell and dump. but for the user and privileges tables, i do by hand. i think it's possible to create mostly clean dump files, but it's not easy, and i usually only need 2-5 different users for tests anyway. -- Javier -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.
Re: more testing questions
On Mon, Jul 8, 2013 at 4:21 PM, Javier Guerra Giraldezwrote: > On Mon, Jul 8, 2013 at 4:14 PM, Larry Martell wrote: >> It appesars it's trying to add a row to django_content_type and it's >> already there. I tried not loading the fixture for django_content_type >> but I got the same error. These fixture files contain data I dumped >> from my real db, so I know it's good. Googling this I found a few >> posts with people having the same problem, but they are all a few >> years old. People 'solved' this by using an external package >> (django-fixture-magic) or excluding the auth tables or hand >> re-ordering the records in the fixtures file. None of these seem like >> good solutions to me. Is this still a known problem? Shouldn't I be >> able to load data generated from a dump? > > > rigth, it's quite messy. i usually don't use dump files. (the mess, > they don't do so 'clean' tests). > > check 'natural keys' > (https://docs.djangoproject.com/en/1.5/topics/serialization/#natural-keys) > for a ways to get more robust fixtures Not having much success. I created the fixture for auth_permission with --natural, but I still got the same error: IntegrityError: Could not load auth.Permission(pk=166): (1062, "Duplicate entry '7-add_logentry' for key 'content_type_id'") Then I tried also creating django_content_type with --natural, but then I got a different error: Problem installing fixture '/usr/local/motor/motor/../motor/core/data/fixtures/django_content_type.json': Traceback (most recent call last): File "/Library/Python/2.7/site-packages/django/core/management/commands/loaddata.py", line 190, in handle for obj in objects: File "/Library/Python/2.7/site-packages/django/core/serializers/json.py", line 47, in Deserializer raise DeserializationError(e) DeserializationError: User matching query does not exist. I need to load these table to login and I need to login to run my other tests. Seems odd that these basic django auth tables give so much grief. So if you don't use dump files, what do you do? Load data row by row from within your test's setups? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.
Re: more testing questions
On Mon, Jul 8, 2013 at 4:14 PM, Larry Martellwrote: > It appesars it's trying to add a row to django_content_type and it's > already there. I tried not loading the fixture for django_content_type > but I got the same error. These fixture files contain data I dumped > from my real db, so I know it's good. Googling this I found a few > posts with people having the same problem, but they are all a few > years old. People 'solved' this by using an external package > (django-fixture-magic) or excluding the auth tables or hand > re-ordering the records in the fixtures file. None of these seem like > good solutions to me. Is this still a known problem? Shouldn't I be > able to load data generated from a dump? rigth, it's quite messy. i usually don't use dump files. (the mess, they don't do so 'clean' tests). check 'natural keys' (https://docs.djangoproject.com/en/1.5/topics/serialization/#natural-keys) for a ways to get more robust fixtures -- Javier -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.
Re: more testing questions
On Mon, Jul 8, 2013 at 12:06 PM, Larry Martellwrote: > Still working on getting my tests to run. I have 2 issues right now: > > 1) I want to load data from fixture files. In this case I am trying to > load auth data to test the logins. I have this in my test code: > > from django.test import TestCase > from django.contrib.auth.models import User, Permission > > class MeasDataTest(TestCase): > > fixtures = ['auth_user', 'auth_permission'] > > The auth_user and auth_permission files are in my apps fixtures dir > (which is a subdir of where the models.py file is). But when run the > test, it does not pick these up. What am I doing wrong here? I figured out what the problem is here. My fixture files did not have any extension on the file names. Once I renamed them to auth_user.json they got picked up. But now I'm having a problem loading then. I changed fixtures to: fixtures = ['django_content_type', 'auth_user', 'auth_permission'' and it loads django_content_type and auth_user, but it fails on auth_permission with: IntegrityError: Could not load auth.Permission(pk=151): (1062, "Duplicate entry '2-add_group' for key 'content_type_id'") It appesars it's trying to add a row to django_content_type and it's already there. I tried not loading the fixture for django_content_type but I got the same error. These fixture files contain data I dumped from my real db, so I know it's good. Googling this I found a few posts with people having the same problem, but they are all a few years old. People 'solved' this by using an external package (django-fixture-magic) or excluding the auth tables or hand re-ordering the records in the fixtures file. None of these seem like good solutions to me. Is this still a known problem? Shouldn't I be able to load data generated from a dump? > > 2) We have a stand alone program that loads data to the db. It's a > django program in that it picks up the apps settings and uses the > models and django API, but it's stand along in that it runs from cron > and not from a web request. I want to run this from my tests, so I'm > invoking it from my test class using subprocess.Popen. I would think > it would use the test's environment and update the test db. But it > does not do that, but neither does it update the 'real' database. It > gives all indications of working though. I'm going to set a breakpoint > in it and see if I can tell more about what it's doing, but should I > expect an externally invoked script like this to hit the test db? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.
more testing questions
Still working on getting my tests to run. I have 2 issues right now: 1) I want to load data from fixture files. In this case I am trying to load auth data to test the logins. I have this in my test code: from django.test import TestCase from django.contrib.auth.models import User, Permission class MeasDataTest(TestCase): fixtures = ['auth_user', 'auth_permission'] The auth_user and auth_permission files are in my apps fixtures dir (which is a subdir of where the models.py file is). But when run the test, it does not pick these up. What am I doing wrong here? 2) We have a stand alone program that loads data to the db. It's a django program in that it picks up the apps settings and uses the models and django API, but it's stand along in that it runs from cron and not from a web request. I want to run this from my tests, so I'm invoking it from my test class using subprocess.Popen. I would think it would use the test's environment and update the test db. But it does not do that, but neither does it update the 'real' database. It gives all indications of working though. I'm going to set a breakpoint in it and see if I can tell more about what it's doing, but should I expect an externally invoked script like this to hit the test db? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.