예제 #1
0
        for i in range(num):
            # 随机生成key
            name = "".join(random.sample(string.ascii_letters, 8))
            type = "".join(random.sample(string.ascii_letters, 8))
            resp = self.client.post(url_for('admin.createkey'),
                                    data={
                                        'appname': name,
                                        'apptype': type
                                    })
            self.assert200(resp, message='create key fail')
            res = json.loads(resp.data)
            self.assertEqual('kiton', res['user'])
            keys.append(res)
        return keys

    # 随机产生一个curl命令
    def random_createcmd(self, keys):
        choice_key = random.choice(keys)
        command = "curl -o /dev/null -s "
        out_format = "-w %{time_connect},%{time_total} "
        test_url = "http://localhost:12480/image/v1/mean "
        value = "-F 'api_key={key}' -F 'api_secret={secret}' -F 'image={img}'".format(
            key=choice_key.get('api_key'),
            secret=choice_key.get('api_secret'),
            img='./darnet/data/dog.jpg')
        return command + out_format + test_url + value


if __name__ == '__main__':
    TestCase.main()