Skip to content

Commit c47477b

Browse files
committed
feat: use connect_proj/user/studio instead of get_p/s/u
1 parent e47b058 commit c47477b

6 files changed

Lines changed: 44 additions & 15 deletions

File tree

tests/test_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import sys
22
import os
3-
import util
43

54

65
def test_import():
76
sys.path.insert(0, ".")
7+
import util
88

99
assert "FERNET_KEY" in os.environ
1010
assert len(os.environ["FERNET_KEY"]) == 32
11-
assert util.AUTH["test"]["note"]
11+
assert util.session().username == "ScratchAttachV2"

tests/test_project.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import sys
22

3+
34
def test_get():
45
sys.path.insert(0, ".")
56
import scratchattach as sa
6-
project = sa.get_project(1209355136)
7+
from util import session
8+
sess = session()
9+
10+
project = sess.connect_project(1209355136)
711

812
assert project
913
assert project.title == "Sample project #1"
@@ -22,7 +26,7 @@ def test_get():
2226
# studios
2327
comment = project.comments()[0] # TODO: move this to a separate comment tester
2428
# comment_by_id
25-
#comment_replies
29+
# comment_replies
2630
# comment by id
2731
# (un)love
2832
# (un)favorite
@@ -38,7 +42,6 @@ def test_get():
3842
# set title/instruction/notes
3943
# visibility
4044

41-
4245
assert comment.id == 489648029
4346

4447
remix = project.remixes()[0]
@@ -47,9 +50,10 @@ def test_get():
4750
assert remix.author_name == "ScratchAttachV2"
4851
assert remix.embed_url == "https://scratch.mit.edu/projects/1209582809/embed"
4952

50-
assert sa.get_project(414601586).moderation_status() == "notsafe"
51-
assert sa.get_project(1207314193).moderation_status() == "safe"
52-
assert sa.get_project(1233).moderation_status() == "notreviewed" # if this becomes reviewed, please update this
53+
assert sess.connect_project(414601586).moderation_status() == "notsafe"
54+
assert sess.connect_project(1207314193).moderation_status() == "safe"
55+
assert sess.connect_project(
56+
1233).moderation_status() == "notreviewed" # if this becomes reviewed, please update this
5357
# ^^ also this project is an infinite remix loop!
5458

5559
assert sa.explore_projects()

tests/test_studio.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
def test_import():
55
sys.path.insert(0, ".")
66
import scratchattach as sa
7+
from util import session
8+
sess = session()
79

8-
studio = sa.get_studio(50809872)
10+
studio = sess.connect_studio(50809872)
911

1012
assert studio.title == "Sample studio"
1113
assert studio.description == "Sample text"

tests/test_user.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
def test_import():
66
sys.path.insert(0, ".")
77
import scratchattach as sa
8+
from util import session
9+
sess = session()
810

9-
user = sa.get_user("ScratchAttachV2")
11+
user = sess.connect_user("ScratchAttachV2")
1012

1113
assert user.id == 147905216
1214
assert user.username == "ScratchAttachV2"
@@ -21,25 +23,25 @@ def test_import():
2123
assert user.classroom is None
2224
assert user.does_exist()
2325

24-
new_scratcher = sa.get_user("-NewScratcher-")
26+
new_scratcher = sess.connect_user("-NewScratcher-")
2527
assert new_scratcher.is_new_scratcher()
2628
assert new_scratcher.rank() == sa.Rank.NEW_SCRATCHER
2729
assert not new_scratcher.scratchteam
2830

29-
ceebee = sa.get_user("ceebee")
31+
ceebee = sess.connect_user("ceebee")
3032
assert not ceebee.is_new_scratcher()
3133
assert ceebee.scratchteam
3234
assert ceebee.rank() == sa.Rank.SCRATCH_TEAM
3335

34-
kaj = sa.get_user("kaj")
36+
kaj = sess.connect_user("kaj")
3537
assert not kaj.does_exist()
3638
# If you request for a user that never existed using sa.get_user, you will get an error. So we construct a new user
3739
# here like so:
3840
assert not sa.User(username="_").does_exist()
3941

4042
# status, bio
4143
# If the following is not the case, then a miracle has occurred
42-
griffpatch = sa.get_user("griffpatch")
44+
griffpatch = sess.connect_user("griffpatch")
4345
assert griffpatch.message_count() > 100
4446

4547
assert user.featured_data() is None

tests/util/__init__.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
# utility methods for testing
22
# includes special handlers for authentication etc.
3-
from .keyhandler import AUTH
3+
import warnings
4+
5+
from typing import Optional
6+
7+
from .keyhandler import AUTH as __AUTH
8+
from scratchattach import login, Session as _Session, LoginDataWarning
9+
10+
warnings.filterwarnings('ignore', category=LoginDataWarning)
11+
12+
_session: Optional[_Session] = None
13+
14+
15+
def session() -> _Session:
16+
global _session
17+
18+
if not _session:
19+
_session = login("ScratchAttachV2", __AUTH["auth"]["scratchattachv2"])
20+
21+
return _session

tests/util/auth.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
[test]
66
# this key is just used to test if auth is working
77
note = "gAAAAABozoVANH3_fARiCOFvv-O6pHd8DU2kb5vzs7xIxzE3JoWnsFByK5LdoLnnfh0pXpmSpo0KS1j4uwl3XvF-Qm3Sm63Fwy_H224EAdqF_d2hWdVxJkn7HmAJTT445AyrtdFYgrg9"
8+
9+
[auth]
10+
scratchattachv2="gAAAAABozo75u7Eov4zakrObMqLVs6wmwSNXQ7KroU5ntU7vZvM49fW-RnEWl1ZCnqIxAnjsPW5OUOBO2IS_MJYfuRl2CVNtaJojaO1s0uHk8_vZhh_YVMI="

0 commit comments

Comments
 (0)