pytest-django

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 to run tests in django using database with data?

我与影子孤独终老i 提交于 2019-12-05 07:19:26
I want to test my views using data from postgres localhost database (with already loaded data). I'm using tox with pytest and pytest-django. My question: How to set up / connect to local database to get all the data model schema and data itself? Or maybe it is better to use factory_boy? Or to load whole data from .sql script (if yes, how)? Example of my test: def test_foo_view(custom_client_login): response = custom_client_login.get('/foo/bar/123/') assert response.status_code == 200 assert 'Transaction no. 123' in response.content But instead of getting status code 200 I get 404, which points

django-pytest setup_method database issue

喜欢而已 提交于 2019-12-05 06:08:14
I have the following set up on Ubuntu 14.04: python 2.7.6 django 1.7 [though I reproduced the same behaviour with django 1.9 too] pytest-django 2.8.0 [also tested with 2.9.1] pytest 2.7.2 [also tested with 2.8.3] And the following test code: import pytest from django.db import connection import settings from pollsapp.models import Question original_db_name = settings.DATABASES["default"]["NAME"] @pytest.mark.django_db class TestExperiment(object): def setup_method(self, method): # it's not using the "test_" + DATABASE_NAME ! assert connection.settings_dict["NAME"] == \ settings.DATABASES[

How to test a Django model with pytest?

一世执手 提交于 2019-12-03 17:47:31
问题 I am getting started with pytest. I have configured pytest, anyway I couldn't found a resource on Django specific testing with pytest. How do I test a model with pytest_django ? I have already asked a question on unittesting, how do I efficiently test this Django model? I want know how the same tests can be written with py.test? adding below the model and the tests written in unittest. the model under test is, class User(AbstractBaseUser, PermissionsMixin): username = models.CharField(max

How to test a Django model with pytest?

一笑奈何 提交于 2019-12-03 06:33:32
I am getting started with pytest. I have configured pytest, anyway I couldn't found a resource on Django specific testing with pytest. How do I test a model with pytest_django ? I have already asked a question on unittesting, how do I efficiently test this Django model? I want know how the same tests can be written with py.test? adding below the model and the tests written in unittest. the model under test is, class User(AbstractBaseUser, PermissionsMixin): username = models.CharField(max_length=25, unique=True, error_messages={ 'unique': 'The username is taken' }) first_name = models