def __init__(self,
              course_id=None,
              partner_id=None,
              group_id=None,
              export_type=None,
              anonymity_level=None,
              statement_of_purpose=None,
              schema_names=None,
              interval=None,
              ignore_existing=None,
              id=None,
              status=None,
              download_link=None,
              metadata=None,
              **kwargs):
     ExportRequest.__init__(self,
                            course_id=course_id,
                            partner_id=partner_id,
                            group_id=group_id,
                            export_type=export_type,
                            anonymity_level=anonymity_level,
                            statement_of_purpose=statement_of_purpose,
                            schema_names=schema_names,
                            interval=interval,
                            ignore_existing=ignore_existing)
     self._id = id
     self._status = status
     self._download_link = download_link
     self._metadata = metadata
Beispiel #2
0
def test_schemas():
    eventing_request = ExportRequest(course_id=fake_course_id,
                                     export_type=EXPORT_TYPE_CLICKSTREAM)
    gradebook_request = ExportRequest(course_id=fake_course_id,
                                      export_type=EXPORT_TYPE_GRADEBOOK)
    all_tables_request = ExportRequest(course_id=fake_course_id,
                                       export_type=EXPORT_TYPE_TABLES,
                                       schema_names=SCHEMA_NAMES)

    assert eventing_request.schema_names_display is None
    assert gradebook_request.schema_names_display is None
    assert all_tables_request.schema_names_display == 'all'
Beispiel #3
0
def test_export_request_deserialize_from_json():
    export_request_json = {
        'scope': {
            'typeName': 'courseContext',
            'definition': {
                'courseId': fake_course_id
            }
        }
    }
    export_request = ExportRequest.from_json(export_request_json)

    assert ExportRequest(course_id=fake_course_id) == export_request
Beispiel #4
0
def test_export_request_serialize_to_json():
    export_request = ExportRequest(course_id=fake_course_id)
    expected_result = {
        'scope': {
            'typeName': 'courseContext',
            'definition': {
                'courseId': fake_course_id
            }
        }
    }

    assert export_request.to_json() == expected_result
Beispiel #5
0
    def request_clickstream(self, export_type = "RESEARCH_EVENTING", anonymity_level = "HASHED_IDS_NO_PII",
                            statement_of_purpose = "Weekly backup of course data"):

        if self.verbose:
            print "Requesting clickstream data ({}) for period {} to {}".format(self.course_slug, self.interval[0], self.interval[1])

        if self.log:
            logging.info("Requesting clickstream data ({}) for period {} to {}".format(self.course_slug, self.interval[0], self.interval[1]))

        # Construct request
        er = ExportRequest(course_id=self.course_id, export_type=export_type, anonymity_level = anonymity_level,
                           statement_of_purpose = statement_of_purpose, interval=self.interval)
        # Fire request
        try:
            ERM = api.post(er)[0]
        except:
            errors = ' '.join([str(e) for e in sys.exc_info()])
            if self.log:
                logging.error("Request failed ({}) with errors {}".format(self.course_slug, errors))
            print errors
            raise FailedRequest("Failed request")

        if self.log:
            logging.info("Request successfull ({})".format(self.course_slug))

        # Add id to self
        vals = ERM.to_json()
        self.id_ = vals['id']
        self.type_ = "CLICKSTREAM"
        self.metadata = vals["metadata"]
        self.schemaNames = "NONE"
Beispiel #6
0
def test_export_request_with_metadata_from_export_request():
    export_request = ExportRequest.from_args(course_id=fake_course_id)
    export_request_with_metadata = \
        ExportRequestWithMetadata.from_export_request(
            export_request, id=fake_export_id)

    assert export_request.course_id == export_request_with_metadata.course_id
    def from_json(cls, json_request):
        """
        Deserialize ExportRequestWithMetadata from json object.
        :param json_request:
        :return export_request: ExportRequestWithMetadata
        """
        export_request = ExportRequest.from_json(json_request)

        return cls.from_export_request(
            export_request=export_request,
            id=json_request.get('id'),
            status=json_request.get('status'),
            download_link=json_request.get('downloadLink'),
            metadata=ExportRequestMetadata.from_json(
                json_request.get('metadata')))
    def to_json(self):
        """
        Serialize ExportRequestWithMetadata to json object
        :return json_request:
        """
        json_request = ExportRequest.to_json(self)

        if self._id:
            json_request['id'] = self._id
        if self._status:
            json_request['status'] = self._status
        if self._download_link:
            json_request['downloadLink'] = self._download_link
        if self._metadata:
            json_request['metadata'] = self._metadata.to_json()

        return json_request
