Skip to content

Commit fb09ec2

Browse files
committed
Add tests for --before-duedate
1 parent e388352 commit fb09ec2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

nbgrader/tests/apps/test_nbgrader_collect.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import datetime
12
import os
23
import time
34
import pytest
@@ -7,6 +8,7 @@
78
from .. import run_nbgrader
89
from .base import BaseTestApp
910
from .conftest import notwindows
11+
from ...api import Gradebook
1012
from ...utils import parse_utc, get_username
1113

1214

@@ -151,3 +153,45 @@ def test_permissions(self, exchange, course_dir, cache, groupshared):
151153
assert self._get_permissions(join(exchange, "abc101", "inbound")) == ("2733" if not groupshared else "2773")
152154
assert self._get_permissions(join(course_dir, "submitted", "foobar_student", "ps1")) == ("777" if not groupshared else "2777")
153155
assert self._get_permissions(join(course_dir, "submitted", "foobar_student", "ps1", "p1.ipynb")) == ("644" if not groupshared else "664")
156+
157+
@pytest.mark.parametrize('before_duedate',
158+
['yes', 'no', 'nofirst'])
159+
def test_collect_before_due_date(self, exchange, course_dir, cache, db, before_duedate):
160+
"""Test --before-duedate flag.
161+
162+
Test is parameterized so we test both with it and without the flag.
163+
164+
'yes': test with --before-duedate
165+
'no': test without
166+
'nofirst': test with --before-duedate but no assignment before duedate
167+
168+
"""
169+
# Release assignment
170+
self._release_and_fetch("ps1", exchange, course_dir)
171+
172+
# Submit something, wait, submit again. Due date is between.
173+
if before_duedate != 'nofirst':
174+
# We don't submit first assignment.
175+
self._submit("ps1", exchange, cache)
176+
time.sleep(.05)
177+
time_duedate = datetime.datetime.utcnow()
178+
time.sleep(.05)
179+
self._submit("ps1", exchange, cache)
180+
181+
# Set the due date
182+
with Gradebook(db) as gb:
183+
gb.update_or_create_assignment('ps1', duedate=time_duedate)
184+
185+
# Collect
186+
flags = ['--db', db]
187+
if before_duedate != 'no':
188+
flags.append('--before-duedate')
189+
self._collect("ps1", exchange, flags=flags)
190+
191+
root = os.path.os.path.join(os.path.join(course_dir, "submitted", get_username(), "ps1"))
192+
timestamp = self._read_timestamp(root)
193+
# Test both ways: with --before-duedate flag and without
194+
if before_duedate == 'yes':
195+
assert timestamp < time_duedate
196+
else: # 'no', 'nofirst'
197+
assert timestamp > time_duedate

0 commit comments

Comments
 (0)