Skip to content

Commit

Permalink
v1.6.5 fix mock data bug and event api bug(#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoye authored Apr 10, 2019
1 parent 360d24c commit ae3c799
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
19 changes: 13 additions & 6 deletions lyrebird/db/database_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,19 @@ def session(self):

def get_event(self, channel_rules, offset=0, limit=20):
session = self._scoped_session()
result = session.query(Event) \
.order_by(Event.id.desc()) \
.filter(Event.channel.in_(channel_rules)) \
.offset(offset) \
.limit(limit) \
.all()
if len(channel_rules) == 0:
result = session.query(Event) \
.order_by(Event.id.desc()) \
.offset(offset) \
.limit(limit) \
.all()
else:
result = session.query(Event) \
.order_by(Event.id.desc()) \
.filter(Event.channel.in_(channel_rules)) \
.offset(offset) \
.limit(limit) \
.all()
self._scoped_session.remove()
return result

Expand Down
5 changes: 4 additions & 1 deletion lyrebird/mock/blueprints/apis/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ class Event(Resource):

def get(self, channel=None, page=0):
db = application.server['db']
events = db.get_event(channel.split('+'), offset=page*20)
channel_rules = []
if channel:
channel_rules = channel.split('+')
events = db.get_event(channel_rules, offset=page*20)
result = []
for event in events:
event_str = event.json()
Expand Down
10 changes: 6 additions & 4 deletions lyrebird/mock/blueprints/apis/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def get(self):
req_list = []
for item in all_items:
info = dict(
id=item['id'],
id=item['id'],
size=item['size'],
duration=item['duration'],
duration=item['duration'],
start_time=item['start_time'],
request=dict(
url=item['request'].get('url'),
Expand All @@ -41,7 +41,7 @@ def get(self):
)if item.get('response') else {}
)
req_list.append(info)
def gen():
def gen():
yield json.dumps(req_list)
return context.make_streamed_response(gen)

Expand All @@ -66,11 +66,13 @@ def post(self):
activated_group = dm.groups.get(dm.activated_group_id)
if not activated_group:
return context.make_fail_response('Not activate any group')

flow_list = context.application.cache.items()
for flow in flow_list:
if flow['id'] in _ids:
data = activated_group.create_data(flow=flow)
data.save()

dm.router.switch_group(activated_group)

return context.make_ok_response()
2 changes: 1 addition & 1 deletion lyrebird/mock/blueprints/apis/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def delete(self, group_id=None, data_id=None):
return context.make_fail_response('Group not found')
ids = request.json.get('ids')
for data_id in ids:
_group.delete_data(data_id)
_group.delete_data(data_id)
return context.make_ok_response()


Expand Down
2 changes: 1 addition & 1 deletion lyrebird/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
IVERSION = (1, 6, 4)
IVERSION = (1, 6, 5)
VERSION = ".".join(str(i) for i in IVERSION)
LYREBIRD = "Lyrebird " + VERSION

0 comments on commit ae3c799

Please sign in to comment.