Ejemplo n.º 1
0
    def test_issues_with_labels(self):
        '''
        Test that /api/issues/labels works as expected.
        Should return issues with any of the passed in label names
        '''
        project = ProjectFactory()
        db.session.flush()

        issue = IssueFactory(project_id=project.id)
        issue2 = IssueFactory(project_id=project.id)

        label1 = LabelFactory(name=u'enhancement')
        label2 = LabelFactory(name=u'hack')
        issue.labels = [label1]
        issue2.labels = [label2]

        db.session.commit()

        response = self.app.get('/api/issues/labels/enhancement')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 1)
        self.assertEqual(response['objects'][0]['labels'][0]['name'], u'enhancement')

        response = self.app.get('/api/issues/labels/enhancement,hack')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 0)
Ejemplo n.º 2
0
    def test_organization_issues(self):
        ''' Test getting all of an organization's issues
        '''
        organization = OrganizationFactory(name=u'Civic Project',
                                           type=u'Not a brigade')
        db.session.flush()

        project1 = ProjectFactory(organization_name=organization.name,
                                  name=u'Civic Project 1')
        project2 = ProjectFactory(organization_name=organization.name,
                                  name=u'Civic Project 2')
        db.session.flush()

        IssueFactory(project_id=project1.id, title=u'Civic Issue 1.1')
        IssueFactory(project_id=project1.id, title=u'Civic Issue 1.2')
        IssueFactory(project_id=project2.id, title=u'Civic Issue 2.1')
        db.session.commit()

        response = self.app.get('/api/organizations/{}/issues'.format(
            organization.name))
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 3)

        self.assertTrue(u'Civic Issue 1.1' in
                        [item['title'] for item in response['objects']])
Ejemplo n.º 3
0
    def test_cascading_delete(self):
        '''
        Test that when an organization is deleted, all of its projects, issues, stories, events are deleted
        '''
        # Create an organization
        organization = OrganizationFactory()
        db.session.flush()

        # Create a project, an event and a story
        project = ProjectFactory(organization_name=organization.name)
        EventFactory(organization_name=organization.name)
        StoryFactory(organization_name=organization.name)
        db.session.flush()

        # Create an issue and give it a label
        issue = IssueFactory(project_id=project.id)
        db.session.flush()

        label = LabelFactory()
        issue.labels = [label]
        db.session.flush()

        # Get all of the stuff
        orgs = Organization.query.all()
        eve = Event.query.all()
        sto = Story.query.all()
        proj = Project.query.all()
        iss = Issue.query.all()
        lab = Label.query.all()

        # Verify they are there
        self.assertEqual(len(orgs), 1)
        self.assertEqual(len(eve), 1)
        self.assertEqual(len(sto), 1)
        self.assertEqual(len(proj), 1)
        self.assertEqual(len(iss), 1)
        self.assertEqual(len(lab), 1)

        # Delete the one organization
        db.session.delete(orgs[0])
        db.session.commit()

        # Get all the stuff again
        orgs = Organization.query.all()
        eve = Event.query.all()
        sto = Story.query.all()
        proj = Project.query.all()
        iss = Issue.query.all()
        lab = Label.query.all()

        # Make sure they are all gone
        self.assertEqual(len(orgs), 0)
        self.assertEqual(len(eve), 0)
        self.assertEqual(len(sto), 0)
        self.assertEqual(len(proj), 0)
        self.assertEqual(len(iss), 0)
        self.assertEqual(len(lab), 0)
Ejemplo n.º 4
0
    def test_issues_query_filter(self):
        org1 = OrganizationFactory(name=u'Code for Africa',
                                   type=u'Code for All')
        org2 = OrganizationFactory(name=u'Code for San Francisco',
                                   type=u'Brigade')
        proj = ProjectFactory(type=u'web',
                              organization_name=u'Code for Africa')
        another_proj = ProjectFactory(
            type=u'mobile', organization_name=u'Code for San Francisco')
        db.session.flush()
        awesome_issue = IssueFactory(title=u'Awesome issue',
                                     project_id=proj.id)
        sad_issue = IssueFactory(title=u'Sad issue',
                                 body=u'learning swift is sad',
                                 project_id=another_proj.id)
        db.session.commit()

        # Make sure total number of stories is 2
        response = self.app.get('/api/issues')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 2)

        # Filter by title should return only 1
        response = self.app.get('/api/issues?title=awesome')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 1)
        self.assertEqual(response['objects'][0]['title'], u'Awesome issue')

        # Filter by type should return only 1
        response = self.app.get('/api/issues?body=swift')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 1)
        self.assertEqual(response['objects'][0]['title'], u'Sad issue')

        # Filter by deep searching project type should return 1
        response = self.app.get('/api/issues?project_type=web')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 1)
        self.assertEqual(response['objects'][0]['title'], u'Awesome issue')

        # Filter by deep searching organization type should return 1
        response = self.app.get('/api/issues?organization_type=Code for All')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 1)
        self.assertEqual(response['objects'][0]['title'], u'Awesome issue')

        # Filter by deep searching organization type should return 1
        response = self.app.get('/api/issues?organization_type=Brigade')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 1)
        self.assertEqual(response['objects'][0]['title'], u'Sad issue')
