def test_n_draft_with_drafts(self): """Test CACHE PROJECTS n_draft returns 2 if there are 2 draft projects""" # Here, we are suposing that a project is draft iff has no presenter AND has no tasks AppFactory.create_batch(2, info={}) number_of_drafts = cached_apps.n_draft() assert number_of_drafts == 2, number_of_drafts
def test_n_draft_with_drafts(self): """Test CACHE PROJECTS _n_draft returns 2 if there are 2 draft projects""" # Here, we are suposing that a project is draft iff has no presenter AND has no tasks AppFactory.create_batch(2, info={}) number_of_drafts = cached_apps._n_draft() assert number_of_drafts == 2, number_of_drafts
def test_filter_by_one_condition(self): """Test filter_by returns a list of projects that meet the filtering condition""" AppFactory.create_batch(3, allow_anonymous_contributors=False) should_be_missing = AppFactory.create(allow_anonymous_contributors=True) retrieved_projects = self.project_repo.filter_by(allow_anonymous_contributors=False) assert len(retrieved_projects) == 3, retrieved_projects assert should_be_missing not in retrieved_projects, retrieved_projects
def test_filter_by_multiple_conditions(self): """Test filter_by supports multiple-condition queries""" AppFactory.create_batch(2, allow_anonymous_contributors=False, hidden=0) project = AppFactory.create(allow_anonymous_contributors=False, hidden=1) retrieved_projects = self.project_repo.filter_by( allow_anonymous_contributors=False, hidden=1) assert len(retrieved_projects) == 1, retrieved_projects assert project in retrieved_projects, retrieved_projects
def test_filter_by_limit_offset(self): """Test that filter_by supports limit and offset options""" AppFactory.create_batch(4) all_projects = self.project_repo.filter_by() first_two = self.project_repo.filter_by(limit=2) last_two = self.project_repo.filter_by(limit=2, offset=2) assert len(first_two) == 2, first_two assert len(last_two) == 2, last_two assert first_two == all_projects[:2] assert last_two == all_projects[2:]
def test_filter_by_one_condition(self): """Test filter_by returns a list of projects that meet the filtering condition""" AppFactory.create_batch(3, allow_anonymous_contributors=False) should_be_missing = AppFactory.create( allow_anonymous_contributors=True) retrieved_projects = self.project_repo.filter_by( allow_anonymous_contributors=False) assert len(retrieved_projects) == 3, retrieved_projects assert should_be_missing not in retrieved_projects, retrieved_projects
def get_all_returns_list_of_all_projects(self): """Test get_all returns a list of all the existing projects""" projects = AppFactory.create_batch(3) retrieved_projects = self.project_repo.get_all() assert isinstance(retrieved_projects, list) assert len(retrieved_projects) == len(projects), retrieved_projects for project in retrieved_projects: assert project in projects, project
def test_limits_query(self): """Test API GET limits works""" owner = UserFactory.create() apps = AppFactory.create_batch(30, owner=owner) for app in apps: task = TaskFactory.create(app=app) TaskRunFactory.create(task=task) res = self.app.get('/api/app') data = json.loads(res.data) assert len(data) == 20, len(data) res = self.app.get('/api/app?limit=10') data = json.loads(res.data) assert len(data) == 10, len(data) res = self.app.get('/api/app?limit=10&offset=10') data = json.loads(res.data) assert len(data) == 10, len(data) assert data[0].get('name') == apps[10].name, data[0] res = self.app.get('/api/task') data = json.loads(res.data) assert len(data) == 20, len(data) res = self.app.get('/api/taskrun') data = json.loads(res.data) assert len(data) == 20, len(data) UserFactory.create_batch(30) res = self.app.get('/api/user') data = json.loads(res.data) assert len(data) == 20, len(data) res = self.app.get('/api/user?limit=10') data = json.loads(res.data) print data assert len(data) == 10, len(data) res = self.app.get('/api/user?limit=10&offset=10') data = json.loads(res.data) assert len(data) == 10, len(data) assert data[0].get('name') == 'user11', data
def test_blogpost_get_one_errors(self): """Test blogposts GET non existing posts raises errors""" self.register() user = user_repo.get(1) app1, app2 = AppFactory.create_batch(2, owner=user) blogpost = BlogpostFactory.create(app=app1) # To a non-existing app url = "/app/non-existing-app/%s" % blogpost.id res = self.app.get(url, follow_redirects=True) assert res.status_code == 404, res.status_code # To a non-existing post url = "/app/%s/999999" % app1.short_name res = self.app.get(url, follow_redirects=True) assert res.status_code == 404, res.status_code # To an existing post but with a project in the URL it does not belong to url = "/app/%s/%s" % (app2.short_name, blogpost.id) res = self.app.get(url, follow_redirects=True) assert res.status_code == 404, res.status_code