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()
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 test_db(self): committee = Committee(name="test") committee.save() Agenda(meeting_time=393939393, committee=committee).save() response = self.client.get("/api/agendas.json") self.assertEqual(200, response.status_code) result_dict = response.json() self.assertEqual(1, len(result_dict['results']))
def handle(self, *args, **options): try: committee = Committee.objects.get(name="Santa Monica City Council") except ObjectDoesNotExist: Committee(name="Santa Monica City Council", email="*****@*****.**").save() committee = Committee.objects.get(name="Santa Monica City Council") years = [2016,2017,2018] agendas = dict() for year in years: agenda_values = get_data(year=year) for time, agenda in agenda_values.items(): agendas[time] = agenda for meeting_time, agenda in agendas.items(): exists = Agenda.objects.filter(meeting_time = meeting_time).first() if (not exists): new_agenda = Agenda(meeting_time = meeting_time) new_agenda.committee = committee for ag in agenda: self.save_agendaitem(ag, new_agenda, meeting_time) new_agenda.save()
def processAgendasForYears(years, committee_name): try: committee = Committee.objects.get(name=committee_name) except ObjectDoesNotExist: committee = Committee(name="Santa Monica City Council", email="*****@*****.**", cutoff_offset_days=0, cutoff_hour=11, cutoff_minute=59, location_lat=34.024212, location_lng=-118.496475, location_tz="America/Los_Angeles") committee.save() for year in years: agenda_values = get_data(year=year) if agenda_values is None: print(f"No agendas/items for {year}") continue for time, agenda in agenda_values.items(): if len(agenda) > 0: found_agenda = Agenda.objects.filter(meeting_time=time).first() if found_agenda is None: found_agenda = Agenda(meeting_time=time) found_agenda.committee = committee found_agenda.meeting_id = agenda[0]['MeetingID'] for ag_item in agenda: save_agendaitem(ag_item, found_agenda, time) found_agenda.save()
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 processAgendasForYears(years, committee_name): try: committee = Committee.objects.get(name=committee_name) except ObjectDoesNotExist: committee = Committee(name="Santa Monica City Council", email="*****@*****.**", cutoff_offset_days=0, cutoff_hour=11, cutoff_minute=59, location_lat=34.024212, location_lng=-118.496475, location_tz="America/Los_Angeles") committee.save() for year in years: agenda_values = get_data(year=year) if agenda_values is None: print(f"No agendas/items for {year}") continue for time, agenda in agenda_values.items(): if len(agenda) > 0: found_agenda = Agenda.objects.filter( meeting_time=time).first() print(found_agenda) if found_agenda is None: found_agenda = Agenda(meeting_time=time) found_agenda.committee = committee found_agenda.meeting_id = agenda[0]['MeetingID'] dt = getLocationBasedDate(found_agenda.meeting_time, committee.cutoff_offset_days, committee.cutoff_hour, committee.cutoff_minute, committee.location_tz) dt = dt + timedelta(minutes=5) log.error(f"scheduling pdf processing for: {dt} for: {committee.name}") dt_utc = datetime.fromtimestamp(dt.timestamp(), tz=pytz.timezone('UTC')) exists = r.get(f"{committee.name}-{found_agenda.meeting_time}") found_agenda.save() if exists is None: r.set(f"{committee.name}-{found_agenda.meeting_time}", True, ex=3*60) schedule_process_pdf.apply_async( (committee.name, found_agenda.meeting_id), eta=dt_utc) log.error(f"scheduled pdf processing") else: log.error(f'{committee.name} {found_agenda.meeting_id} already queued for pdf in utils') for ag_item in agenda: save_agendaitem(ag_item, found_agenda, time) found_agenda.save()
def handle(self, *args, **options): try: committee = Committee.objects.get(name="Santa Monica City Council") except ObjectDoesNotExist: Committee(name="Santa Monica City Council", email="*****@*****.**").save() committee = Committee.objects.get(name="Santa Monica City Council") years = [2016, 2017, 2018] for year in years: agenda_values = get_data(year=year) for time, agenda in agenda_values.items(): if len(agenda) > 0: found_agenda = Agenda.objects.filter( meeting_time=time).first() if found_agenda is None: found_agenda = Agenda(meeting_time=time) found_agenda.committee = committee found_agenda.meeting_id = agenda[0]['MeetingID'] for ag_item in agenda: self.save_agendaitem(ag_item, found_agenda, time) found_agenda.save()
def setUp(self): committee = Committee(name="Council") committee.save() agenda = Agenda(meeting_time=1518571800, committee=committee) agenda.save()