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
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
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
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
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
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
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
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
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
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
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
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
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