[3] | 1 | import testlib |
---|
| 2 | import os, unittest, random |
---|
| 3 | from django.test import utils |
---|
| 4 | from django.db import connection |
---|
| 5 | from django.conf import settings |
---|
| 6 | from genetrack import conf, util, logger |
---|
| 7 | from genetrack.server.scripts import initializer |
---|
| 8 | from genetrack.server.web import html |
---|
| 9 | from django.contrib.auth.models import User |
---|
| 10 | from django.core.files import File |
---|
| 11 | |
---|
| 12 | class AuthorizeTest( unittest.TestCase ): |
---|
| 13 | """ |
---|
| 14 | Tests the models |
---|
| 15 | """ |
---|
| 16 | def setUp(self): |
---|
| 17 | "Setting up the tests database for data insert" |
---|
| 18 | self.old_name = settings.DATABASE_NAME |
---|
| 19 | utils.setup_test_environment() |
---|
| 20 | connection.creation.create_test_db(verbosity=0, autoclobber=True) |
---|
| 21 | options = util.Params(test_mode=True, delete_everything=False, flush=False, verbosity=0) |
---|
| 22 | fname = conf.testdata('test-users.csv') |
---|
| 23 | initializer.load_users(fname, options) |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | def tearDown(self): |
---|
| 27 | "Tearing down the database after test" |
---|
| 28 | connection.creation.destroy_test_db(self.old_name, 0) |
---|
| 29 | utils.teardown_test_environment() |
---|
| 30 | |
---|
| 31 | def test_data_creation(self): |
---|
| 32 | """ |
---|
| 33 | Create datasets |
---|
| 34 | """ |
---|
| 35 | |
---|
| 36 | # it seems that importing it earlier messes up the test database setup |
---|
| 37 | from genetrack.server.web import authorize |
---|
| 38 | |
---|
| 39 | john = User.objects.get(username='johndoe') |
---|
| 40 | project = authorize.create_project(user=john, name="Test project") |
---|
| 41 | stream = File( open(conf.testdata('test-users.csv')) ) |
---|
| 42 | data = authorize.create_data(user=john, pid=project.id, stream=stream, name="Test data") |
---|
| 43 | |
---|
| 44 | # project counts update |
---|
| 45 | project = authorize.get_project(user=john, pid=project.id) |
---|
| 46 | self.assertEqual(project.data_count, 1) |
---|
| 47 | |
---|
| 48 | # testing data deletion |
---|
| 49 | authorize.delete_data(user=john, pid=project.id, dids=[data.id]) |
---|
| 50 | project = authorize.get_project(user=john, pid=project.id) |
---|
| 51 | self.assertEqual(project.data_count, 0) |
---|
| 52 | |
---|
| 53 | def test_two(self): |
---|
| 54 | pass |
---|
| 55 | |
---|
| 56 | def get_suite(): |
---|
| 57 | "Returns the testsuite" |
---|
| 58 | tests = [ |
---|
| 59 | AuthorizeTest, |
---|
| 60 | ] |
---|
| 61 | |
---|
| 62 | return testlib.make_suite( tests ) |
---|
| 63 | |
---|
| 64 | if __name__ == '__main__': |
---|
| 65 | suite = get_suite() |
---|
| 66 | logger.disable('DEBUG') |
---|
| 67 | unittest.TextTestRunner(verbosity=2).run( suite ) |
---|