def setUpClass(cls): """ Project1: user1, user2, user3 Project2: user1, user2 Project3: user1, user3 """ super(SearchTestMixin, cls).setUpClass() cls.user1 = snippets.create_user() cls.user2 = snippets.create_user() cls.user3 = snippets.create_user() cls.project1 = snippets.create_project(cls.user1) cls.project2 = snippets.create_project(cls.user1) cls.project3 = snippets.create_project(cls.user1) cls.project1.add_user(cls.user2) cls.project1.add_user(cls.user3) cls.project2.add_user(cls.user2) cls.project3.add_user(cls.user3) cls.issue1 = Issue.create(cls.user1, "first issue", "whatever dude", cls.project1, assigned=cls.user1) cls.issue2 = Issue.create(cls.user1, "second issue", "lamb on the ground", cls.project1, assigned=cls.user2) cls.issue3 = Issue.create(cls.user1, "friendly hello", "hey there dude", cls.project2, assigned=cls.user1) cls.issue4 = Issue.create(cls.user1, "big problem", "pizza on the ground", cls.project2) search.refresh() # to ensure our stuff is going to be there when we search
def test_assignment(self): results = Issue.search(projects=[self.project1, self.project2], assigned=[self.user1]) for x in results: self.assertEqual(self.user1.id, x.assigned_to_id) self.assertEqual(self.user1, x.assigned) self.assertEqual(results.total, 2) results = Issue.search(projects=[self.project1], assigned=[self.user1]) self.assertEqual(results.total, 1) with self.assertRaises(InvalidSearchException): results = Issue.search(assigned=[self.user2])
def test_should_be_able_to_create_new_issue(self): """Should be able to create a new issue and get all related objects""" user = snippets.create_user() project = Project.create(name="test project", user=user) issue = Issue.create(user, name="test issue", description="Hey Jon, here's a bug for ya!", project=project)
def search(self): # we might want to have /issues/search just return all issues # that are open in all projects a user is a part of pids = request.args.get('projects').split(",") assert pids projects = Project.all(pids) text = request.args.get('text', "").strip() issues = Issue.search(projects, search_text=text) return success(issues)
def post(self): form = request.form project = Project.get(form['project']) assigned = form.get('assigned', None) if assigned: assigned = User.get(assigned) issue = Issue.create(session.user, form['name'], form['description'], project, assigned=assigned) return success(issue)
def setUpClass(cls): super(IssueListTest, cls).setUpClass() cls.issues = Issue.search(projects=[cls.project1])
def test_text_filter(self): results = Issue.search(projects=[self.project1], search_text="whatever") self.assertEquals(results.total, 1) results = Issue.search(projects=[self.project1], search_text="first") self.assertEquals(results.total, 1)
def test_multiple_projects_filter(self): results = Issue.search(projects=[self.project1, self.project2]) self.assertEquals(results.total, 4)
def test_project_filter(self): # should return 2 issues created on project1 results = Issue.search(projects=[self.project1]) self.assertEquals(results.total, 2)
def get(self, issue): issue = Issue.get(issue) return success(issue)
def to_python(self, value): return Issue.get(value)