FIX hidden assignment test
import copy
from datetime import datetime, timedelta
-from utils import Session
+from utils import Session, with_context
sample_sync = {
"name": "CS-UY 3224 TEST PUBLIC HIDDEN 1",
"course": "CS-UY 3224",
- "hidden": True,
- "github_template": "wabscale/xv6-public",
- "github_repo_required": True,
"unique_code": "aaaaa1",
"pipeline_image": "registry.digitalocean.com/anubis/assignment/aa11bb2233",
- "date": {
- "release": str(datetime.now() - timedelta(hours=2)),
- "due": str(datetime.now() + timedelta(hours=12)),
- "grace": str(datetime.now() + timedelta(hours=13)),
- },
- "description": "This is a very long description that encompasses the entire assignment\n",
- "questions": [],
- "tests": ["abc123"],
+ "tests": [{"name": "abc123", "hidden": False, "points": 10}],
}
sample_sync_2 = copy.deepcopy(sample_sync)
sample_sync_2["name"] = "CS-UY 3224 TEST PUBLIC HIDDEN 2"
-sample_sync_2["hidden"] = False
sample_sync_2["unique_code"] = "aaaaa2"
-sample_sync_2["date"]["release"] = str(datetime.now() + timedelta(hours=2))
+
+
+@with_context
+def update_hidden_assignments(aid1, aid2):
+ from anubis.models import db, Assignment
+ db.session.expire_all()
+ db.session.expunge_all()
+
+ assignment1: Assignment = Assignment.query.filter(Assignment.id == aid1).first()
+ assignment2: Assignment = Assignment.query.filter(Assignment.id == aid2).first()
+
+ assignment1.hidden = True
+ assignment1.release_date = datetime.now() - timedelta(hours=2)
+ assignment2.hidden = False
+ assignment2.release_date = datetime.now() + timedelta(hours=2)
+
+ db.session.commit()
def create_hidden_assignments():
s = Session("superuser")
- s.post_json("/admin/assignments/sync", json={"assignment": sample_sync})
- s.post_json("/admin/assignments/sync", json={"assignment": sample_sync_2})
+
+ d1 = s.post_json("/admin/assignments/sync", json={"assignment": sample_sync})
+ d2 = s.post_json("/admin/assignments/sync", json={"assignment": sample_sync_2})
+
+ update_hidden_assignments(d1['assignment']['id'], d2['assignment']['id'])
def test_assignment_public():
