django-testing

Using coverage, how do I test this line?

流过昼夜 提交于 2019-12-03 06:10:32
I have a simple test: class ModelTests(TestCase): def test_method(self): instance = Activity(title="Test") self.assertEqual(instance.get_approved_member_count(), 0) My problem is that coverage still shows get_approved_member_count line as NOT tested: How do I satisfy the above for coverage? To run the tests I'm using Django Nose with Coverage: TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' NOSE_ARGS = [ '--with-coverage', '--cover-html', '--cover-package=apps.users,apps.activities', ] Console: python manage.py test /Users/user/Documents/workspace/api/env/lib/python3.4/importlib/_bootstrap.py

difference between django.test.TestCase vs unittest vs django.utils.unittest.TestCase

↘锁芯ラ 提交于 2019-12-03 04:57:31
I am still using Django 1.2.1, and I think with the newer Django we don't import unittest and then do unittest.TestCase . Illustration import unittest class TestThis(unittest.TestCase): from django.utils.unittest import TestCase class TestThis(TestCase): from django.test import TestCase class TestThis(TestCase): According to PyCon2011 talk , the second one is slightly more efficient. Here is the diagram showing the relations: So django.utils.unittest and django.test inherit from either unittest or unittest2 . I am not sure if the following is correct or not. Please help editing. ______________

Writing test cases for django models

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 04:09:10
问题 Half way through my current project, after suffering the pain of spending uncountable minutes on debugging, I have decided to adopt TDD. To start, I am planning to write a set of unit tests for each existing models. But for models that only have attributes defined (ie. no additional methods/properties) I am not sure what I need to test nor how. class Product(models.Model): name = models.CharField(max_length=50) description = models.TextField(default='', blank=True) retails = models

Testing Django apps that use South migrations

前提是你 提交于 2019-12-03 03:38:11
问题 I'm trying to create some Functional tests for a Django app that uses South migrations. Eventually, I will also be creating Twill tests. When I try to run the existing tests, the test database is not created successfully because of a problem with the South migrations. ( Fails @ 7th of 58 migrations ) It would seem that for the purpose of testing, it's better to build the test database from the Django models, like a syncdb would, than from South. How do I set up the Django test suite to build

Testing email sending

China☆狼群 提交于 2019-12-03 03:01:30
问题 Any tips on testing email sending? Other than maybe creating a gmail account, especially for receiving those emails? I would like to, maybe, store the emails locally, within a folder as they are sent. 回答1: You can use a file backend for sending emails which is a very handy solution for development and testing; emails are not sent but stored in a folder you can specify! 回答2: Django test framework has some built in helpers to aid you with testing e-mail service. Example from docs (short version

Running django tests with sqlite

流过昼夜 提交于 2019-12-02 21:57:09
I use Postgres for production and development, but I'd like to use sqlite to run some tests. I don't see an easy way to configure one engine for tests and another for dev / production. Am I missing something? shanyu Append the following lines in your settings: import sys if 'test' in sys.argv or 'test_coverage' in sys.argv: #Covers regular testing and django-coverage DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3' Make sure your actual database setting comes before them. This is not a direct answer, but yes, you are missing one big problem - testing a Postgres app on SQLite is

Django test RequestFactory vs Client

半世苍凉 提交于 2019-12-02 21:41:28
I am trying to decide whether I should use Django's Client or RequestFactory to test my views. I am creating my server using DjangoRESTFramework and it's really simple, so far: class SimpleModelList(generics.ListCreateAPIView): """ Retrieve list of all route_areas or create a new one. """ queryset = SimpleModel.objects.all() serializer_class = SimpleModelSerializer filter_backends = (IsOwnerFilterBackend,) def perform_create(self, serializer): serializer.save(owner=self.request.user) What are the differences between testing with Django's Client and RequestFactory and which approach is more

Problems using User model in django unit tests

我是研究僧i 提交于 2019-12-02 20:30:54
I have the following django test case that is giving me errors: class MyTesting(unittest.TestCase): def setUp(self): self.u1 = User.objects.create(username='user1') self.up1 = UserProfile.objects.create(user=self.u1) def testA(self): ... def testB(self): ... When I run my tests, testA will pass sucessfully but before testB starts, I get the following error: IntegrityError: column username is not unique It's clear that it is trying to create self.u1 before each test case and finding that it already exists in the Database. How do I get it to properly clean up after each test case so that

Wagtail unit testing: Adding child pages converts them to base type

◇◆丶佛笑我妖孽 提交于 2019-12-02 18:38:03
问题 Trying to create some unit tests for Wagtail and running into the following problem: >> root = FrontPage.add_root(instance=FrontPageFactory.build()) >> root <FrontPage: article0> >> root.add_child(instance=ArticlePageFactory.build()) <ArticlePage: article1> >> root.get_tree() <PageQuerySet [<Page: article0>, <Page: article1>]> "article0" goes from being type ArticlePage to type Page in the page tree. Is this Page object a reference to the ArticlePage and there's a method I'm not aware of to

Writing test cases for django models

假装没事ソ 提交于 2019-12-02 17:27:40
Half way through my current project, after suffering the pain of spending uncountable minutes on debugging, I have decided to adopt TDD. To start, I am planning to write a set of unit tests for each existing models. But for models that only have attributes defined (ie. no additional methods/properties) I am not sure what I need to test nor how. class Product(models.Model): name = models.CharField(max_length=50) description = models.TextField(default='', blank=True) retails = models.ManyToManyField(Retail, verbose_name='Retail stores that carry the product') manufacturer = models.ForeignKey