Exemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        super(DatabaseWrapper, self).__init__(*args, **kwargs)

        self.features = DatabaseFeatures(self)
        self.ops = DatabaseOperations(self)
        self.client = DatabaseClient(self)
        self.creation = DatabaseCreation(self)
        self.introspection = DatabaseIntrospection(self)
        self.validation = BaseDatabaseValidation(self)
Exemplo n.º 2
0
 def setUp(self):
     setup_test_environment()
     self.b = DatabaseCreation(django.db.connection)
     self.test_db = self.b.create_test_db(autoclobber=True)
Exemplo n.º 3
0
class TestMultiTenancy(unittest.TestCase):
    def setUp(self):
        setup_test_environment()
        self.b = DatabaseCreation(django.db.connection)
        self.test_db = self.b.create_test_db(autoclobber=True)

    def tearDown(self):
        teardown_test_environment()
        self.b.destroy_test_db(self.test_db)

    def test_should_create_organization_setting_with_document_store_on_create_organization(
            self):
        c = Client()
        reg_post = dict(
            email="*****@*****.**",
            first_name="first_name",
            last_name="last",
            organization_addressline1="x",
            organization_addressline2="y",
            organization_city="city",
            organization_country="country",
            organization_name="TEST_ORG_NAME",
            organization_office_phone="",
            organization_sector="PublicHealth",
            organization_state="state",
            organization_website="",
            organization_zipcode="zip",
            password1="a",
            password2="a",
            title="",
        )
        response = c.post('/register/', reg_post)
        self.assertIsNotNone(response)

        user = User.objects.get(email='*****@*****.**')
        profile = RegistrationProfile.objects.get(user=user)
        activation_key = profile.activation_key
        response = c.post('/activate/%s/' % activation_key)
        self.assertIsNotNone(response)

        organization = Organization.objects.get(name="TEST_ORG_NAME")
        organization_settings = OrganizationSetting.objects.get(
            organization=organization)
        organization_db_name = organization_settings.document_store

        expected_org_db_name = ("hni_test_org_name_%s" %
                                (organization.org_id, )).lower()
        self.assertEqual(expected_org_db_name, organization_db_name)

        couch_server = couchdb.client.Server(settings.COUCH_DB_SERVER)

        org_db = None
        try:
            org_db = couch_server[organization_db_name]
        except Exception:
            self.fail("Organization database %s not created" %
                      (organization_db_name, ))
        self.assertIsNotNone(org_db)

        manager = get_db_manager(server=couch_server,
                                 database=organization_db_name)
        test_reporter = reporter.find_reporter_entity(
            manager, TEST_REPORTER_MOBILE_NUMBER)
        self.assertIsNotNone(test_reporter)

        #clean up the org db
        del couch_server[organization_db_name]
Exemplo n.º 4
0
 def setUp(self):
     setup_test_environment()
     self.b = DatabaseCreation(django.db.connection)
     self.test_db = self.b.create_test_db(autoclobber=True)
Exemplo n.º 5
0
class TestMultiTenancy(unittest.TestCase):
    def setUp(self):
        setup_test_environment()
        self.b = DatabaseCreation(django.db.connection)
        self.test_db = self.b.create_test_db(autoclobber=True)

    def tearDown(self):
        teardown_test_environment()
        self.b.destroy_test_db(self.test_db)

    def test_should_create_organization_setting_with_document_store_on_create_organization(self):
        c = Client()
        reg_post = dict(
            email="*****@*****.**",
            first_name="first_name",
            last_name="last",
            organization_addressline1="x",
            organization_addressline2="y",
            organization_city="city",
            organization_country="country",
            organization_name="TEST_ORG_NAME",
            organization_office_phone="",
            organization_sector="PublicHealth",
            organization_state="state",
            organization_website="",
            organization_zipcode="zip",
            password1="a",
            password2="a",
            title="",
            )
        response = c.post('/register/', reg_post)
        self.assertIsNotNone(response)

        user = User.objects.get(email='*****@*****.**')
        profile = RegistrationProfile.objects.get(user=user)
        activation_key = profile.activation_key
        response = c.post('/activate/%s/' % activation_key)
        self.assertIsNotNone(response)

        organization = Organization.objects.get(name="TEST_ORG_NAME")
        organization_settings = OrganizationSetting.objects.get(organization=organization)
        organization_db_name = organization_settings.document_store

        expected_org_db_name = ("hni_test_org_name_%s" % (organization.org_id,)).lower()
        self.assertEqual(expected_org_db_name, organization_db_name)

        couch_server = couchdb.client.Server(settings.COUCH_DB_SERVER)

        org_db = None
        try:
            org_db = couch_server[organization_db_name]
        except Exception:
            self.fail("Organization database %s not created" % (organization_db_name,))
        self.assertIsNotNone(org_db)

        manager = get_db_manager(server=couch_server, database=organization_db_name)
        test_reporter = reporter.find_reporter_entity(manager, TEST_REPORTER_MOBILE_NUMBER)
        self.assertIsNotNone(test_reporter)

        #clean up the org db
        del couch_server[organization_db_name]