5
I’m doing an api test, which I pass a json it validates me if it came back all ok:
my base class:
# -*- coding: utf-8 -*-
# base.py
import os
import unittest
from app import initialize
from mock import mock
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from app import database
os.environ = {
my_variavels:
}
test_app = Flask(__name__)
test_app.config.from_object('app.config.TestingConfig')
database.AppRepository.db = SQLAlchemy(test_app)
class TestCase(unittest.TestCase):
mock = mock
user = initialize.web_app.test_client()
I believe that in this base file, should have the functions teardown, Setup etc..
json_gardener = {"id": "1",
"name": "Jamme"}
And I have the following function that makes the post in this case:
def test_post_gardener(self):
response = self.user.post('/gardeners', headers={'VALIDATION': 'XXXX'}, data=self.json_gardener)
self.assertEqual(response.status_code, 201)
So far everything ok, works perfectly, but when I run the second time obviously it will already exist the id in the bank and will give error.
My doubt the following, there is a way to upload a database to test and when finished running it disassemble?
How’s your test structure? I suggest you use unittest with a database like sqlite, and in unittest there is the tearDown() class method that runs at the end of the run, so you could have a routine to clean the bank. Could you give more details?
– Marlysson
I’m using the nosetest, bench postgres can tell me more of the teardown method, and how I start the bank?
– Guilherme Lima
If the bank is testing, you can’t just send one
DELETE
forAPI
and erase the record? Still testing the methodDELETE
application. Unless you use it to disable the guy, then it’s really better to have a test cleaning function that only givesTRUNCATE
in the same tables.– Daniel
Using classes or only isolated methods?
– Marlysson
class, after lunch I will detail better the question
– Guilherme Lima
Solved? The problem..
– Marlysson
Negative, I added more information to the question
– Guilherme Lima
Is it part of the rule to generate the id in the application layer and not with a sequential one in the database? Or you’re simply doing this in the Test Method Feed to be able to test the ID already having the value previously?
– Intruso