Skip to content

Commit

Permalink
升级 Django 3.1,增加 python 3.7、3.8 的CI
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyo committed Oct 31, 2020
1 parent 43541bd commit 4da9c5f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 58 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: python
python:
- "3.6.5"
- "3.7"
- "3.8"
before_install:
- sudo apt-get install unixodbc unixodbc-dev
services:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
[![Release](https://img.shields.io/github/release/hhyo/archery.svg)](https://github.com/hhyo/archery/releases/)
[![codecov](https://codecov.io/gh/hhyo/archery/branch/master/graph/badge.svg)](https://codecov.io/gh/hhyo/archery)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/94e8587e507f4565a1ea5ea21fd94c32)](https://app.codacy.com/app/hhyo/Archery?utm_source=github.com&utm_medium=referral&utm_content=hhyo/Archery&utm_campaign=Badge_Grade_Dashboard)
[![version](https://img.shields.io/badge/python-3.6.5-blue.svg)](https://www.python.org/downloads/release/python-365/)
[![version](https://img.shields.io/badge/django-2.2-brightgreen.svg)](https://docs.djangoproject.com/zh-hans/2.2/)
[![version](https://img.shields.io/pypi/pyversions/django)](https://img.shields.io/pypi/pyversions/django/)
[![version](https://img.shields.io/badge/django-3.1-brightgreen.svg)](https://docs.djangoproject.com/zh-hans/3.1/)
[![docker_pulls](https://img.shields.io/docker/pulls/hhyo/archery.svg)](https://hub.docker.com/r/hhyo/archery/)
[![HitCount](http://hits.dwyl.io/hhyo/hhyo/Archery.svg)](http://hits.dwyl.io/hhyo/hhyo/Archery)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](http://github.com/hhyo/archery/blob/master/LICENSE)
Expand Down
22 changes: 11 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Django==2.2.13
mysqlclient==1.4.6
requests==2.23.0
simplejson==3.17.0
Django==3.1.2
mysqlclient==2.0.1
requests==2.24.0
simplejson==3.17.2
mybatis_mapper2sql==0.1.9
django-auth-ldap==2.1.0
django-auth-ldap==2.2.0
python-dateutil==2.8.1
pymongo==3.10.1
psycopg2-binary==2.8.4
pymongo==3.11.0
psycopg2-binary==2.8.6
pymysql==0.9.3
mysql-replication==0.21
django-q==1.0.2
django-redis==4.11.0
mysql-replication==0.22
django-q==1.3.4
django-redis==4.12.1
pyodbc==4.0.30
gunicorn==20.0.4
pyecharts==1.7.1
Expand All @@ -19,7 +19,7 @@ cx-Oracle==7.3.0
supervisor==4.1.0
gevent==1.4.0
phoenixdb==0.7
django-mirage-field==1.0.1
django-mirage-field==1.1.6
schema-sync==0.9.7
parsedatetime==2.4
sshtunnel==0.1.5
7 changes: 4 additions & 3 deletions sql/engines/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def __next_const(self):
outstr += self.__cur_char()
self.__move_i()
if outstr.replace(" ", "") in (
"ObjectId", "newDate", "ISODate", "newISODate"): # ======类似的类型比较多还需单独处理,如int()等
"ObjectId", "newDate", "ISODate", "newISODate"): # ======类似的类型比较多还需单独处理,如int()等
data_type = outstr
for c in self.__remain_str():
outstr += c
Expand Down Expand Up @@ -330,9 +330,10 @@ def execute(self, db_name=None, sql=''):
if not exec_sql == '':
exec_sql = exec_sql.strip()
try:
start = time.clock()
# DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
start = time.perf_counter()
r = self.exec_cmd(exec_sql, db_name)
end = time.clock()
end = time.perf_counter()
line += 1
logger.debug("执行结果:" + r)
# 如果执行中有错误
Expand Down
30 changes: 7 additions & 23 deletions sql/engines/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ def test_query(self, mock_get_connection):
def test_query_check(self, mock_get_all_tables):
test_sql = """db.job.find().count()"""
mock_get_all_tables.return_value.rows = ("job")
check_result = self.engine.query_check('some_db',sql=test_sql)
check_result = self.engine.query_check('some_db', sql=test_sql)
mock_get_all_tables.assert_called_once()
self.assertEqual(False, check_result.get('bad_query'))

Expand All @@ -1602,7 +1602,6 @@ def test_get_all_tables(self, mock_get_connection):
mock_db.list_collection_names.assert_called_once()
self.assertEqual(table_list.rows, ['u', 'v', 'w'])


def test_filter_sql(self):
sql = """explain db.job.find().count()"""
check_result = self.engine.filter_sql(sql, 0)
Expand Down Expand Up @@ -1632,18 +1631,17 @@ def test_execute_check(self, mock_get_all_tables, mock_get_table_conut):
mock_get_all_tables.return_value.rows = ("job")
mock_get_table_conut.return_value = 1000
row = ReviewResult(id=1, errlevel=0,
stagestatus='Audit completed',
errormessage='检测通过',
affected_rows=1000,
sql=sql,
execute_time=0)
stagestatus='Audit completed',
errormessage='检测通过',
affected_rows=1000,
sql=sql,
execute_time=0)
check_result = self.engine.execute_check('some_db', sql)
self.assertEqual(check_result.rows[0].__dict__["errormessage"], row.__dict__["errormessage"])


@patch('sql.engines.mongo.MongoEngine.exec_cmd')
@patch('sql.engines.mongo.MongoEngine.get_master')
def test_execute(self,mock_get_master, mock_exec_cmd):
def test_execute(self, mock_get_master, mock_exec_cmd):
sql = '''db.job.find().createIndex({"skuId":1},{background:true})'''
mock_exec_cmd.return_value = '''{
"createdCollectionAutomatically" : false,
Expand All @@ -1655,17 +1653,3 @@ def test_execute(self,mock_get_master, mock_exec_cmd):
check_result = self.engine.execute("some_db", sql)
mock_get_master.assert_called_once()
self.assertEqual(check_result.rows[0].__dict__["errlevel"], 0)














22 changes: 3 additions & 19 deletions sql/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,18 +950,6 @@ def testSQLWithoutLimit(self, _priv_check, _get_engine, _user_instances):
self.assertEqual(r_json['data']['rows'], ['value'])
self.assertEqual(r_json['data']['column_list'], ['some'])

# 带 * 且不带 limit 的sql
sql_with_star = 'select * from some_table'
filtered_sql_with_star = 'select * from some_table limit {0};'.format(some_limit)
_get_engine.return_value.filter_sql.return_value = filtered_sql_with_star
_get_engine.return_value.query.reset_mock()
c.post('/query/', data={'instance_name': self.slave1.instance_name,
'sql_content': sql_with_star,
'db_name': some_db,
'limit_num': some_limit})
_get_engine.return_value.query.assert_called_once_with(
some_db, filtered_sql_with_star, some_limit, schema_name=None, tb_name=None, max_execution_time=60000)

@patch('sql.query.query_priv_check')
def testStarOptionOn(self, _priv_check):
c = Client()
Expand Down Expand Up @@ -1242,7 +1230,7 @@ def test_submit(self, _user_instances, _get_engine, _audit, _async_task):
_audit.add.return_value = None
_async_task.return_value = None
r = c.post('/autoreview/', data=data)
workflow_id = SqlWorkflow.objects.latest(field_name='id').id
workflow_id = SqlWorkflow.objects.order_by('-id').first().id
self.assertRedirects(r, f'/detail/{workflow_id}/', fetch_redirect_response=False)

@patch('sql.utils.workflow_audit.Audit.can_review')
Expand Down Expand Up @@ -1593,7 +1581,6 @@ def test_tuning(self):
r = self.client.post(path='/slowquery/optimize_sqltuning/', data=data)
self.assertEqual(json.loads(r.content), {'status': 1, 'msg': '你所在组未关联该实例!', 'data': []})


# 获取sys_parm
data['instance_name'] = 'test_instance'
data['option[]'] = 'sys_parm'
Expand Down Expand Up @@ -2107,9 +2094,8 @@ def test_binlog2sql(self, _subprocess):
r = self.client.post(path='/binlog/binlog2sql/', data=data)
self.assertEqual(json.loads(r.content), {"status": 0, "msg": "ok", "data": [{"sql": {}, "binlog_info": {}}]})

@patch('builtins.iter')
@patch('sql.plugins.plugin.subprocess')
def test_binlog2sql_file(self, _subprocess, _iter):
@patch('builtins.open')
def test_binlog2sql_file(self, _open):
"""
测试保存文件
:param _subprocess:
Expand All @@ -2131,8 +2117,6 @@ def test_binlog2sql_file(self, _subprocess, _iter):
"only_dml": "true",
"sql_type": "",
"instance": self.master}
_subprocess.Popen.return_value.stdout.return_value.readline.return_value = 'sql'
_iter.return_value = ''
r = binlog2sql_file(args=args, user=self.superuser)
self.assertEqual(self.superuser, r[0])

Expand Down

0 comments on commit 4da9c5f

Please sign in to comment.