def test_optional_parameters(self, mocker):
     """should allow optional parameters"""
     mocker.return_value = MOCK_RESPONSE
     expires_at = int(time.time() + 3600)
     uploader.create_zip(
         tags=[TEST_TAG],
         expires_at=expires_at,
         allow_missing=True,
         skip_transformation_name=True,
     )
     params = mocker.call_args[0][2]
     self.assertEqual(params['expires_at'], expires_at)
     self.assertTrue(params['allow_missing'])
     self.assertTrue(params['skip_transformation_name'])
Exemple #2
0
 def test_optional_parameters(self, mocker):
     """should allow optional parameters"""
     mocker.return_value = MOCK_RESPONSE
     expires_at = int(time.time()+3600)
     uploader.create_zip(
         tags=[TEST_TAG],
         expires_at=expires_at,
         allow_missing=True,
         skip_transformation_name=True,
     )
     params = mocker.call_args[0][2]
     self.assertEqual(params['expires_at'], expires_at)
     self.assertTrue(params['allow_missing'])
     self.assertTrue(params['skip_transformation_name'])
 def test_create_archive(self):
     """should successfully generate an archive"""
     result = uploader.create_archive(tags=[TEST_TAG], target_tags=[TEST_TAG_RAW])
     self.assertEqual(2, result.get("file_count"))
     result2 = uploader.create_zip(
         tags=[TEST_TAG], transformations=[{"width": 0.5}, {"width": 2.0}], target_tags=[TEST_TAG_RAW])
     self.assertEqual(4, result2.get("file_count"))
Exemple #4
0
 def test_create_archive(self):
     """should successfully generate an archive"""
     result = uploader.create_archive(tags=[TEST_TAG], target_tags=[TEST_TAG_RAW])
     self.assertEqual(2, result.get("file_count"))
     result2 = uploader.create_zip(
         tags=[TEST_TAG], transformations=[{"width": 0.5}, {"width": 2.0}], target_tags=[TEST_TAG_RAW])
     self.assertEqual(4, result2.get("file_count"))
    def test_create_archive_multiple_resource_types(self, mocker):
        """should allow fully_qualified_public_ids"""

        mocker.return_value = MOCK_RESPONSE

        test_ids = [
            "image/upload/" + UNIQUE_TEST_ID,
            "video/upload/" + UNIQUE_TEST_ID,
            "raw/upload/" + UNIQUE_TEST_ID,
        ]
        uploader.create_zip(resource_type='auto',
                            fully_qualified_public_ids=test_ids)

        args, kargs = mocker.call_args

        self.assertTrue(get_uri(args).endswith('/auto/generate_archive'))
        self.assertEqual(test_ids,
                         get_list_param(mocker, 'fully_qualified_public_ids'))
Exemple #6
0
 def test_expires_at(self):
     """should successfully generate an archive"""
     expires_at = int(time.time()+3600)
     result = uploader.create_zip(tags=[TEST_TAG], expires_at=expires_at)
     self.assertEqual(2, result.get("file_count"))
Exemple #7
0
 def test_expires_at(self):
     """should successfully generate an archive"""
     expires_at = int(time.time() + 3600)
     result = uploader.create_zip(tags=[TEST_TAG], expires_at=expires_at)
     self.assertEqual(2, result.get("file_count"))
Exemple #8
0
def handle_text_message(event):
    text = event.message.text
    userID = event.source.user_id
    profile = line_bot_api.get_profile(event.source.user_id)
    keyword_match_output = []
    for x in rules_db.find():
        if x['keyword'] in text:
            keyword_match_output.append(x)
    try:
        groupID = event.source.group_id
    except:
        groupID = 'No groupID'
    log_info = {
        "userID": userID,
        "messageID": event.message.id,
        "text": text,
        "message_type": event.message.type,
        "source_type": event.source.type,
        "datetime": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
        "groupID": groupID
    }
    log_db.insert_one(log_info)

    if text == '報到':

        if isinstance(event.source, SourceGroup):
            user_data = users_db.find({}, {"userID": 1, "groupID": 1})
            user_match_output = userID in user_data
            group_match_output = groupID in user_data
            if user_match_output == False and group_match_output == False:
                user_info = {
                    "groupID":
                    groupID,
                    "userID":
                    userID,
                    "display_name":
                    profile.display_name,
                    "picture_url":
                    profile.picture_url,
                    "status_message":
                    profile.status_message,
                    "join_datetime":
                    time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
                }
                users_db.insert_one(user_info)
                line_bot_api.reply_message(event.reply_token, [
                    TextSendMessage(text=profile.display_name + '的資料登記完成!'),
                ])
            else:
                line_bot_api.reply_message(event.reply_token, [
                    TextSendMessage(text=profile.display_name + '的資料已經登記過了喔!'),
                ])
        else:
            line_bot_api.reply_message(
                event.reply_token, TextSendMessage(text="資料登記失敗,請聯絡老師或助教!!"))
    elif len(keyword_match_output) != 0:
        # function for exec
        def func():
            exec(rule_string)

        for rule_data in keyword_match_output:
            rule_string = str(rule_data['rule'])
            func()
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text='觸發規則!'))
    elif text == '下載報告':
        download_info = create_zip(tags='report', resource_type='raw')
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=download_info['url']))
    elif re.match(r'([0-9]+)-([^0-9]+)-(點名)', text) != None:
        rollcall_info = {
            "userID": userID,
            "messageID": event.message.id,
            "text": text,
            "message_type": event.message.type,
            "source_type": event.source.type,
            "datetime": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
            "groupID": groupID
        }
        rollcall_db.insert_one(rollcall_info)
        line_bot_api.reply_message(
            event.reply_token,
            TextSendMessage(text=profile.display_name + '點名成功!'))
    elif text == 'help':
        content = '功能說明:\n輸入「報到」進行群組內成員資料登記\n\n點名格式(數字-姓名-點名)\nex:10312345-王小明-點名\n\n上傳檔案網址:\nhttps://ai1082.herokuapp.com'
        line_bot_api.reply_message(event.reply_token,
                                   TextSendMessage(text=content))
    else:
        pass
    '''