django-testing

running all tests post django 1.6

久未见 提交于 2019-12-08 16:00:32
问题 In django 1.5 and earlier, running python manage.py test would, by default, run all tests in a project (including all those in django.contrib). Subsequent to version 1.6, the default behaviour is to run all the tests in the current directory. What is the best way (v 1.6) to run all tests, either with or without the django.contrib tests? 回答1: Django 1.6 changed the default test runner to: TEST_RUNNER = 'django.test.runner.DiscoverRunner' You can get the old behaviour back by adding to your

How do I test a Django CreateView?

烈酒焚心 提交于 2019-12-07 17:38:40
问题 I want to practice testing on Django, and I have a CreateView I want to test. The view allows me to create a new post and I want to check if it can find posts without a publication date, but first I'm testing posts with published date just to get used to syntax. This is what I have: import datetime from django.test import TestCase from django.utils import timezone from django.urls import reverse from .models import Post, Comment # Create your tests here. class PostListViewTest(TestCase): def

Django: Selenium- stale element reference on browse

蹲街弑〆低调 提交于 2019-12-07 17:00:58
问题 I am using Chrome webdriver, because the Firefox webdriver seems to have issues on my Windows PC. My Django Functional Tests were working just fine before I went on vacation, but now they are throwing all kinds of errors. Sometimes, when trying to find an element on a page I get: selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document Other times, an attempt to verify the url fails, because Selenium seems to be

Error in django unittest while loading a fixture

房东的猫 提交于 2019-12-07 07:18:03
问题 I am making unittests for a django app. I need some data in the database for my tests so I am using a json fixture. I have two fixtures: for users and it works ok. for some webpages The fixture 2 cause the following error: Problem installing fixture 'C:\Users\luc\Dev\Hg\mnl-adminpub\website\fixtures\website-unittest.json': Traceback (most recent call last): File "C:\Python26\lib\site-packages\django\core\management\commands\loaddata.py", line 169, in handle obj.save(using=using) File "C:

Models inside tests - Django 1.7 issue

旧时模样 提交于 2019-12-06 19:27:06
问题 I'm trying to port my project to use Django 1.7. Everything is fine except 1 thing. Models inside tests folders. Django 1.7 new migrations run migrate command internally. Before syncdb was ran. That means if a model is not included in migrations - it won't be populated to DB (and also to test DB). That's exactly what I'm experiencing right now. What I do is: In my /app/tests/models.py I have dummy model: class TestBaseImage(BaseImage): pass All it does is to inherit from an abstract BaseImage

How can I keep test data after Django tests complete?

╄→尐↘猪︶ㄣ 提交于 2019-12-06 18:09:45
问题 I am using Django 1.8 and the docs say to use --keepdb to save the test database. I am doing that and the database is there but every time I see it, it is empty and has no data in it. Is there any way that I can preserve that so that I can see what's in there? 回答1: All of your code is running within database transactions, which get rolled back at the end of each test. From the Django testing docs: Here is an example which subclasses from django.test.TestCase, which is a subclass of unittest

Django test tables are not being created

◇◆丶佛笑我妖孽 提交于 2019-12-06 13:50:23
I'm trying to write test cases for my django project but when I run "$ ./manage.py test" command its creating test database but its not creating any tables and I'm getting an error that table does't exists. Any suggestions are welcome. Here is my model which i have created through "./manage.py inspectdb > models.py" class MyCustomModel(models.Model): name = models.CharField(max_length=200) last_name = models.CharField(max_length=200) class Meta: managed = False db_table = 'MY_TABLE' Your table is unmanaged ( managed = False ) so it does not get created automatically during migration or testing

how do I efficiently test this Django model?

岁酱吖の 提交于 2019-12-06 12:06:45
I'm building an authentication system for a website, I don't have prior test experience with Django. I have written some basic tests. the model, class User(AbstractBaseUser, PermissionsMixin): username = models.CharField(max_length=25, unique=True, error_messages={ 'unique': 'The username is taken' }) first_name = models.CharField(max_length=60, blank=True, null=True) last_name = models.CharField(max_length=60, blank=True, null=True) email = models.EmailField(unique=True, db_index=True, error_messages={ 'unique': 'This email id is already registered!' }) is_active = models.BooleanField(default

can't change user permissions during unittest in django

旧巷老猫 提交于 2019-12-06 05:54:30
问题 I've finally decided to make some tests for my apps but I'm stuck on testing if a user can change another user (depends on the type of the user -- I use django-rules to be able to do logical permission checks, but this is not important) Here's the code I have so far class RulesAndPermissionsTests(TestCase): fixtures = ['auth_no_permissions.json', 'profiles.json', 'rules.json'] def setUp(self): self.c = Client() self.user = User.objects.get(username="estagiario") self.non_staff = User.objects

How do I test a Django CreateView?

安稳与你 提交于 2019-12-05 22:02:51
I want to practice testing on Django, and I have a CreateView I want to test. The view allows me to create a new post and I want to check if it can find posts without a publication date, but first I'm testing posts with published date just to get used to syntax. This is what I have: import datetime from django.test import TestCase from django.utils import timezone from django.urls import reverse from .models import Post, Comment # Create your tests here. class PostListViewTest(TestCase): def test_published_post(self): post = self.client.post('/post/compose/', {'author':"manualvarado22", 'title