Ejemplo n.º 5
0
    def test_cascading_delete(self):
        '''
        Test that when an organization is deleted, all of its projects, issues, stories, events are deleted
        '''
        # Create an organization
        organization = OrganizationFactory()
        db.session.flush()

        # Create a project, an event and a story
        project = ProjectFactory(organization_name=organization.name)
        EventFactory(organization_name=organization.name)
        StoryFactory(organization_name=organization.name)
        db.session.flush()

        # Create an issue and give it a label
        issue = IssueFactory(project_id=project.id)
        db.session.flush()

        label = LabelFactory()
        issue.labels = [label]
        db.session.flush()

        # Get all of the stuff
        orgs = Organization.query.all()
        eve = Event.query.all()
        sto = Story.query.all()
        proj = Project.query.all()
        iss = Issue.query.all()
        lab = Label.query.all()

        # Verify they are there
        self.assertEqual(len(orgs), 1)
        self.assertEqual(len(eve), 1)
        self.assertEqual(len(sto), 1)
        self.assertEqual(len(proj), 1)
        self.assertEqual(len(iss), 1)
        self.assertEqual(len(lab), 1)

        # Delete the one organization
        db.session.delete(orgs[0])
        db.session.commit()

        # Get all the stuff again
        orgs = Organization.query.all()
        eve = Event.query.all()
        sto = Story.query.all()
        proj = Project.query.all()
        iss = Issue.query.all()
        lab = Label.query.all()

        # Make sure they are all gone
        self.assertEqual(len(orgs), 0)
        self.assertEqual(len(eve), 0)
        self.assertEqual(len(sto), 0)
        self.assertEqual(len(proj), 0)
        self.assertEqual(len(iss), 0)
        self.assertEqual(len(lab), 0)
Ejemplo n.º 6
0
    def test_issue_cascading_deletes(self):
        ''' Test that labels get deleted when their parent
            issue, project, and org is deleted
        '''

        # set up test objects and delete an issue
        organization = OrganizationFactory(name=u'TEST ORG')
        db.session.flush()

        project = ProjectFactory(organization_name=organization.name,
                                 name=u'TEST PROJECT')
        db.session.flush()

        issue = IssueFactory(title=u'TEST ISSUE', project_id=project.id)
        db.session.flush()

        label = LabelFactory(issue_id=issue.id)
        db.session.flush()

        db.session.execute('DELETE FROM issue')
        db.session.commit()
        labels = db.session.query(Label).all()
        self.assertFalse(len(labels))

        # delete a project
        issue = IssueFactory(title=u'TEST ISSUE', project_id=project.id)
        db.session.flush()

        label = LabelFactory(issue_id=issue.id)
        db.session.flush()

        db.session.execute('DELETE FROM project')
        db.session.commit()
        labels = db.session.query(Label).all()
        self.assertFalse(len(labels))

        # delete an organization
        project = ProjectFactory(organization_name=organization.name,
                                 name=u'TEST PROJECT')
        db.session.flush()

        issue = IssueFactory(title=u'TEST ISSUE', project_id=project.id)
        db.session.flush()

        label = LabelFactory(issue_id=issue.id)
        db.session.flush()

        db.session.execute('DELETE FROM organization')
        db.session.commit()
        labels = db.session.query(Label).all()
        self.assertFalse(len(labels))
