Skip to content

Commit d3d1c2a

Browse files
authored
Merge pull request #534 from leancloud/include-file-url
fix: missing url attribute when decoding file object
2 parents 0f1bf69 + 9f10f07 commit d3d1c2a

5 files changed

Lines changed: 33 additions & 3 deletions

File tree

.github/workflows/pythonpackage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ jobs:
5757
pip install -e .'[test]'
5858
- name: Run tests with ${{ matrix.python-version }}
5959
env:
60-
APP_ID: 8FfQwpvihLHK4htqmtEvkNrv
61-
APP_KEY: eE9tNOcCiWoMHM1phxY41rAz
62-
MASTER_KEY: 75zAjEJSj7lifKQqKSTryae9
60+
APP_ID: YJRGphy60b8JCBib0vtDDtak-MdYXbMMI
61+
APP_KEY: ${{ secrets.APP_KEY }}
62+
MASTER_KEY: ${{ secrets.MASTER_KEY }}
6363
USE_REGION: US
6464
run:
6565
nosetests -v

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ Configure the following environment variables:
4545
- `MASTER_KEY`
4646
- `USE_REGION`
4747

48+
Make sure the following options are configured on the LeanCloud console:
49+
50+
- Data Storage > Settings > Include ACL with objects being queried: **checked**
51+
- Push Notification > Push notification settings > Prevent clients from sending push notifications: **unchecked**
52+
- Settings > Security > Service switches > Push notifications: **enabled**
53+
- Settings > Security > Service switches > SMS: **disabled**
54+
55+
And there is a cloud function naming `add` which returns `3` for `add(a=1, b=2)` deployed on the LeanEngine production environment of the application.
56+
For example:
57+
58+
```js
59+
AV.Cloud.define('add', async function (request) {
60+
return request.params["a"] + request.params["b"]
61+
})
62+
```
63+
4864
Install dependencies:
4965

5066
```sh

leancloud/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def decode(key, value):
140140
if meta_data:
141141
f._metadata = meta_data
142142
f._url = value["url"]
143+
f._successful_url = value["url"]
143144
f.id = value["objectId"]
144145
return f
145146

tests/test_file.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ def test_save_with_specified_key(): # type: () -> None
123123
path = urlparse(f.url).path
124124
if path.startswith("/avos-cloud-"): # old school aws s3 file url
125125
assert path.split("/")[2] == user_specified_key
126+
elif f.url.startswith("https://lc-gluttony"): # new aws s3 gluttony bucket
127+
gluttony_path = "/" + os.environ["APP_ID"][0:12] + "/" + user_specified_key
128+
assert path == gluttony_path
126129
else:
127130
assert path == "/" + user_specified_key
128131

tests/test_query.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from leancloud import Query
1818
from leancloud import Object
1919
from leancloud import GeoPoint
20+
from leancloud.file_ import File
2021

2122
__author__ = "asaka <lan@leancloud.rocks>"
2223

@@ -68,6 +69,9 @@ def setup_func():
6869
game_score.set("playerName", "张三")
6970
game_score.set("location", GeoPoint(latitude=i, longitude=-i))
7071
game_score.set("random", random.randrange(100))
72+
f = File("Blah.txt", open("tests/sample_text.txt", "rb"))
73+
f.save()
74+
game_score.set("attachment", f)
7175
game_score.save()
7276

7377
return setup_func
@@ -468,6 +472,12 @@ def test_include(): # type: () -> None
468472
result = Query(GameScore).include(["score"]).find()
469473
assert len(result) == 10
470474

475+
@with_setup(make_setup_func())
476+
def test_attachment(): # type: () -> None
477+
result = Query(GameScore).first()
478+
print(result.dump())
479+
attachment = result.get('attachment')
480+
assert attachment.url
471481

472482
@with_setup(make_setup_func())
473483
def test_select(): # type: () -> None

0 commit comments

Comments
 (0)