Ejemplo n.º 1
0
    def patch(self, user_id, activity_id):
        """
        修改报名信息
        """
        try:
            activity = Activity.get(id=activity_id)
        except Activity.DoesNotExist:
            raise ApiException(404, "活动不存在")

        self.joined_this_activity(activity_id, user_id)

        # 校验提交的参数是否合法, 1. 自定义参数; 2. 必填参数是否发生修改
        fields = {}
        fields.update(self.handle_extra_fields(activity=activity))
        fields.update(self.handler_required_fields(activity))

        if not fields:
            raise ApiException(400, "填写需要修改的属性和值")

        ActivityMember.update(**fields)\
            .where(ActivityMember.activity == activity_id,
                   ActivityMember.user == user_id)\
            .execute()

        self.set_status(204)
Ejemplo n.º 2
0
    def test_finish_activity(self):
        finish_activity(self.activity.id)

        try:
            finish_activity(self.activity.id)
        except Exception as e:
            pass

        finished_activity = Activity.get(id=self.activity.id)
        rich_team = Team.get(id=self.team.id)

        new_activity = Activity.get(parent_id=self.activity.id)

        self.assertEqual(self.online_paid_amount,
                         finished_activity.online_paid_amount)
        self.assertEqual(finished_activity.state,
                         Activity.ActivityState.finished)
        self.assertEqual(rich_team.credit, self.online_paid_amount)
        self.assertIsInstance(new_activity, Activity)
Ejemplo n.º 3
0
 def get(self, activity_id):
     activity = Activity.get(id=activity_id)
     query = ActivityMember.select()\
         .where(ActivityMember.activity == activity)
     query = self.filter_query(query)
     page = self.paginate_query(query)
     data = self.get_paginated_data(
         page=page,
         alias="members",
         serializer=self.get_serializer(activity)
     )
     self.write(data)
Ejemplo n.º 4
0
    def test_path_object(self):
        body = {'title': 'new title', 'need_name': True}
        url = self.OBJECT_PATH.format(activity_id=self.activity.id)

        self.auth_user = self.team_owner
        response = self.fetch(url, method='PATCH', body=json.dumps(body))
        self.assertEqual(403, response.code, response.body)

        self.auth_user = self.creator
        response = self.fetch(url, method='PATCH', body=json.dumps(body))
        self.assertEqual(200, response.code, response.body)

        updated = Activity.get(id=self.activity.id)
        self.assertEqual(updated.title, 'new title')
        self.assertTrue(updated.need_name is True)
Ejemplo n.º 5
0
 def get_activity(self, activity_id) -> Activity:
     try:
         activity = Activity.get(id=activity_id)
     except Activity.DoesNotExist:
         raise ApiException(400, "活动不存在")
     return activity