def test_main(self, get_supplier_users, find_user_emails):
        supplier_users = {
            100: [{
                'supplier_id': 100,
                'email address': '*****@*****.**'
            }, {
                'supplier_id': 100,
                'email address': '*****@*****.**'
            }]
        }
        framework_services = iter([{'supplierId': 100}])

        self.data_api_client.find_services_iter.return_value = framework_services
        get_supplier_users.return_value = supplier_users
        find_user_emails.return_value = self.LIST_OF_EMAILS
        self.dm_mailchimp_client.get_email_addresses_from_list.return_value = [
            '*****@*****.**'
        ]

        assert main(self.data_api_client, self.dm_mailchimp_client,
                    self.LOT_DATA, self.logger) is True
        self.data_api_client.find_services_iter.assert_called_once_with(
            framework="digital-outcomes-and-specialists-2",
            lot="digital-specialists")
        get_supplier_users.assert_called_once()
        find_user_emails.assert_called_once_with(supplier_users,
                                                 framework_services)
        self.dm_mailchimp_client.get_email_addresses_from_list.assert_called_once_with(
            "my list id")
        self.dm_mailchimp_client.subscribe_new_emails_to_list.assert_called_once_with(
            "my list id", {'*****@*****.**'})
    def test_main_returns_false_if_subscribing_emails_fails(
            self, get_supplier_users, find_user_emails):
        find_user_emails.return_value = self.LIST_OF_EMAILS
        self.dm_mailchimp_client.subscribe_new_emails_to_list.return_value = False

        assert main(self.data_api_client, self.dm_mailchimp_client,
                    self.LOT_DATA, self.logger) is False
        self.dm_mailchimp_client.subscribe_new_emails_to_list.assert_called_once(
        )
        subscribe_new_emails_to_list_call_args = self.dm_mailchimp_client.subscribe_new_emails_to_list.call_args[
            0]
        assert subscribe_new_emails_to_list_call_args[0] == "my list id"
        assert sorted(subscribe_new_emails_to_list_call_args[1]) == sorted(
            self.LIST_OF_EMAILS)
        assert len(subscribe_new_emails_to_list_call_args) == 2
Beispiel #3
0
            'digital-outcomes':
            "5c92c78a78" if stage == "production" else "f0077c516d",
            'user-research-participants':
            "34ebe0bffa" if stage == "production" else "d35601203b",
        },
        'digital-outcomes-and-specialists-4': {
            'digital-specialists':
            "29d06d5201" if stage == "production" else "07c21f0451",
            'digital-outcomes':
            "4360debc5a" if stage == "production" else "f0077c516d",
            'user-research-participants':
            "2538f8a0f1" if stage == "production" else "d35601203b",
        },
    }

    lots = [{
        'lot_slug': lot_slug,
        'list_id': list_ids[framework_slug][lot_slug],
        'framework_slug': framework_slug
    } for lot_slug in LOT_SLUGS]

    api_url = get_api_endpoint_from_stage(stage)
    data_api_client = DataAPIClient(api_url, get_auth_token('api', stage))
    dm_mailchimp_client = DMMailChimpClient(arguments['<mailchimp_username>'],
                                            arguments['<mailchimp_api_key>'],
                                            logger,
                                            retries=3)

    for lot_data in lots:
        main(data_api_client, dm_mailchimp_client, lot_data, logger)