def test_osm_service_raise_error_if_user_element_not_found(self): # Arrange osm_response = get_canned_simplified_osm_user_details() # Act / Assert with self.assertRaises(OSMServiceError): OSMService._parse_osm_user_details_response(osm_response, "wont-find")
def check_and_update_mapper_level(user_id: int): """ Check users mapping level and update if they have crossed threshold """ user = UserService.get_user_by_id(user_id) user_level = MappingLevel(user.mapping_level) if user_level == MappingLevel.ADVANCED: return # User has achieved highest level, so no need to do further checking intermediate_level = current_app.config["MAPPER_LEVEL_INTERMEDIATE"] advanced_level = current_app.config["MAPPER_LEVEL_ADVANCED"] try: osm_details = OSMService.get_osm_details_for_user(user_id) if (osm_details.changeset_count > advanced_level and user.mapping_level != MappingLevel.ADVANCED.value): user.mapping_level = MappingLevel.ADVANCED.value UserService.notify_level_upgrade(user_id, user.username, "ADVANCED") elif (intermediate_level < osm_details.changeset_count < advanced_level and user.mapping_level != MappingLevel.INTERMEDIATE.value): user.mapping_level = MappingLevel.INTERMEDIATE.value UserService.notify_level_upgrade(user_id, user.username, "INTERMEDIATE") except OSMServiceError: # Swallow exception as we don't want to blow up the server for this current_app.logger.error("Error attempting to update mapper level") return user.save()
def get_osm_details_for_user(username: str) -> UserOSMDTO: """ Gets OSM details for the user from OSM API :param username: username in scope :raises UserServiceError, NotFound """ user = UserService.get_user_by_username(username) osm_dto = OSMService.get_osm_details_for_user(user.id) return osm_dto
def test_osm_service_can_parse_oms_user_details_xml(self): # Arrange osm_response = get_canned_simplified_osm_user_details() # Act dto = OSMService._parse_osm_user_details_response(osm_response) # Assert self.assertEqual(dto.account_created, "2015-05-14T18:10:16Z") self.assertEqual(dto.changeset_count, 16)