|
| 1 | +import datetime |
1 | 2 | import os |
2 | 3 | import time |
3 | 4 | import pytest |
|
7 | 8 | from .. import run_nbgrader |
8 | 9 | from .base import BaseTestApp |
9 | 10 | from .conftest import notwindows |
| 11 | +from ...api import Gradebook |
10 | 12 | from ...utils import parse_utc, get_username |
11 | 13 |
|
12 | 14 |
|
@@ -151,3 +153,45 @@ def test_permissions(self, exchange, course_dir, cache, groupshared): |
151 | 153 | assert self._get_permissions(join(exchange, "abc101", "inbound")) == ("2733" if not groupshared else "2773") |
152 | 154 | assert self._get_permissions(join(course_dir, "submitted", "foobar_student", "ps1")) == ("777" if not groupshared else "2777") |
153 | 155 | 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