Beispiel #1
0
    def test_main(self):
        self.mox.StubOutWithMock(create_dev_db.getpass, 'getuser')
        self.mox.StubOutWithMock(create_dev_db, 'create_dev_db')
        create_dev_db.getpass.getuser().AndReturn('foo')

        create_dev_db.create_dev_db('foo')

        self.mox.ReplayAll()
        create_dev_db.main()
        self.mox.VerifyAll()
Beispiel #2
0
    def test_main(self):
        self.mox.StubOutWithMock(create_dev_db.getpass, 'getuser')
        self.mox.StubOutWithMock(create_dev_db, 'create_dev_db')
        create_dev_db.getpass.getuser().AndReturn('foo')

        create_dev_db.create_dev_db('foo')

        self.mox.ReplayAll()
        create_dev_db.main()
        self.mox.VerifyAll()
Beispiel #3
0
    def test_fail_to_create_db(self):
        self.mox.StubOutWithMock(create_dev_db.MySQLdb, 'connect')
        create_dev_db.DB_PASSWORD = '******'

        db = self.mox.CreateMockAnything()
        create_dev_db.MySQLdb.connect(user='******',
                                      passwd='bar').AndReturn(db)

        cursor = self.mox.CreateMockAnything()
        db.cursor().AndReturn(cursor)
        cursor.execute('CREATE DATABASE IF NOT EXISTS quark_dev_foo'
                       ' CHARACTER SET utf8'
                       ' COLLATE utf8_unicode_ci')
        cursor.close()
        db.commit()

        ex_cursor = self.mox.CreateMockAnything()
        db.cursor().AndReturn(ex_cursor)
        ex_cursor.execute(
            ('SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA'
             ' WHERE SCHEMA_NAME = %s'), ['quark_dev_foo'])
        ex_cursor.fetchone().AndReturn(None)
        ex_cursor.close()

        db.close()

        self.mox.ReplayAll()
        self.assertFalse(create_dev_db.create_dev_db('foo'))
        self.mox.VerifyAll()
Beispiel #4
0
    def test_fail_to_create_db(self):
        self.mox.StubOutWithMock(create_dev_db.MySQLdb, 'connect')
        create_dev_db.DB_PASSWORD = '******'

        db = self.mox.CreateMockAnything()
        create_dev_db.MySQLdb.connect(
            user='******', passwd='bar').AndReturn(db)

        cursor = self.mox.CreateMockAnything()
        db.cursor().AndReturn(cursor)
        cursor.execute('CREATE DATABASE IF NOT EXISTS quark_dev_foo'
                       ' CHARACTER SET utf8'
                       ' COLLATE utf8_unicode_ci')
        cursor.close()
        db.commit()

        ex_cursor = self.mox.CreateMockAnything()
        db.cursor().AndReturn(ex_cursor)
        ex_cursor.execute(
            ('SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA'
             ' WHERE SCHEMA_NAME = %s'), ['quark_dev_foo'])
        ex_cursor.fetchone().AndReturn(None)
        ex_cursor.close()

        db.close()

        self.mox.ReplayAll()
        self.assertFalse(create_dev_db.create_dev_db('foo'))
        self.mox.VerifyAll()
Beispiel #5
0
 def test_fail_bad_db_name(self):
     self.assertFalse(create_dev_db.create_dev_db('foo!??!'))
Beispiel #6
0
 def test_fail_bad_db_name(self):
     self.assertFalse(create_dev_db.create_dev_db('foo!??!'))