def _parse_project(project, filename, new_project): """Perform the required checks and get the final project name""" current_slug = get_cached_slug() # Check for existing project in-memory or in .jovianrc if not new_project and project is None: # From in-memory variable if current_slug is not None: project = current_slug # From .jovianrc file else: project = get_notebook_slug(filename) # Skip if project is not provided & can't be read if project is None: return None, None # Get project metadata for UUID & username/title if is_uuid(project): project_title = None metadata = api.get_gist(project) elif '/' in project: project_title = project.split('/')[1] username = api.get_current_user()['username'] metadata = api.get_gist(project) # Attach username to the title else: project_title = project username = api.get_current_user()['username'] metadata = api.get_gist(username + '/' + project) # Skip if metadata could not be found if not metadata: log('Creating a new project "' + username + '/' + project_title + '"') return project_title, None # Extract information from metadata username = metadata['owner']['username'] project_title = metadata['title'] project_id = metadata['slug'] # Check if the current user can commit to this project permissions = api.get_gist_access(project_id) if not permissions['write']: return project_title, None # Log whether this is an update or creation if project_id is None: log('Creating a new notebook on ' + read_webapp_url()) else: log('Updating notebook "' + username + "/" + project_title + '" on ' + read_webapp_url()) return project_title, project_id
def test_is_uuid_false(self): text = "this-is-not-a-uuid" self.assertFalse(is_uuid(text))
def test_is_uuid_with_hypens(self): text = "374ab608-6ca4-4976-9b3e-44b6e35f9126" self.assertTrue(is_uuid(text))
def test_is_uuid_without_hyphens(self): text = "374ab6086ca449769b3e44b6e35f9126" self.assertTrue(is_uuid(text))
def test_is_uuid(uuid, expected_result): assert is_uuid(uuid) == expected_result