Ejemplo n.º 7
0
    def test_spaces_in_issues_requests_list(self):
        ''' Test that spaces in the list of labels works
        '''
        # Set up an issue with labels
        # Try requesting it with spaces in the request
        # Assert that it returns
        organization = OrganizationFactory()
        db.session.commit()
        project = ProjectFactory(organization_name=organization.name)
        db.session.commit()
        issue = IssueFactory(project_id=project.id)
        db.session.commit()
        hw_label = LabelFactory(name=u'help wanted', issue_id=issue.id)
        bug_label = LabelFactory(name=u'bug', issue_id=issue.id)
        db.session.commit()

        # Test that help wanted works
        response = self.app.get('/api/issues/labels/help wanted')
        response = json.loads(response.data)
        self.assertEqual(len(response['objects']), 1)

        # Test that help wanted, bug works
        response = self.app.get('/api/issues/labels/help wanted, bug')
        response = json.loads(response.data)
        self.assertEqual(len(response['objects']), 1)
Ejemplo n.º 8
0
    def test_issues_with_labels(self):
        '''
        Test that /api/issues/labels works as expected.
        Should return issues with any of the passed in label names
        '''
        project = ProjectFactory()
        db.session.flush()

        issue = IssueFactory(project_id=project.id)
        issue2 = IssueFactory(project_id=project.id)

        label1 = LabelFactory(name=u'enhancement')
        label2 = LabelFactory(name=u'hack')
        issue.labels = [label1]
        issue2.labels = [label2]

        db.session.commit()

        response = self.app.get('/api/issues/labels/enhancement')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 1)
        self.assertEqual(response['objects'][0]['labels'][0]['name'],
                         u'enhancement')

        response = self.app.get('/api/issues/labels/enhancement,hack')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 0)
Ejemplo n.º 9
0
    def test_create_child_without_parent(self):
        ''' Test that children created without parents cannot be committed to the database
        '''
        test_passed = False
        project = ProjectFactory(organization_name=None)
        try:
            db.session.commit()
        except IntegrityError:
            test_passed = True

        self.assertTrue(test_passed)
        db.session.rollback()

        test_passed = False
        story = StoryFactory(organization_name=None)
        try:
            db.session.commit()
        except IntegrityError:
            test_passed = True

        self.assertTrue(test_passed)
        db.session.rollback()

        test_passed = False
        event = EventFactory(organization_name=None)
        try:
            db.session.commit()
        except IntegrityError:
            test_passed = True

        self.assertTrue(test_passed)
        db.session.rollback()

        test_passed = False
        issue = IssueFactory(project_id=None)
        try:
            db.session.commit()
        except IntegrityError:
            test_passed = True

        self.assertTrue(test_passed)
        db.session.rollback()

        test_passed = False
        label = LabelFactory(issue_id=None)
        try:
            db.session.commit()
        except IntegrityError:
            test_passed = True

        self.assertTrue(test_passed)
Ejemplo n.º 10
0
    def test_org_dont_show_issues(self):
        ''' Test that calls to /organizations dont return project issues '''
        from test.factories import OrganizationFactory, ProjectFactory, IssueFactory
        organization = OrganizationFactory()
        db.session.flush()

        project = ProjectFactory(organization_name=organization.name)
        db.session.flush()

        issue = IssueFactory(project_id=project.id)
        db.session.commit()

        response = self.app.get('/api/organizations')
        response = json.loads(response.data)
        for org in response['objects']:
            if org['current_projects']:
                self.assertFalse(isinstance(org['current_projects'][0]["issues"], list))
                break
Ejemplo n.º 11
0
    def test_project_cascading_deletes(self):
        ''' Test that issues get deleted when their parent
            project and org is deleted
        '''

        # set up test objects and delete a project
        organization = OrganizationFactory(name=u'TEST ORG')
        db.session.flush()

        project = ProjectFactory(organization_name=organization.name,
                                 name=u'TEST PROJECT')
        db.session.flush()

        issue = IssueFactory(title=u'TEST ISSUE', project_id=project.id)
        another_issue = IssueFactory(title=u'ANOTHER TEST ISSUE',
                                     project_id=project.id)
        a_third_issue = IssueFactory(title=u'A THIRD TEST ISSUE',
                                     project_id=project.id)
        db.session.commit()

        # make sure the issues are in the db
        issues = db.session.query(Issue).all()
        self.assertTrue(len(issues) == 3)

        db.session.execute('DELETE FROM project')
        db.session.commit()
        issues = db.session.query(Issue).all()
        self.assertFalse(len(issues))

        # delete an organization
        project = ProjectFactory(organization_name=organization.name,
                                 name=u'TEST PROJECT')
        db.session.flush()

        issue = IssueFactory(title=u'TEST ISSUE', project_id=project.id)
        another_issue = IssueFactory(title=u'ANOTHER TEST ISSUE',
                                     project_id=project.id)
        a_third_issue = IssueFactory(title=u'A THIRD TEST ISSUE',
                                     project_id=project.id)
        db.session.add(issue)
        db.session.add(another_issue)
        db.session.add(a_third_issue)
        db.session.commit()

        # make sure the issues are in the db
        issues = db.session.query(Issue).all()
        self.assertTrue(len(issues) == 3)

        db.session.execute('DELETE FROM organization')
        db.session.commit()
        issues = db.session.query(Issue).all()
        self.assertFalse(len(issues))
