def setUp(self): user = User.objects.create_user("test", email="*****@*****.**", password="******") self.engage_user = EngageUserProfile(user=user) self.engage_user.save() committee = Committee(name="test") committee.save() self.agenda = Agenda(meeting_time=393939393, committee=committee) self.agenda.save() self.ag_item = AgendaItem(title="test", department="test", agenda=self.agenda) self.ag_item.save()
def setUp(self): for i in range(0, 3): Tag(name="Tag" + str(i)).save() committee = Committee(name="Council") committee.save() agenda = Agenda(meeting_time=949494949, committee=committee) agenda.save() self.agenda_item = AgendaItem(title="test", department="test", agenda=agenda) self.agenda_item.save() self.tagengine = RandomTagEngine()
class TestRandomTagEngine(TestCase): def setUp(self): for i in range(0, 3): Tag(name="Tag" + str(i)).save() committee = Committee(name="Council") committee.save() agenda = Agenda(meeting_time=949494949, committee=committee) agenda.save() self.agenda_item = AgendaItem(title="test", department="test", agenda=agenda) self.agenda_item.save() self.tagengine = RandomTagEngine() def test_engine_applies_tags(self): self.assertEqual(0, len(self.agenda_item.tags.all())) tags_to_apply = self.tagengine.find_tags(self.agenda_item) self.assertEqual(2, len(tags_to_apply)) self.assertNotEqual(tags_to_apply[0].name, tags_to_apply[1].name) self.tagengine.apply_tags(self.agenda_item, tags_to_apply) self.assertEqual(2, len(self.agenda_item.tags.all()))
class TestSendMessageEndpoint(TestCase): def setUp(self): user = User.objects.create_user("test", email="*****@*****.**", password="******") self.engage_user = EngageUserProfile(user=user) self.engage_user.save() committee = Committee(name="test") committee.save() self.agenda = Agenda(meeting_time=393939393, committee=committee) self.agenda.save() self.ag_item = AgendaItem(title="test", department="test", agenda=self.agenda) self.ag_item.save() def test_response(self): self.client.login(username="******", password="******") response = self.client.post("/api/send/message/", data=json.dumps({ "content": "I support that", "ag_item": self.ag_item.pk }), content_type="application/json") self.assertEqual(200, response.status_code) self.assertEqual(1, len(Message.objects.all())) sent_message = Message.objects.first() self.assertEqual("*****@*****.**", sent_message.user.email) self.assertGreater(sent_message.sent, 0) def test_mail_util_func(self): user = self.engage_user.user sent_message = Message(sent=int(datetime.now().timestamp()), content="Hello world", user=user, agenda_item=self.ag_item) sent_message.save() result = send_message(sent_message) self.assertTrue(result)
class TestSendMessageEndpoint(TestCase): def setUp(self): user = User.objects.create_user("test", email="*****@*****.**", password="******") self.engage_user = EngageUserProfile(user=user) self.engage_user.save() committee = Committee(name="test") committee.save() self.agenda = Agenda(meeting_time=393939393, committee=committee) self.agenda.save() self.ag_item = AgendaItem(title="test", department="test", agenda=self.agenda) self.ag_item.save() def test_response(self): self.client.login(username="******", password="******") response = self.client.post("/api/add/message/", data=json.dumps({ "token": "faketoken123", "committee": "test", "pro": 4, "content":"I support that", "ag_item":self.ag_item.pk}), content_type="application/json") self.assertEqual(201, response.status_code) self.assertEqual(1, len(Message.objects.all())) sent_message = Message.objects.first() self.assertEqual("*****@*****.**", sent_message.user.email) self.assertEqual(0, sent_message.sent) ''' Add SES test ''' def test_mail_util_func(self): root_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) static = 'PDF_Reports' full_path = os.path.join(root_dir, static) attachment_file_path = str(full_path) + "/test_pdf_report.pdf" print(attachment_file_path) result = send_mail({'user': {'email': '*****@*****.**'}, 'subject': 'test', 'content': '<html><body>Testing</body></html>', 'attachment_file_path': attachment_file_path, 'attachment_file_name': 'test_pdf_report.pdf'}) self.assertTrue(result)
def test_response(self): tag = Tag(name="Test") tag.save() committee = Committee(name="Council") committee.save() agenda = Agenda(meeting_time=949494949, committee=committee) agenda.save() agenda_item = AgendaItem(title="test", department="test", agenda=agenda ) agenda_item.save() agenda_item.tags.add(tag) agenda_item.save() response = self.client.get("/api/tag/Test/agenda/items/") self.assertEqual(200, response.status_code) self.assertEqual("Test", response.json()['tag']) self.assertEqual(1, len(response.json()['items'])) self.assertEqual("test", response.json()['items'][0]['title'])
def save_agendaitem(self, agenda_item, new_agenda, meeting_time): agendaitem = AgendaItem.objects.filter( agenda_item_id=agenda_item['ID']) if len(agendaitem) == 0: random_tagger = RandomTagEngine() new_agenda_item = AgendaItem() new_agenda_item.department = agenda_item['Department'] new_agenda_item.title = agenda_item['Title'] new_agenda_item.sponsors = agenda_item['Sponsors'] new_agenda_item.meeting_time = meeting_time new_agenda_item.agenda_item_id = agenda_item['ID'] if 'Body' in agenda_item: new_agenda_item.body = agenda_item['Body'] else: new_agenda_item.body = [] new_agenda.save() new_agenda_item.agenda = new_agenda new_agenda_item.save() tags = random_tagger.find_tags(new_agenda_item) random_tagger.apply_tags(new_agenda_item, tags) if 'Recommendations' in agenda_item: new_rec = AgendaRecommendation( recommendation=agenda_item['Recommendations']) new_rec.agenda_item = new_agenda_item new_rec.save()