示例#1
0
    def test_submit(self, exchange):
        self._release_and_fetch("ps1", exchange)
        now = datetime.datetime.now()

        time.sleep(1)
        self._submit("ps1", exchange)

        filename, = os.listdir(os.path.join(exchange, "abc101/inbound"))
        username, assignment, timestamp1 = filename.split("+")
        assert username == os.environ['USER']
        assert assignment == "ps1"
        assert parse_utc(timestamp1) > now
        assert os.path.isfile(os.path.join(exchange, "abc101/inbound", filename, "p1.ipynb"))
        assert os.path.isfile(os.path.join(exchange, "abc101/inbound", filename, "timestamp.txt"))

        with open(os.path.join(exchange, "abc101/inbound", filename, "timestamp.txt"), "r") as fh:
            assert fh.read() == timestamp1

        time.sleep(1)
        self._submit("ps1", exchange)

        assert len(os.listdir(os.path.join(exchange, "abc101/inbound"))) == 2
        filename = sorted(os.listdir(os.path.join(exchange, "abc101/inbound")))[1]
        username, assignment, timestamp2 = filename.split("+")
        assert username == os.environ['USER']
        assert assignment == "ps1"
        assert parse_utc(timestamp2) > parse_utc(timestamp1)
        assert os.path.isfile(os.path.join(exchange, "abc101/inbound", filename, "p1.ipynb"))
        assert os.path.isfile(os.path.join(exchange, "abc101/inbound", filename, "timestamp.txt"))

        with open(os.path.join(exchange, "abc101/inbound", filename, "timestamp.txt"), "r") as fh:
            assert fh.read() == timestamp2
示例#2
0
def test_update_or_create_submission(assignment):
    assignment.add_student('hacker123')
    s1 = assignment.update_or_create_submission('foo', 'hacker123')
    assert s1.timestamp is None

    s2 = assignment.update_or_create_submission('foo', 'hacker123', timestamp="2015-02-02 14:58:23.948203 PST")
    assert s1 == s2
    assert s2.timestamp == utils.parse_utc("2015-02-02 14:58:23.948203 PST")
示例#3
0
 def _get_existing_timestamp(self, dest_path):
     """Get the timestamp, as a datetime object, of an existing submission."""
     timestamp_path = os.path.join(dest_path, 'timestamp.txt')
     if os.path.exists(timestamp_path):
         with open(timestamp_path, 'r') as fh:
             timestamp = fh.read().strip()
         return parse_utc(timestamp)
     else:
         return None
示例#4
0
 def _get_existing_timestamp(self, dest_path):
     """Get the timestamp, as a datetime object, of an existing submission."""
     timestamp_path = os.path.join(dest_path, 'timestamp.txt')
     if os.path.exists(timestamp_path):
         with open(timestamp_path, 'r') as fh:
             timestamp = fh.read().strip()
         return parse_utc(timestamp)
     else:
         return None
示例#5
0
 def _path_to_record(self, path):
     filename = os.path.split(path)[1]
     # Only split twice on +, giving three components. This allows usernames with +.
     filename_list = filename.rsplit('+', 2)
     if len(filename_list) != 3:
         self.fail("Invalid filename: {}".format(filename))
     username = filename_list[0]
     timestamp = parse_utc(filename_list[2])
     return {'username': username, 'filename': filename, 'timestamp': timestamp}
示例#6
0
 def _path_to_record(self, path):
     filename = os.path.split(path)[1]
     # Only split twice on +, giving three components. This allows usernames with +.
     filename_list = filename.rsplit('+', 2)
     if len(filename_list) != 3:
         self.fail("Invalid filename: {}".format(filename))
     username = filename_list[0]
     timestamp = parse_utc(filename_list[2])
     return {'username': username, 'filename': filename, 'timestamp': timestamp}
示例#7
0
def test_update_or_create_assignment(gradebook):
    # first test creating it
    a1 = gradebook.update_or_create_assignment('foo')
    assert gradebook.find_assignment('foo') == a1
    assert a1.duedate is None

    # now test finding/updating it
    a2 = gradebook.update_or_create_assignment('foo', duedate="2015-02-02 14:58:23.948203 PST")
    assert a1 == a2
    assert a2.duedate == utils.parse_utc("2015-02-02 14:58:23.948203 PST")
示例#8
0
    def _get_submission_list(self, course_id, assignment_id):
        '''
        Returns a list of submission entries. Each entry is a dictionary
        containing the 'student_id' and 'timestamp'.
        '''
        response = self.ngshare_api_get('/submissions/{}/{}'.format(
            course_id, assignment_id))
        if response is None:
            return None

        return [{
            'student_id': x['student_id'],
            'timestamp': parse_utc(x['timestamp']),
        } for x in response['submissions']]
示例#9
0
 def _get_submission(self, request: PreparedRequest, context):
     request = parse_body(request.body)
     timestamp = None
     try:
         if 'timestamp' in request:
             timestamp = request['timestamp']
         else:
             timestamp = (str(2000 + self.num_submissions) +
                          self.timestamp_template)
         time = parse_utc(timestamp)
         assert time.year > 2000 and time.year < 2001 + self.num_submissions
         assert timestamp == str(time.year) + self.timestamp_template
     except Exception:
         return {'success': False, 'message': 'Submission not found'}
     content = base64.b64encode(self._notebook_content()).decode()
     files = [{'path': self.notebook_id + '.ipynb', 'content': content}]
     return {'success': True, 'timestamp': timestamp, 'files': files}
示例#10
0
 def _read_timestamp(self, root):
     with open(os.path.join(root, "timestamp.txt"), "r") as fh:
         timestamp = parse_utc(fh.read())
     return timestamp
示例#11
0
 def _read_timestamp(self, root):
     with open(os.path.join(root, "timestamp.txt"), "r") as fh:
         timestamp = parse_utc(fh.read())
     return timestamp