Ejemplo n.º 12
0
    def test_issues(self):
        '''
        Test that issues have everything we expect.
        Make sure linked issues are not included in the linked project
        '''
        organization = OrganizationFactory()
        db.session.add(organization)
        db.session.commit()
        project = ProjectFactory(organization_name=organization.name)
        db.session.add(project)
        db.session.commit()
        issue = IssueFactory(project_id=project.id,
                             title=u'TEST ISSUE',
                             body=u'TEST ISSUE BODY',
                             created_at="2013-06-06T00:12:30Z",
                             updated_at="2014-02-21T20:43:16Z")
        db.session.add(issue)
        db.session.commit()

        response = self.app.get('/api/issues', follow_redirects=True)
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)

        self.assertEqual(response['total'], 1)
        self.assertEqual(response['objects'][0]['title'], u'TEST ISSUE')
        self.assertEqual(response['objects'][0]['body'], u'TEST ISSUE BODY')
        self.assertEqual(response['objects'][0]['created_at'],
                         u'2013-06-06T00:12:30Z')
        self.assertEqual(response['objects'][0]['updated_at'],
                         u'2014-02-21T20:43:16Z')

        # Check for linked issues in linked project
        self.assertTrue('project' in response['objects'][0])
        self.assertFalse('issues' in response['objects'][0])

        # Check that project_id is hidden
        self.assertTrue('project_id' not in response['objects'][0])

        # Check for linked project issues on single issue
        response = self.app.get('/api/issues/1', follow_redirects=True)
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertTrue('project' in response)
Ejemplo n.º 13
0
    def test_include_issues(self):
        """ Test the include_issues flag """
        project = ProjectFactory()
        db.session.commit()
        IssueFactory(project_id=project.id)
        db.session.commit()

        got = self.app.get("/api/projects?include_issues=True")
        project = json.loads(got.data)['objects'][0]
        self.assertTrue(isinstance(project['issues'], list))
        got = self.app.get("/api/projects?include_issues=False")
        project = json.loads(got.data)['objects'][0]
        self.assertFalse(isinstance(project['issues'], list))
        self.assertEqual("http://localhost/api/projects/1/issues",
                         project["issues"])
        got = self.app.get("/api/projects")
        project = json.loads(got.data)['objects'][0]
        self.assertFalse(isinstance(project['issues'], list))
        self.assertEqual("http://localhost/api/projects/1/issues",
                         project["issues"])
Ejemplo n.º 14
0
    def test_set_childs_parent_association_null(self):
        ''' Test that a child's parent association cannot be deleted
        '''

        test_passed = False
        project = ProjectFactory()
        db.session.commit()
        setattr(project, 'organization_name', None)
        try:
            db.session.commit()
        except IntegrityError:
            test_passed = True

        self.assertTrue(test_passed)
        db.session.rollback()

        test_passed = False
        story = StoryFactory()
        db.session.commit()
        setattr(story, 'organization_name', None)
        try:
            db.session.commit()
        except IntegrityError:
            test_passed = True

        self.assertTrue(test_passed)
        db.session.rollback()

        test_passed = False
        event = EventFactory()
        db.session.commit()
        setattr(event, 'organization_name', None)
        try:
            db.session.commit()
        except IntegrityError:
            test_passed = True

        self.assertTrue(test_passed)
        db.session.rollback()

        test_passed = False
        project = ProjectFactory()
        db.session.flush()
        issue = IssueFactory(project_id=project.id)
        db.session.commit()
        setattr(issue, 'project_id', None)
        try:
            db.session.commit()
        except IntegrityError:
            test_passed = True

        self.assertTrue(test_passed)
        db.session.rollback()

        test_passed = False
        project = ProjectFactory()
        db.session.flush()
        issue = IssueFactory(project_id=project.id)
        db.session.flush()
        label = LabelFactory(issue_id=issue.id)
        db.session.commit()
        setattr(label, 'issue_id', None)
        try:
            db.session.commit()
        except IntegrityError:
            test_passed = True

        self.assertTrue(test_passed)
