Skip to content

Commit

Permalink
Merge pull request #534 from leancloud/include-file-url
Browse files Browse the repository at this point in the history
fix: missing url attribute when decoding file object
  • Loading branch information
weakish authored Dec 8, 2021
2 parents 0f1bf69 + 9f10f07 commit d3d1c2a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ jobs:
pip install -e .'[test]'
- name: Run tests with ${{ matrix.python-version }}
env:
APP_ID: 8FfQwpvihLHK4htqmtEvkNrv
APP_KEY: eE9tNOcCiWoMHM1phxY41rAz
MASTER_KEY: 75zAjEJSj7lifKQqKSTryae9
APP_ID: YJRGphy60b8JCBib0vtDDtak-MdYXbMMI
APP_KEY: ${{ secrets.APP_KEY }}
MASTER_KEY: ${{ secrets.MASTER_KEY }}
USE_REGION: US
run:
nosetests -v
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ Configure the following environment variables:
- `MASTER_KEY`
- `USE_REGION`

Make sure the following options are configured on the LeanCloud console:

- Data Storage > Settings > Include ACL with objects being queried: **checked**
- Push Notification > Push notification settings > Prevent clients from sending push notifications: **unchecked**
- Settings > Security > Service switches > Push notifications: **enabled**
- Settings > Security > Service switches > SMS: **disabled**

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.
For example:

```js
AV.Cloud.define('add', async function (request) {
return request.params["a"] + request.params["b"]
})
```

Install dependencies:

```sh
Expand Down
1 change: 1 addition & 0 deletions leancloud/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def decode(key, value):
if meta_data:
f._metadata = meta_data
f._url = value["url"]
f._successful_url = value["url"]
f.id = value["objectId"]
return f

Expand Down
3 changes: 3 additions & 0 deletions tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def test_save_with_specified_key(): # type: () -> None
path = urlparse(f.url).path
if path.startswith("/avos-cloud-"): # old school aws s3 file url
assert path.split("/")[2] == user_specified_key
elif f.url.startswith("https://lc-gluttony"): # new aws s3 gluttony bucket
gluttony_path = "/" + os.environ["APP_ID"][0:12] + "/" + user_specified_key
assert path == gluttony_path
else:
assert path == "/" + user_specified_key

Expand Down
10 changes: 10 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from leancloud import Query
from leancloud import Object
from leancloud import GeoPoint
from leancloud.file_ import File

__author__ = "asaka <[email protected]>"

Expand Down Expand Up @@ -68,6 +69,9 @@ def setup_func():
game_score.set("playerName", "张三")
game_score.set("location", GeoPoint(latitude=i, longitude=-i))
game_score.set("random", random.randrange(100))
f = File("Blah.txt", open("tests/sample_text.txt", "rb"))
f.save()
game_score.set("attachment", f)
game_score.save()

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

@with_setup(make_setup_func())
def test_attachment(): # type: () -> None
result = Query(GameScore).first()
print(result.dump())
attachment = result.get('attachment')
assert attachment.url

@with_setup(make_setup_func())
def test_select(): # type: () -> None
Expand Down

0 comments on commit d3d1c2a

Please sign in to comment.