Ejemplo n.º 1
0
def send_document_expiry_reminder():
    # Find sellers with documents 28 days from expiry, 14 days from expiry, on expiry and 28 days after expiry
    sellers = (suppliers.get_suppliers_with_expiring_documents(days=28) +
               suppliers.get_suppliers_with_expiring_documents(days=14) +
               suppliers.get_suppliers_with_expiring_documents(days=0) +
               suppliers.get_suppliers_with_expiring_documents(days=-28))

    if not sellers:
        return

    try:
        client = get_client()
        send_document_expiry_campaign(client, sellers)
    except Exception as e:
        current_app.logger.error(
            'An error occurred while creating the expiring documents campaign, aborting: {}'.format(e))
        rollbar.report_exc_info()
Ejemplo n.º 2
0
def send_document_expiry_reminder():
    # Find sellers with documents 28 days from expiry, 14 days from expiry, on expiry and 28 days after expiry
    sellers = (suppliers.get_suppliers_with_expiring_documents(days=28) +
               suppliers.get_suppliers_with_expiring_documents(days=14) +
               suppliers.get_suppliers_with_expiring_documents(days=0) +
               suppliers.get_suppliers_with_expiring_documents(days=-28))

    if not sellers:
        return

    try:
        client = get_client()
        send_document_expiry_campaign(client, sellers)
    except Exception as e:
        current_app.logger.error(
            'An error occurred while creating the expiring documents campaign, aborting: {}'.format(e))
        rollbar.report_exc_info()
    def test_get_expired_documents_returns_all_supplier_email_addresses(self, supplier, users):
        expiry_date = date.today() + timedelta(days=10)
        expiry = '{}-{}-{}'.format(expiry_date.year, expiry_date.month, expiry_date.day)

        suppliers_with_expired_documents = suppliers.get_suppliers_with_expiring_documents(days=10)

        email_addresses = suppliers_with_expired_documents[0]['email_addresses']
        assert len(email_addresses) == 4
        assert '*****@*****.**' in email_addresses
        assert '*****@*****.**' in email_addresses
        assert '*****@*****.**' in email_addresses
        assert '*****@*****.**' in email_addresses
    def test_get_expired_documents_removes_duplicate_email_addresses(self, supplier, users):
        expiry_date = date.today() + timedelta(days=10)
        expiry = '{}-{}-{}'.format(expiry_date.year, expiry_date.month, expiry_date.day)

        supplier.data['contact_email'] = '*****@*****.**'
        supplier.data['email'] = '*****@*****.**'

        suppliers_with_expired_documents = suppliers.get_suppliers_with_expiring_documents(days=10)

        email_addresses = suppliers_with_expired_documents[0]['email_addresses']
        assert len(email_addresses) == 2
        assert '*****@*****.**' in email_addresses
        assert '*****@*****.**' in email_addresses
    def test_get_expired_documents_returns_both_liability_and_workers(self, supplier, users):
        expiry_date = date.today() + timedelta(days=10)
        expiry = '{}-{}-{}'.format(expiry_date.year, expiry_date.month, expiry_date.day)

        suppliers_with_expired_documents = suppliers.get_suppliers_with_expiring_documents(days=10)
        assert suppliers_with_expired_documents[0]['documents'] == [
            {
                'expiry': expiry,
                'type': 'liability'
            },
            {
                'expiry': expiry,
                'type': 'workers'
            }
        ]
    def test_get_expired_documents_returns_all_supplier_email_addresses(
            self, supplier, users):
        expiry_date = date.today() + timedelta(days=10)
        expiry = '{}-{}-{}'.format(expiry_date.year, expiry_date.month,
                                   expiry_date.day)

        suppliers_with_expired_documents = suppliers.get_suppliers_with_expiring_documents(
            days=10)

        email_addresses = suppliers_with_expired_documents[0][
            'email_addresses']
        assert len(email_addresses) == 4
        assert '*****@*****.**' in email_addresses
        assert '*****@*****.**' in email_addresses
        assert '*****@*****.**' in email_addresses
        assert '*****@*****.**' in email_addresses
    def test_get_expired_documents_removes_duplicate_email_addresses(
            self, supplier, users):
        expiry_date = date.today() + timedelta(days=10)
        expiry = '{}-{}-{}'.format(expiry_date.year, expiry_date.month,
                                   expiry_date.day)

        supplier.data['contact_email'] = '*****@*****.**'
        supplier.data['email'] = '*****@*****.**'

        suppliers_with_expired_documents = suppliers.get_suppliers_with_expiring_documents(
            days=10)

        email_addresses = suppliers_with_expired_documents[0][
            'email_addresses']
        assert len(email_addresses) == 2
        assert '*****@*****.**' in email_addresses
        assert '*****@*****.**' in email_addresses
Ejemplo n.º 8
0
    def test_get_expired_documents_returns_both_liability_and_workers(
            self, supplier, users):
        expiry_date = date.today() + timedelta(days=10)
        expiry = '{}-{}-{}'.format(expiry_date.year, expiry_date.month,
                                   expiry_date.day)

        suppliers_with_expired_documents = suppliers.get_suppliers_with_expiring_documents(
            days=10)
        assert suppliers_with_expired_documents[0]['documents'] == [{
            'expiry':
            expiry,
            'type':
            'liability'
        }, {
            'expiry':
            expiry,
            'type':
            'workers'
        }]
 def test_get_expired_documents_returns_empty_array_when_no_expired_documents(
         self, supplier, users):
     suppliers_with_expired_documents = suppliers.get_suppliers_with_expiring_documents(
         days=2)
     assert len(suppliers_with_expired_documents) == 0
 def test_get_expired_documents_returns_empty_array_when_no_expired_documents(self, supplier, users):
     suppliers_with_expired_documents = suppliers.get_suppliers_with_expiring_documents(days=2)
     assert len(suppliers_with_expired_documents) == 0