I am currently trying to do some testing on django application, however info about testing on official documentation is quite small(or probably I didn't search enough). Here is my test (its start actually)
from django.test import TestCase
from django.contrib.auth.models import User
from rest_framework.test import APIRequestFactory, force_authenticate
class PassengerEditTest(TestCase):
factory = APIRequestFactory()
PASSENGER_DATA = {
"id": 18,
"given_name": "CHyna",
"surname": "Jake",
"birth_date": "1980-11-16",
"gender": 0,
"email": "chyna.jake25@gmail.com",
"phone": "87017777777",
"DOCO": "ololololo"
}
URL = '127.0.0.1:8000/api/v1/tickets/profile/passengers/'
# def setup(self):
# user = User.objects.get(username = 'admin')
#
# request = factory.post(self.URL, {'title': 'new idea'}, format='json')
def test_given_name(self):
# print "Test given_name start"
user = User.objects.get(username='chynajake')
request = self.factory.post(self.URL, self.PASSENGER_DATA, format='json')
force_authenticate(request, user=self.user)
# print "Test given_name finish"
My problem is when I run on terminal:
./manage.py test -s path.to.test.PassengerEditTest
it creates a new clean test database, but for this test I need db with actual data from my database. How can I make it so it also inserts all records from actual db not only tables? I am using postgresql
P.S. I am very newbie at writing test, please suggest some convention, resources and tutorials to learn from.