Beispiel #9
0
def request_tables(args):
    """
    Create and send a tables data export request with Coursera.
    """
    export_request = ExportRequest.from_args(
        course_id=args.course_id,
        course_slug=args.course_slug,
        partner_id=args.partner_id,
        partner_short_name=args.partner_short_name,
        group_id=args.group_id,
        user_id_hashing=args.user_id_hashing,
        statement_of_purpose=args.purpose,
        export_type=EXPORT_TYPE_TABLES,
        schema_names=args.schemas)

    export_request_with_metadata = api.post(export_request)[0]

    logging.info('Successfully created tables export request {id}.'.format(
        id=export_request_with_metadata.id))
    logging.debug('Request created with json body:\n{json}'.format(
        json=json.dumps(export_request_with_metadata.to_json(), indent=2)))
Beispiel #10
0
    def request_schemas(self,
                        export_type="RESEARCH_WITH_SCHEMAS",
                        anonymity_level="HASHED_IDS_NO_PII",
                        statement_of_purpose="Weekly backup of course data",
                        schema_names=[
                            "demographics", "users", "course_membership",
                            "course_progress", "feedback", "assessments",
                            "course_grades", "peer_assignments", "discussions",
                            "programming_assignments", "course_content"
                        ]):

        if self.log:
            logging.info("Requesting table data ({})".format(self.course_slug))

        # Construct request
        er = ExportRequest(course_id=self.course_id,
                           export_type=export_type,
                           anonymity_level=anonymity_level,
                           statement_of_purpose=statement_of_purpose,
                           schema_names=schema_names)
        # Fire request
        try:
            ERM = api.post(er)[0]
        except:  # Find out specific error
            errors = ' '.join([str(e) for e in sys.exc_info()])
            if self.log:
                logging.error("Request failed ({}) with errors {}".format(
                    self.course_slug, errors))
            print errors
            raise FailedRequest("Failed request")

        if self.log:
            logging.info("Request successfull ({})".format(self.course_slug))

        # Add info to self
        vals = ERM.to_json()
        self.id_ = vals['id']
        self.type_ = "TABLES"
        self.metadata = vals["metadata"]
        self.schemaNames = vals["schemaNames"]
Beispiel #11
0
def request_clickstream(args):
    """
    Create and send an clickstream data export request with Coursera. Only
    available for data coordinators.
    """
    export_request = ExportRequest.from_args(
        course_id=args.course_id,
        course_slug=args.course_slug,
        partner_id=args.partner_id,
        partner_short_name=args.partner_short_name,
        group_id=args.group_id,
        anonymity_level=ANONYMITY_LEVEL_COORDINATOR,
        statement_of_purpose=args.purpose,
        export_type=EXPORT_TYPE_CLICKSTREAM,
        interval=args.interval,
        ignore_existing=args.ignore_existing)

    export_request_with_metadata = api.post(export_request)[0]

    logging.info(
        'Successfully created clickstream export request {id}.'.format(
            id=export_request_with_metadata.id))
    logging.debug('Request created with json body:\n{json}'.format(
        json=json.dumps(export_request_with_metadata.to_json(), indent=2)))
Beispiel #12
0
def test_scope_id():
    export_request = ExportRequest(course_id=fake_course_id)

    assert export_request.scope_id == fake_course_id
Beispiel #13
0
def test_partner_id_inference(lookup_partner_id_by_short_name):
    lookup_partner_id_by_short_name.return_value = fake_partner_id
    export_request = ExportRequest.from_args(
        partner_short_name=fake_partner_short_name)

    assert ExportRequest(partner_id=fake_partner_id) == export_request
Beispiel #14
0
def test_course_id_inference(lookup_course_id_by_slug):
    lookup_course_id_by_slug.return_value = fake_course_id
    export_request = ExportRequest.from_args(course_slug=fake_course_slug)

    assert ExportRequest(course_id=fake_course_id) == export_request
Beispiel #15
0
def test_create_from_args_non_integer_partner_id():
    export_request = ExportRequest.from_args(partner_id=bad_partner_id)
Beispiel #16
0
def test_create_from_args():
    export_request = ExportRequest.from_args(course_id=fake_course_id)
    assert ExportRequest(course_id=fake_course_id) == export_request