python - How to make django test framework read from live database? -


I have a similar question here, but it has a different perspective: I have a dynamic app that can be used on data Indexes with queries; I would like to write unit tests for the search component of this app, and of course, I'll need the Django settings module and all the connections will be active with the database, so the test runner Joe Django is ideal. However , the Django testing framework creates an dummy database and I hate to dump all my data into a crop and then index it (tests always Will take for );

My data is not in danger because the test is done only by read database, so, how can it be obtained? -I am new to this whole unit test, so a new solution to write test runner I have read in similar questions, at least I do not reveal anything without some details. To read / test cases for Dzepians I actually found very interesting facts: Use the set up method for what these people do. Tests classes: They create an object and then use the update method for the indexer, so they have a document to effectively find and a way to write controlled query tests! For curiosity, the method looks something like this:

  def set up (self): p = person.objects.create (name = "Alex") for i category (self.num_entries ): Entry.objects.create (author = p, title = "entry with number% s"% i, text = "fubar" * i) Entry.indexer.update ()  

I think this will have to happen, but we have to remember that I am testing a little search engine here, so this solution can be a simple way; I can not come up with any objection, however, if you have any answers that will help define a strategy to check such webpages in general, it is more than welcome!

- I think that now I will settle for something like this (I wanted to test the latency of questions with a fully populated database, but I think I would later wear the bench

edit : Well, to be loyal to someone's solution to be interested, I went into the second problem: xapian index (As stated in the comment ). To solve this, I made a default test runner, which changed the production expanse index for a test index (a small, created with a management script). This runner is quite simple:

  Def custom_run_tests (test_labels, verbosity = 1, interactive = true, extra_tests = []): "" "set test index" "settings". CATEGORY_CLASSIFIER_DATA = Settings TEST_CLASSIFIER_DATA returned action (test_label, verbosity, interactive, additional_tests)  

And, to use it, I've just added a setting:

  TEST_RUNNER = 'search .test.custom_run_tests'  

I removed the above approach (making the document in the set up) for reasons of performance and readability: to check the database, Requires a good amount of documents with text (One paragraph or two), so I ended up building a stability for that (I used a management command that documents were created in the actual database, they were sorted - writing them in a file - and then ' Deleted '). So, finally, I did not read at Live DB at all, and instead used a test fixtures built with some laughing script and a custom runner, and it was not difficult :)


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -