using unittest.skip with django-jenkins - django

I have added #unittest.skip decorator for few of my test methods. It works as expected while running with python manage.py test --settings=PATH_TO_SETTING
But it does not work with python manage.py jenkins --settings=PATH_TO_SETTING
I read that I need to add JENKINS_TEST_RUNNER to settings file but I am not aware of how to add that class.
How can I make it work with jenkins ?

Adding the JENKINS_TEST_RUNNER is not solving the problem.
it can be added as
JENKINS_TEST_RUNNER = 'django_jenkins.runner.CITestSuiteRunner'
I solved the problem by setting the name attribute explicitly on the classes in whose test functions i am using unittest.skip

Related

Django Migrations: How to mark a migration as a parent of other apps migrations?

I'm trying to create a new Django application whose migrations depend on other apps migrations. I want migrations on the other apps to have a dependency on migrations on the new application, even when the new application doesn't reference at all the models at the other apps.
For example, let's say I have application A (an existing app) and application B (my new application):
A has a migration called A.0001, and B has a migration called B.0001 which depends on A.0001. I now make a change at A.MyModel, so I need to run python manage.py makemigrations to generate a new migration A.0002.
What I want is A.0002 to automatically depend on B.0001.
How can I specify this dependency on new migrations in A without having to do it by hand each time I modify a model in A?
I tried to add empty modifications of models in A at the migration B.0001, but I haven't got it to work and it looks very hacky to me.
I found a solution that doesn't exactly solve what I asked, but can be a workaround for some people, so I will post it here.
There is an undocumented field of the django.Migration class, called run_before, that works just like an inverse dependencies.
A.0002 will depend on B.0001 if I simply define run_before = [ A.0002 ] at B.0001.

Rails 4 plugin with my models, where do I put migrations?

I created a plugin (gem) with my models that I'm using in two other apps.
I placed models to /lib folder and my app is working all good. But my question is where do I put future migrations? And how do I generate migrations inside the gem? Or do I have to write them manually?
To answer your first question the future migrations can be stored in /lib/db/migrate/ folder
Coming to the second part
Rails does not include any built-in support for calling migrations from plugins.But still you can run migrations by different methods
1.Create a Custom Rake Task
The first method is by using a rake task
Consider an example
namespace :db do
namespace :migrate do
description = "Migrate the database through scripts in vendor/plugins/pluginname/lib/db/migrate"
description << "and update db/schema.rb by invoking db:schema:dump."
description << "Target specific version with VERSION=x. Turn off output with VERBOSE=false."
desc description
task :pluginame => :environment do
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
ActiveRecord::Migrator.migrate("vendor/plugins/pluginname/lib/db/migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
end
end
end
2. Call Migrations directly
Dir.glob(File.join(File.dirname(__FILE__), "db", "migrate", "*")).each do |file|
require file
end
3. Migration Generator
These methods apart you can create your own migration generator.
Generating migrations has several advantages over other methods. Namely, you can allow other developers to more easily customize the migration. The flow looks like this:
call your script/generate script and pass in whatever options they
need
examine the generated migration, adding/removing columns or other
options as necessary
Providing the generator template example of railties gem
https://github.com/rails/rails/blob/master/railties/lib/rails/generators/migration.rb
Please Refer http://guides.rubyonrails.org/v2.3.11/plugins.html#migrations
for more details

How to run a single test or single TestCase with django-nose?

With Django's normal test runner, you can drill down to run tests in a specific app, a specific subclass of TestCase, or a specific test within a specific subclass of TestCase.
E.g.:
./manage.py test myapp.MyTestCase.test_something
However, django-nose doesn't appear to support anything beyond testing a specific app. How do I replicate the last two behaviors?
Nose supports the following syntax (note : between test script name and test class name):
./manage.py test myapp.tests.test_script:MyTestCase.test_method
The correct answer is ./manage.py test myapp/tests/test_script:MyTestCase.test_method.
Using dots in the relative path did not work for me, but slashes did.

Django Unit Test fails project-wide but passes app-wide

I'm using Django 1.4 with Python 2.7 on Ubuntu 12.10.
I have a project with several apps and dozens of unit tests. We've recently run into a little issue using the #override_settings decorator.
Here is some code:
#override_settings(MEDIA_URL='/test/media/')
def test_get_content_dict(self):
self.assertEqual(
self.offer.get_content_dict(),
{ 'some stuff': some stuff }
When tests are run at the app level everything passes.
python manage.py test my_app --settings=proton.settings.test
But when we run at the project level it fails.
python manage.py test --settings=proton.settings.test
It's failing due to some stuff using /test/media but the model method offer.get_contect_dict() using /media, which is our actual MEDIA_URL.
We can change the MEDIA_URL in our settings/test.py file, but that would require all tests to use /test/media (which might be a good idea anyway).
Clearly the problem is in Django's core.files.storage.FileSystemStorage.__init__() - it sets the base_url earlier in the test suite but does not re-instantiate the object after each test (for obvious reasons) so the #override_settings doesn't actually do anything.
Is this a bug or is this working as intended? Any suggestions to an elegant solution other than forcing all unit tests to use /test/media by setting our MEDIA_URL constant in our settings/test.py to /test/media?

Invoking django tests in subdirectories

I recently split up an app into subdirectories. For example, I had a "shop" app, and I split it up into shop/foo, shop/bar, shop/baz subdirectories, treating each one as a separate app, so my INSTALLED_APPS now looks like:
"shop",
"shop.foo",
"shop.bar",
"shop.baz",
...
I want to be able to run the tests in shop/foo/tests.py by doing:
python manage.py test shop.foo
However, if I do that, I get the error:
ValueError: Test label 'shop.foo' does not refer to a test
On the other hand, I can run the tests by doing this:
python manage.py test foo
Why is this happening, and what can I change so that I can run the tests as "shop.foo" instead of "foo"?
This is because Django expects the arguments to test command to be of the format:
app_label[.TestCase[.test_method]]
There is no way of doing this with the stock test runner (see, Carl Meyers comment). If everything goes well, this should be fixed in Django 1.5, but in the meantime you can use an alternate runner which accepts full module paths: django-discovery-runner.
django-discover-runner has been made part of Django 1.6.. :)
For Version <1.6 , it can be used as a third party app.