Пример #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)
Пример #2
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))
Пример #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)
Пример #4
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)
Пример #5
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)
Пример #6
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)