Skip to content

Commit

Permalink
Try to fix the overabundance of profiles (#1370)
Browse files Browse the repository at this point in the history
* Try to fix the overabundance of profiles

and dep updates

* thanksh, stubs

* stop using deleted password generation method in tests

* Fix silly test stuff

* fix filtering
  • Loading branch information
ethteck authored Oct 27, 2024
1 parent 373584c commit 36edf52
Show file tree
Hide file tree
Showing 8 changed files with 815 additions and 775 deletions.
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ RUN apt-get -y update && apt-get install -y \
&& rm -rf /var/lib/apt/lists/*

RUN curl -sSL https://install.python-poetry.org/ | \
POETRY_VERSION=1.8.3 POETRY_HOME=/etc/poetry python3.10 -
POETRY_VERSION=1.8.4 POETRY_HOME=/etc/poetry python3.10 -

COPY --from=nsjail /nsjail/nsjail /bin/nsjail

Expand Down
2 changes: 1 addition & 1 deletion backend/coreapp/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def set_user_profile(
def middleware(request: Request) -> Response:
# Skip if the request is from SSR
if "User-Agent" in request.headers and (
"node-fetch" in request.headers["User-Agent"]
"node" in request.headers["User-Agent"]
or "undici" in request.headers["User-Agent"]
or "Next.js Middleware" in request.headers["User-Agent"]
):
Expand Down
4 changes: 2 additions & 2 deletions backend/coreapp/models/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def login(request: Request, oauth_code: str) -> "GitHubUser":
response = requests.post(
"https://github.com/login/oauth/access_token",
json={
"client_id": settings.GITHUB_CLIENT_ID, # type: ignore
"client_secret": settings.GITHUB_CLIENT_SECRET, # type: ignore
"client_id": settings.GITHUB_CLIENT_ID,
"client_secret": settings.GITHUB_CLIENT_SECRET,
"code": oauth_code,
},
headers={"Accept": "application/json"},
Expand Down
4 changes: 1 addition & 3 deletions backend/coreapp/models/scratch.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ def to_python(self, value: Any) -> list[Library]:
return [Library(name=lib["name"], version=lib["version"]) for lib in res]

def from_db_value(self, *args: Any, **kwargs: Any) -> list[Library]:
# We ignore the type error here as this is a bug in the django stubs.
# CC: https://github.com/typeddjango/django-stubs/issues/934
res = super().from_db_value(*args, **kwargs) # type: ignore
res = super().from_db_value(*args, **kwargs)
return [Library(name=lib["name"], version=lib["version"]) for lib in res]


Expand Down
4 changes: 2 additions & 2 deletions backend/coreapp/tests/test_preset.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class PresetTests(BaseTestCase):
def create_admin(self) -> None:
self.username = "admin"
self.password = User.objects.make_random_password()
self.password = "testpassword"
user, created = User.objects.get_or_create(username=self.username)
user.set_password(self.password)
user.is_staff = True
Expand All @@ -43,7 +43,7 @@ def create_admin(self) -> None:

def create_user(self, username: str = "dummy-user") -> User:
self.username = username
self.password = User.objects.make_random_password()
self.password = "testpassword"
user, created = User.objects.get_or_create(username=self.username)
user.set_password(self.password)
user.save()
Expand Down
29 changes: 14 additions & 15 deletions backend/coreapp/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,20 @@ def test_github_login(self) -> None:
Ensure that a user is created upon sign-in with GitHub.
"""

responses.add(
responses.POST,
responses.post(
"https://github.com/login/oauth/access_token",
json={
"access_token": "__mock__",
"scope": "public_repo",
},
status=200,
)
responses.add(
responses.GET,
responses.get(
"https://api.github.com:443/user",
json=GITHUB_USER,
status=200,
)
responses.add(
responses.GET,
responses.get(
f"https://api.github.com:443/user/{GITHUB_USER['id']}",
json=GITHUB_USER,
status=200,
Expand All @@ -105,31 +102,33 @@ def test_github_login_where_exists_already(self) -> None:
Ensure that you can log in to an existing user with GitHub.
"""

# log in as the user
self.test_github_login()

responses.add(
responses.POST,
responses.post(
"https://github.com/login/oauth/access_token",
json={
"access_token": "__mock__",
"scope": "public_repo",
},
status=200,
)
responses.add(
responses.GET,
responses.get(
"https://api.github.com:443/user",
json=GITHUB_USER,
status=200,
)
responses.add(
responses.GET,
responses.get(
f"https://api.github.com:443/user/{GITHUB_USER['id']}",
json=GITHUB_USER,
status=200,
)

# log in as the user
response = self.client.post(
self.current_user_url,
{
"code": "__mock__",
},
)

# log in as the user again
response = self.client.post(
self.current_user_url,
Expand Down
Loading

0 comments on commit 36edf52

Please sign in to comment.