Ejemplo n.º 15
0
    def test_org_issues_filtered_by_label(self):
        ''' An organization's issues, filtered by label, are returned as expected.
        '''
        org1 = OrganizationFactory(name=u'Civic Organization')
        db.session.flush()

        project1 = ProjectFactory(organization_name=org1.name, name=u'Civic Project 1')
        db.session.flush()

        issue1 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.1')
        issue2 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.2')
        issue3 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.3')
        issue4 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.4')
        issue5 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.5')
        issue6 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.6')
        issue7 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.7')
        issue8 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.8')
        issue9 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.9')
        issue10 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.10')
        issue11 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.11')
        issue12 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.12')
        issue13 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.13')
        issue14 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.14')
        issue15 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.15')
        issue16 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.16')
        issue17 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.17')
        issue18 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.18')
        issue19 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.19')
        issue20 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.20')
        issue21 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.21')
        issue22 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.22')
        issue23 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.23')
        issue24 = IssueFactory(project_id=project1.id, title=u'Civic Issue 1.24')
        db.session.flush()

        label1 = LabelFactory(issue_id=issue1.id, name=u'bug')
        label2 = LabelFactory(issue_id=issue2.id, name=u'enhancement')
        label3 = LabelFactory(issue_id=issue3.id, name=u'bug')
        label4 = LabelFactory(issue_id=issue4.id, name=u'enhancement')
        label5 = LabelFactory(issue_id=issue5.id, name=u'bug')
        label6 = LabelFactory(issue_id=issue6.id, name=u'enhancement')
        label7 = LabelFactory(issue_id=issue7.id, name=u'bug')
        label8 = LabelFactory(issue_id=issue8.id, name=u'enhancement')
        label9 = LabelFactory(issue_id=issue9.id, name=u'bug')
        label10 = LabelFactory(issue_id=issue10.id, name=u'enhancement')
        label11 = LabelFactory(issue_id=issue11.id, name=u'bug')
        label12 = LabelFactory(issue_id=issue12.id, name=u'enhancement')
        label13 = LabelFactory(issue_id=issue13.id, name=u'bug')
        label14 = LabelFactory(issue_id=issue14.id, name=u'enhancement')
        label15 = LabelFactory(issue_id=issue15.id, name=u'bug')
        label16 = LabelFactory(issue_id=issue16.id, name=u'enhancement')
        label17 = LabelFactory(issue_id=issue17.id, name=u'bug')
        label18 = LabelFactory(issue_id=issue18.id, name=u'enhancement')
        label19 = LabelFactory(issue_id=issue19.id, name=u'bug')
        label20 = LabelFactory(issue_id=issue20.id, name=u'enhancement')
        label21 = LabelFactory(issue_id=issue21.id, name=u'bug')
        label22 = LabelFactory(issue_id=issue22.id, name=u'enhancement')
        label23 = LabelFactory(issue_id=issue23.id, name=u'bug')
        label24 = LabelFactory(issue_id=issue24.id, name=u'enhancement')
        db.session.commit()

        # get project 4's issues twice and compare results; there should
        # be results and they should be randomized
        response = self.app.get('/api/organizations/{}/issues/labels/{}?per_page=12'.format(org1.name, label1.name))
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 12)
        ids_round_one = [item['id'] for item in response['objects']]
        self.assertTrue(label1.id in ids_round_one)
        self.assertTrue(label3.id in ids_round_one)
        self.assertTrue(label5.id in ids_round_one)
        self.assertTrue(label7.id in ids_round_one)
        self.assertTrue(label9.id in ids_round_one)
        self.assertTrue(label11.id in ids_round_one)
        self.assertTrue(label13.id in ids_round_one)
        self.assertTrue(label15.id in ids_round_one)
        self.assertTrue(label17.id in ids_round_one)
        self.assertTrue(label19.id in ids_round_one)
        self.assertTrue(label21.id in ids_round_one)
        self.assertTrue(label23.id in ids_round_one)

        response = self.app.get('/api/organizations/{}/issues/labels/{}?per_page=12'.format(org1.name, label1.name))
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 12)
        ids_round_two = [item['id'] for item in response['objects']]
        self.assertTrue(label1.id in ids_round_two)
        self.assertTrue(label3.id in ids_round_two)
        self.assertTrue(label5.id in ids_round_two)
        self.assertTrue(label7.id in ids_round_two)
        self.assertTrue(label9.id in ids_round_two)
        self.assertTrue(label11.id in ids_round_two)
        self.assertTrue(label13.id in ids_round_two)
        self.assertTrue(label15.id in ids_round_two)
        self.assertTrue(label17.id in ids_round_two)
        self.assertTrue(label19.id in ids_round_two)
        self.assertTrue(label21.id in ids_round_two)
        self.assertTrue(label23.id in ids_round_two)

        self.assertTrue(ids_round_one != ids_round_two)
