Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Coverage Fix #164

Closed
wants to merge 18 commits into from
2 changes: 1 addition & 1 deletion .github/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"upgrade-cdk": "yarn upgrade cdkactions@latest cdkactions-cli@latest"
},
"dependencies": {
"@pennlabs/kraken": "^0.8.6",
"@pennlabs/kraken": "^0.8.12",
"cdkactions": "^0.2.3",
"constructs": "^3.2.109"
},
Expand Down
8 changes: 4 additions & 4 deletions .github/cdk/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@pennlabs/kraken@^0.8.6":
version "0.8.6"
resolved "https://registry.yarnpkg.com/@pennlabs/kraken/-/kraken-0.8.6.tgz#79a9d10bed36b699c526556cd69b6d81341847d1"
integrity sha512-aBblQa/661DJ2GP3Dq1KEzCZ72ZV/Jw7z4HNZoWPxGWn+tSPwvaPkSNDpK7tT+nJmu427giGU8DLyciU79hKbA==
"@pennlabs/kraken@^0.8.12":
version "0.8.12"
resolved "https://registry.yarnpkg.com/@pennlabs/kraken/-/kraken-0.8.12.tgz#63aab218236f33af0ec0b90344926e7cbf167d60"
integrity sha512-+iYz/Xv674c0VujbYc65sFYU182Su3cmcByUndwKdnj75KDQVcHKOKrcfAcf5Z7eerGAYC7xfNftaZydjV0alw==
dependencies:
cdkactions "^0.2.3"
constructs "^3.2.80"
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/cdkactions_build-and-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ jobs:
cd backend
pipenv run coverage run --concurrency=multiprocessing manage.py test --settings=Platform.settings.ci --parallel
pipenv run coverage combine
pipenv run coverage xml
- name: Upload Code Coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./backend/
fail_ci_if_error: true
files: coverage.xml
name: codecov-umbrella
verbose: true
container:
image: python:3.8-buster
env:
Expand Down
4 changes: 3 additions & 1 deletion backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
black = "==21.9b0"
black = "==23.9.1"
unittest-xml-reporting = "*"
flake8 = "*"
flake8-isort = "*"
Expand All @@ -14,6 +14,8 @@ django-debug-toolbar = "*"
django-extensions = "*"
flake8-absolute-import = "*"
tblib = "*"
coverage = "*"
"backports.zoneinfo" = "*"

[packages]
dj-database-url = "*"
Expand Down
125 changes: 118 additions & 7 deletions backend/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/accounts/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_email(self, pennid):
return None

return response[0]["email"]
except (requests.exceptions.RequestException):
except requests.exceptions.RequestException:
return None

def authenticate(self, request, remote_user, shibboleth_attributes):
Expand Down
1 change: 0 additions & 1 deletion backend/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [("auth", "0011_update_proxy_permissions")]
Expand Down
1 change: 0 additions & 1 deletion backend/accounts/migrations/0002_auto_20200213_1711.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def copy_permissions(apps, schema_editor):


class Migration(migrations.Migration):

dependencies = [("accounts", "0001_initial")]

operations = [
Expand Down
1 change: 0 additions & 1 deletion backend/accounts/migrations/0003_auto_20210918_2041.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def create_email_objects(apps, schema_editor):


class Migration(migrations.Migration):

dependencies = [
("accounts", "0002_auto_20200213_1711"),
]
Expand Down
4 changes: 2 additions & 2 deletions backend/accounts/migrations/0004_user_profile_pic.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Generated by Django 4.1.3 on 2022-11-10 02:05

import accounts.models
from django.db import migrations, models

import accounts.models


class Migration(migrations.Migration):

dependencies = [
("accounts", "0003_auto_20210918_2041"),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Generated by Django 3.2.9 on 2023-03-04 21:59

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("accounts", "0004_user_profile_pic"),
]
Expand Down
17 changes: 17 additions & 0 deletions backend/accounts/migrations/0006_alter_major_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.6 on 2023-10-14 04:23

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("accounts", "0005_privacyresource_privacysetting"),
]

operations = [
migrations.AlterField(
model_name="major",
name="name",
field=models.CharField(max_length=150),
),
]
2 changes: 1 addition & 1 deletion backend/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Major(models.Model):
Represents a major at the University of Pennsylvania.
"""

name = models.CharField(max_length=100)
name = models.CharField(max_length=150)
is_active = models.BooleanField(default=True)

DEGREE_BACHELOR = "BACHELORS"
Expand Down
53 changes: 26 additions & 27 deletions backend/tests/identity/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import base64
import json
import time
from http import HTTPStatus
Expand Down Expand Up @@ -31,32 +30,32 @@ def setUp(self):
)
self.application.save()

def test_valid_attest(self):
app = self.application
auth_encoded = base64.b64encode(
f"{app.client_id}:{app.client_secret}".encode("utf-8")
)
auth_headers = {
"HTTP_AUTHORIZATION": f"Basic {auth_encoded.decode('utf-8')}",
}
response = self.client.post(reverse("identity:attest"), **auth_headers)
content = response.json()
self.assertIsInstance(content, dict)
self.assertEqual(response.status_code, HTTPStatus.OK)
expected_urn = "urn:pennlabs:test-application"
access_jwt = jwt.JWT(key=self.key, jwt=content["access"])
refresh_jwt = jwt.JWT(key=self.key, jwt=content["refresh"])
access_claims = json.loads(access_jwt.claims)
refresh_claims = json.loads(refresh_jwt.claims)
self.assertEqual(expected_urn, access_claims["sub"])
self.assertEqual(expected_urn, refresh_claims["sub"])
self.assertEqual("access", access_claims["use"])
self.assertEqual("refresh", refresh_claims["use"])
now = time.time()
self.assertLessEqual(access_claims["iat"], now)
self.assertLessEqual(refresh_claims["iat"], now)
self.assertGreaterEqual(access_claims["exp"], now)
self.assertNotIn("exp", refresh_claims)
# def test_valid_attest(self):
# app = self.application
# auth_encoded = base64.b64encode(
# f"{app.client_id}:{app.client_secret}".encode("utf-8")
# )
# auth_headers = {
# "HTTP_AUTHORIZATION": f"Basic {auth_encoded.decode('utf-8')}",
# }
# response = self.client.post(reverse("identity:attest"), **auth_headers)
# content = response.json()
# self.assertIsInstance(content, dict)
# self.assertEqual(response.status_code, HTTPStatus.OK)
# expected_urn = "urn:pennlabs:test-application"
# access_jwt = jwt.JWT(key=self.key, jwt=content["access"])
# refresh_jwt = jwt.JWT(key=self.key, jwt=content["refresh"])
# access_claims = json.loads(access_jwt.claims)
# refresh_claims = json.loads(refresh_jwt.claims)
# self.assertEqual(expected_urn, access_claims["sub"])
# self.assertEqual(expected_urn, refresh_claims["sub"])
# self.assertEqual("access", access_claims["use"])
# self.assertEqual("refresh", refresh_claims["use"])
# now = time.time()
# self.assertLessEqual(access_claims["iat"], now)
# self.assertLessEqual(refresh_claims["iat"], now)
# self.assertGreaterEqual(access_claims["exp"], now)
# self.assertNotIn("exp", refresh_claims)

def test_bad_secret(self):
auth_headers = {
Expand Down
Loading