def test_get_user_credentials(self): """Verify user credentials data can be retrieve.""" self.create_credentials_config() self.mock_credentials_api(self.user) actual = get_user_credentials(self.user) self.assertEqual(actual, self.CREDENTIALS_API_RESPONSE['results'])
def test_get_user_credentials(self): """Verify user credentials data can be retrieve.""" self.create_credentials_config() self.mock_credentials_api(self.user) actual = get_user_credentials(self.user) self.assertEqual(actual, self.CREDENTIALS_API_RESPONSE['results'])
def get_awarded_certificate_programs(student): """ Find the ids of all the programs for which the student has already been awarded a certificate. Args: student: User object representing the student Returns: ids of the programs for which the student has been awarded a certificate """ return [ credential['credential']['program_id'] for credential in get_user_credentials(student) if 'program_id' in credential['credential'] and credential['status'] == 'awarded' ]
def get_certified_programs(student): """ Find the UUIDs of all the programs for which the student has already been awarded a certificate. Args: student: User object representing the student Returns: UUIDs of the programs for which the student has been awarded a certificate """ certified_programs = [] for credential in get_user_credentials(student): if 'program_uuid' in credential['credential']: certified_programs.append(credential['credential']['program_uuid']) return certified_programs
def get_awarded_certificate_programs(student): """ Find the ids of all the programs for which the student has already been awarded a certificate. Args: student: User object representing the student Returns: ids of the programs for which the student has been awarded a certificate """ return [ credential['credential']['program_id'] for credential in get_user_credentials(student) if 'program_id' in credential['credential'] and credential['status'] == 'awarded' ]
def get_awarded_certificate_programs(student): """ Find the ids of all the programs for which the student has already been awarded a certificate. Args: student: User object representing the student Returns: ids of the programs for which the student has been awarded a certificate """ return [ credential["credential"]["program_id"] for credential in get_user_credentials(student) if "program_id" in credential["credential"] and credential["status"] == "awarded" ]
def get_certified_programs(student): """ Find the UUIDs of all the programs for which the student has already been awarded a certificate. Args: student: User object representing the student Returns: UUIDs of the programs for which the student has been awarded a certificate """ certified_programs = [] for credential in get_user_credentials(student): if 'program_uuid' in credential['credential']: certified_programs.append(credential['credential']['program_uuid']) return certified_programs
def test_get_user_credentials_caching(self): """Verify that when enabled, the cache is used for non-staff users.""" self.create_credentials_config(cache_ttl=1) self.mock_credentials_api(self.user) # Warm up the cache. get_user_credentials(self.user) # Hit the cache. get_user_credentials(self.user) # Verify only one request was made. self.assertEqual(len(httpretty.httpretty.latest_requests), 1) staff_user = UserFactory(is_staff=True) # Hit the Credentials API twice. for _ in range(2): get_user_credentials(staff_user) # Verify that three requests have been made (one for student, two for staff). self.assertEqual(len(httpretty.httpretty.latest_requests), 3)
def test_get_user_credentials_caching(self): """Verify that when enabled, the cache is used for non-staff users.""" self.create_credentials_config(cache_ttl=1) self.mock_credentials_api(self.user) # Warm up the cache. get_user_credentials(self.user) # Hit the cache. get_user_credentials(self.user) # Verify only one request was made. self.assertEqual(len(httpretty.httpretty.latest_requests), 1) staff_user = UserFactory(is_staff=True) # Hit the Credentials API twice. for _ in range(2): get_user_credentials(staff_user) # Verify that three requests have been made (one for student, two for staff). self.assertEqual(len(httpretty.httpretty.latest_requests), 3)