Ejemplo n.º 16
0
    def test_issues_returned_randomly(self):
        ''' Issues are returned in random order by default
        '''
        org1 = OrganizationFactory(name=u'Civic Organization')
        org2 = OrganizationFactory(name=u'Institute of Institutions')
        db.session.flush()

        project1 = ProjectFactory(organization_name=org1.name, name=u'Civic Project 1')
        project2 = ProjectFactory(organization_name=org1.name, name=u'Civic Project 2')
        project3 = ProjectFactory(organization_name=org1.name, name=u'Civic Project 3')
        project4 = ProjectFactory(organization_name=org2.name, name=u'Civic Project A')
        project5 = ProjectFactory(organization_name=org2.name, name=u'Civic Project B')
        db.session.flush()

        IssueFactory(project_id=project1.id, title=u'Civic Issue 1.1')
        IssueFactory(project_id=project2.id, title=u'Civic Issue 2.1')
        IssueFactory(project_id=project3.id, title=u'Civic Issue 3.1')
        IssueFactory(project_id=project4.id, title=u'Civic Issue 4.1')
        IssueFactory(project_id=project5.id, title=u'Civic Issue 5.1')
        IssueFactory(project_id=project3.id, title=u'Civic Issue 3.2')
        IssueFactory(project_id=project4.id, title=u'Civic Issue 4.2')
        IssueFactory(project_id=project4.id, title=u'Civic Issue 4.3')
        IssueFactory(project_id=project4.id, title=u'Civic Issue 4.4')
        IssueFactory(project_id=project4.id, title=u'Civic Issue 4.5')
        IssueFactory(project_id=project4.id, title=u'Civic Issue 4.6')
        IssueFactory(project_id=project5.id, title=u'Civic Issue 5.2')
        IssueFactory(project_id=project1.id, title=u'Civic Issue 1.2')
        IssueFactory(project_id=project2.id, title=u'Civic Issue 2.2')
        IssueFactory(project_id=project3.id, title=u'Civic Issue 3.3')
        IssueFactory(project_id=project4.id, title=u'Civic Issue 4.7')
        IssueFactory(project_id=project5.id, title=u'Civic Issue 5.3')
        IssueFactory(project_id=project3.id, title=u'Civic Issue 3.4')
        IssueFactory(project_id=project4.id, title=u'Civic Issue 4.8')
        IssueFactory(project_id=project4.id, title=u'Civic Issue 4.9')
        IssueFactory(project_id=project4.id, title=u'Civic Issue 4.10')
        IssueFactory(project_id=project4.id, title=u'Civic Issue 4.11')
        IssueFactory(project_id=project4.id, title=u'Civic Issue 4.12')
        IssueFactory(project_id=project5.id, title=u'Civic Issue 5.4')
        db.session.commit()

        # get all the issues twice and compare results
        response = self.app.get('/api/issues?per_page=24')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 24)
        ids_round_one = [item['id'] for item in response['objects']]

        response = self.app.get('/api/issues?per_page=24')
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 24)
        ids_round_two = [item['id'] for item in response['objects']]

        self.assertTrue(ids_round_one != ids_round_two)

        # get project 4's issues twice and compare results
        response = self.app.get('/api/organizations/{}/issues?per_page=16'.format(project4.organization_name))
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 16)
        ids_round_three = [item['id'] for item in response['objects']]

        response = self.app.get('/api/organizations/{}/issues?per_page=16'.format(project4.organization_name))
        self.assertEqual(response.status_code, 200)
        response = json.loads(response.data)
        self.assertEqual(response['total'], 16)
        ids_round_four = [item['id'] for item in response['objects']]

        self.assertTrue(ids_round_three != ids_round_four)