def test_process_email_persons_subscription(self): subscription_item = self._prep_persons_subscription() parl_ids = [ p['parl_id'] for p in subscription_item.content.get_content() ] for parl_id in parl_ids[:2]: person = Person.objects.get(parl_id=parl_id) person.full_name = u"{}2".format(person.full_name) person.parl_id = u"{}2".format(person.parl_id) person.save() person.mandates = Person.objects.get( parl_id=parl_id).mandates.all() person.save() person = Person.objects.get(parl_id=parl_ids[-1]) person.full_name = u"{}2".format(person.full_name) person.save() call_command('rebuild_index', verbosity=0, interactive=False) check_subscriptions() assert len(mail.outbox) == 1 email = mail.outbox[0] alts = email.alternatives assert len(alts) == 1 assert alts[0][1] == u'text/html' html_text = alts[0][0] assert "2 neue Ergebnisse</li>" in html_text assert "nderte Ergebnisse</li>" in html_text
def test_process_email_empty_person_subscription(self): subscription_item = self._prep_person_subscription() # Test no changes check_subscriptions() assert len(mail.outbox) == 0 # Test changes, but no messages (fields not watched) parl_id = [ p['parl_id'] for p in subscription_item.content.get_content() ][0] person = Person.objects.get(parl_id=parl_id) # Let's test some changes on the primary items changes = { 'reversed_name': "arabraB dnasiertS", } for attr in changes: person.__setattr__(attr, changes[attr]) person.save() call_command('rebuild_index', verbosity=0, interactive=False) check_subscriptions() assert len(mail.outbox) == 0
def test_process_email_laws_subscription(self): subscription_item = self._prep_laws_subscription() parl_ids = [ l['parl_id'] for l in subscription_item.content.get_content() ] for parl_id in parl_ids[:2]: law = Law.objects.get(parl_id=parl_id) law.pk = None law.title = u"{}2".format(law.title) law.parl_id = u"{}2".format(law.parl_id) law.references = None law.save() law = Law.objects.get(parl_id=parl_ids[-1]) law.title = u"{}2".format(law.title) law.save() call_command('rebuild_index', verbosity=0, interactive=False) check_subscriptions() assert len(mail.outbox) == 1 email = mail.outbox[0] alts = email.alternatives assert len(alts) == 1 assert alts[0][1] == u'text/html' html_text = alts[0][0] assert "2 neue Ergebnisse</li>" in html_text assert "ndertes Ergebnis</li>" in html_text
def test_process_email_law_subscription(self): subscription_item = self._prep_law_subscription() parl_id = [ l['parl_id'] for l in subscription_item.content.get_content() ][0] law = Law.objects.get(parl_id=parl_id) # Let's test some changes on the primary items changes = { 'title': "Novelle zur Novelle der Begutachtung des Hohen Hauses", 'description': "Ein ganz tolles neues Gesetz! Frohlocket!", } for attr in changes: law.__setattr__(attr, changes[attr]) new_keywords = Keyword.objects.all()[:5] law.keywords = new_keywords new_opinions = [ op for op in Opinion.objects.all() if op.prelaw != law ][:5] law.opinions = new_opinions new_steps = [] [ new_steps.append(ph.step_set.first()) for ph in Phase.objects.all()[:5] ] for new_step in new_steps: new_step.pk = None new_step.law = law new_step.save() law.save() call_command('rebuild_index', verbosity=0, interactive=False) check_subscriptions() assert len(mail.outbox) == 1 email = mail.outbox[0] alts = email.alternatives assert len(alts) == 1 assert alts[0][1] == u'text/html' html_text = alts[0][0] assert "Es gibt Neuigkeiten" in html_text assert "Gesetze</h2>" in html_text assert changes['title'] in html_text assert changes['description'] in html_text assert u"hat 5 neue Schlagworte:" in html_text assert u"hat 5 neue Stellungnahmen:" in html_text assert u"hat 5 Statusänderungen im parl. Verfahren:" in html_text
def test_process_email_persons_subscription(self): subscription_item = self._prep_persons_subscription() parl_ids = [ p['parl_id'] for p in subscription_item.content.get_content() ] for parl_id in parl_ids[:2]: person = Person.objects.get(parl_id=parl_id) person.full_name = u"{}2".format(person.full_name) person.parl_id = u"{}2".format(person.parl_id) person.save() mandates_to_copy = Person.objects.get( parl_id=parl_id).mandate_set.all() for m in mandates_to_copy: m.person = person m.pk = None m.save() assert ( person.mandate_set.all().count() == mandates_to_copy.count()) exclude_ids = [ x.parl_id.replace('asdf', '') for x in Inquiry.objects.filter(parl_id__contains='asdf') ] inquiry_to_copy = Inquiry.objects.exclude( parl_id__in=exclude_ids)[0] inquiry_to_copy.pk = inquiry_to_copy.id = None inquiry_to_copy.parl_id += 'asdf' inquiry_to_copy.save() inquiry_to_copy.sender.add(person) person = Person.objects.get(parl_id=parl_ids[-1]) person.full_name = u"{}2".format(person.full_name) person.save() call_command('rebuild_index', verbosity=0, interactive=False) check_subscriptions() assert len(mail.outbox) == 1 email = mail.outbox[0] alts = email.alternatives assert len(alts) == 1 assert alts[0][1] == u'text/html' html_text = alts[0][0] assert "2 neue Ergebnisse:" in html_text assert "nderte Ergebnisse:" in html_text
def test_process_email_empty_inquiry_subscription(self): subscription_item = self._prep_inquiry_subscription() # Test no changes check_subscriptions() assert len(mail.outbox) == 0 # Test changes, but no messages (fields not watched) parl_id = [ l['parl_id'] for l in subscription_item.content.get_content() ][0] inquiry = Inquiry.objects.get(parl_id=parl_id) inquiry.save() call_command('rebuild_index', verbosity=0, interactive=False) check_subscriptions() assert len(mail.outbox) == 0
def test_process_email_empty_law_subscription(self): subscription_item = self._prep_law_subscription() # Test no changes check_subscriptions() assert len(mail.outbox) == 0 # Test changes, but no messages (fields not watched) parl_id = [ l['parl_id'] for l in subscription_item.content.get_content() ][0] law = Law.objects.get(parl_id=parl_id) new_category = [ cat for cat in Category.objects.all()[:5] if cat != law.category ][0] law.category = new_category law.save() call_command('rebuild_index', verbosity=0, interactive=False) check_subscriptions() assert len(mail.outbox) == 0
def test_process_email_inquiry_subscription(self): subscription_item = self._prep_inquiry_subscription() parl_id = [ l['parl_id'] for l in subscription_item.content.get_content() ][0] inquiry = Inquiry.objects.get(parl_id=parl_id) # Let's test some changes on the primary items changes = {'response': InquiryResponse.objects.first()} for attr in changes: inquiry.__setattr__(attr, changes[attr]) new_steps = [] [ new_steps.append(ph.step_set.first()) for ph in Phase.objects.all()[:5] ] inquiry.steps = new_steps inquiry.save() call_command('rebuild_index', verbosity=0, interactive=False) check_subscriptions() assert len(mail.outbox) == 1 email = mail.outbox[0] alts = email.alternatives assert len(alts) == 1 assert alts[0][1] == u'text/html' html_text = alts[0][0] assert "Es gibt Neuigkeiten" in html_text assert "Anfragen</h2>" in html_text assert u"hat eine neue Antwort" in html_text
def check_subscriptions(): print "Checking subscriptions" check_subscriptions() return
def test_process_email_empty_persons_subscription(self): subscription_item = self._prep_persons_subscription() # Test no changes check_subscriptions() assert len(mail.outbox) == 0
def test_process_email_person_subscription(self): subscription_item = self._prep_person_subscription() parl_id = [ p['parl_id'] for p in subscription_item.content.get_content() ][0] person = Person.objects.get(parl_id=parl_id) changes = { 'birthdate': datetime.date(1959, 6, 20), 'deathdate': datetime.date(2000, 6, 20), 'full_name': "Barbara Streisand", 'reversed_name': "Streisand, Barbara", 'birthplace': "Buxtehude", 'deathplace': "Wien", 'occupation': "Rechte Reckin", } for attr in changes: person.__setattr__(attr, changes[attr]) changed_mandate = person.mandates.first() changed_mandate.end_date = datetime.date(2026, 1, 1) changed_mandate.start_date = datetime.date(2000, 1, 1) changed_mandate.save() new_mandate = Mandate.objects.filter(~Q( party__short=person.party.short)).all()[0] person.mandates = [new_mandate, changed_mandate] person.latest_mandates = new_mandate person.save() new_statement = DebateStatement.objects.filter(~Q( person_id=person.pk)).first() new_statement.person = person new_statement.save() new_inq_sent = [ i for i in Inquiry.objects.all() if person not in i.sender.all() ][0] new_inq_sent.sender = [person] new_inq_sent.save() new_inq_rec = [ i for i in Inquiry.objects.all() if person != i.receiver ][0] new_inq_rec.receiver = person new_inq_rec.save() new_inq_resp = [ i for i in InquiryResponse.objects.all() if person != i.sender ][0] new_inq_resp.sender = person new_inq_resp.save() # TODO commitee memberships call_command('rebuild_index', verbosity=0, interactive=False) check_subscriptions() assert len(mail.outbox) == 1 email = mail.outbox[0] alts = email.alternatives assert len(alts) == 1 assert alts[0][1] == u'text/html' html_text = alts[0][0] assert "Es gibt Neuigkeiten" in html_text assert "Personen</h2>" in html_text assert "Barbara Streisand</a>" in html_text assert u"hat einen neuen Redeeintr" in html_text assert u"ist verstorben am: 20. 06. 2000</li>" in html_text assert u"hat eine neue parlamentarische Anfrage erhalten</li>" in html_text assert u"hat ein neues und ein ge" in html_text assert u"hat eine neue parlamentarische Anfrage beantwortet</li>" in html_text assert u"hat eine neue parlamentarische Anfrage gestellt</li>" in html_text assert u"hat einen neuen Beruf angegeben: Rechte Reckin</li>" in html_text
def handle(self, *args, **options): check_subscriptions()