Пример #1
0
    def test_delete_report_removes_report(self):
        report_id = 1234
        test_utils.create_report(report_id=report_id)

        self.post_to_delete_reports(report_id=report_id)

        report = helpers.get_record_from_id(Report, report_id)

        assert not report
Пример #2
0
    def test_create_publication_requires_writer_privileges(self):
        report_id = 111
        test_utils.create_report(report_id=report_id)

        response = self.post_to_create_publication(token_type='viewer',
                                                   report_id=report_id)
        response_dict = json.loads(response.data)

        assert response.status_code == 401
Пример #3
0
    def test_delete_report_requires_writer_privileges(self):
        report_id = 1234
        test_utils.create_report(report_id=report_id)

        self.post_to_delete_reports(report_id=report_id, token_type='viewer')

        report = helpers.get_record_from_id(Report, report_id)

        assert report
Пример #4
0
    def test_create_publication_with_invalid_data(self):
        report_id = 111
        test_utils.create_report(report_id=report_id)

        frequency = ''
        response = self.post_to_create_publication(frequency=frequency,
                                                   report_id=report_id)
        response_dict = json.loads(response.data)

        assert response.status_code == 400
Пример #5
0
    def test_add_usergroup_to_report_with_bad_usergroup_id(self):
        report_id = 1234
        test_utils.create_report(report_id=report_id)

        response = self.patch_to_edit_report(report_id=report_id,
                                             usergroup_ids=[99999])

        report = helpers.get_record_from_id(Report, report_id)

        assert response.status_code == 400
        assert not report.usergroups
Пример #6
0
    def test_get_all_reports_returns_all_reports(self):
        test_utils.create_report(label='ug101')
        test_utils.create_report(label='ug202')

        report_count = len(Report.query.all())

        response = self.get_to_get_all_reports()
        response_dict = json.loads(response.data)
        response_count = len(response_dict['reports'])

        assert response.status_code == 200
        assert report_count == response_count
Пример #7
0
    def test_create_publication_with_valid_data(self):
        with db.session.no_autoflush:
            report_id = 111
            test_utils.create_report(report_id=report_id)

            response = self.post_to_create_publication(report_id=report_id)
            response_dict = json.loads(response.data)

            publication = Publication.query.filter(
                Publication.report_id == report_id).first()

        assert response.status_code == 200
        assert publication
Пример #8
0
    def test_edit_label_with_bad_label(self):
        starting_label = 'test123'
        conn_id = 42
        test_utils.create_report(label=starting_label, report_id=conn_id)

        new_label = ''
        response = self.patch_to_edit_report(label=new_label,
                                             report_id=conn_id)
        response_dict = json.loads(response.data)
        report = helpers.get_record_from_id(Report, conn_id)
        report_label = report.label

        assert report_label == starting_label
Пример #9
0
    def test_edit_label_with_valid_data(self):
        starting_label = 'my_conn'
        conn_id = 42
        test_utils.create_report(label=starting_label, report_id=conn_id)

        new_label = 'my_new_conn'
        response = self.patch_to_edit_report(label=new_label,
                                             report_id=conn_id)
        report = helpers.get_record_from_id(Report, conn_id)
        report_label = report.label

        assert response.status_code == 200
        assert report_label == new_label
Пример #10
0
    def test_add_report_to_usergroup(self):
        usergroup_id = 1234
        test_utils.create_usergroup(usergroup_id=usergroup_id)

        report_id = 42
        test_utils.create_report(report_id=report_id)

        response = self.patch_to_edit_usergroups(usergroup_id=usergroup_id,
                                                 report_ids=[report_id])

        usergroup = helpers.get_record_from_id(Usergroup, usergroup_id)

        assert response.status_code == 200
        assert len(usergroup.reports) == 1
Пример #11
0
    def test_add_usergroup_to_report(self):
        with db.session.no_autoflush:
            usergroup_id = 42
            usergroup = test_utils.create_usergroup(usergroup_id=usergroup_id)

            report_id = 1234
            test_utils.create_report(report_id=report_id)

            response = self.patch_to_edit_report(report_id=report_id,
                                                 usergroup_ids=[usergroup_id])

            report = helpers.get_record_from_id(Report, report_id)

            assert response.status_code == 200
            assert len(report.usergroups) == 1
            assert report.usergroups[0].id == usergroup_id
Пример #12
0
    def test_add_contact_to_publication(self):
        contact_id = 42
        contact = test_utils.create_contact(contact_id=contact_id)

        report_id = 99
        test_utils.create_report(report_id=report_id)

        publication_id = 1234
        test_utils.create_publication(publication_id=publication_id,
                                      report_label='report1111')

        response = self.patch_to_edit_publication(
            publication_id=publication_id, contact_ids=[contact_id])

        publication = helpers.get_record_from_id(Publication, publication_id)

        assert response.status_code == 200
        assert len(publication.recipients) == 1
        assert publication.recipients[0].id == contact_id
Пример #13
0
    def test_get_dict_returns_dict(self):
        pub_type = 'dashboard'
        user = test_utils.create_user(username='******')
        report = test_utils.create_report(label='r1')
        publication = Publication(type=pub_type,
                                  creator=user,
                                  publication_report=report)
        db.session.add(publication)
        db.session.commit()

        publication_dict = publication.get_dict()

        assert isinstance(publication_dict, dict)
        assert publication_dict['publication_id']
        assert publication_dict['type'] == pub_type
        assert publication_dict['creator']['username'] == 'samson'
        assert publication_dict['report_id'] == 1