Exemplo n.º 1
0
    def setUp(self):

        conn = pymysql.Connect(self.HOSTNAME, self.USER)
        conn.query('create database %s;' % self.DB_NAME)
        conn.close()

        uri = 'mysql+pymysql://%s@%s/%s' % (self.USER, self.HOSTNAME, self.DB_NAME)

        conf = DummyConfig(uri)

        session.initialize(conf)

        with session.Session() as sess:
            with sess.begin():
                tables.create_user(sess,
                                   id=DUMMY_ID,
                                   name=DUMMY_NAME)

            with sess.begin():
                tables.create_project(sess,
                                      id=DUMMY_ID,
                                      owner_id=DUMMY_ID,
                                      name=DUMMY_NAME,
                                      repository_uri='',
                                      repository_type='')

            with sess.begin():
                tables.create_file(sess,
                                   id=DUMMY_ID,
                                   project_id=DUMMY_ID,
                                   filepath=DUMMY_FILEPATH)
Exemplo n.º 2
0
    def test_file(self):
        u'''
        ファイルテーブルの定義テスト
        '''

        fpath = 'aaaa'

        with session.Session() as sess:
            with sess.begin():
                f = tables.create_file(sess,
                                       project_id=DUMMY_ID,
                                       filepath=fpath)

            results = tables.search_file(sess, project_id=DUMMY_ID,
                                         filepath=fpath)

            self.assertEqual(len(results), 1)


        # foreign key constraint
        with self.assertRaises(exceptions.IntegrityError):
            with session.Session() as sess:
                with sess.begin():
                    f = tables.create_file(sess,
                                           project_id=DUMMY_ID*100,
                                           filepath=fpath)

        # unique constraint
        with self.assertRaises(exceptions.IntegrityError):
            with session.Session() as sess:
                with sess.begin():
                    f = tables.create_file(sess,
                                           project_id=DUMMY_ID,
                                           filepath=fpath)