"""Test the DigitalOcean backed ACME DNS Authentication Class."""

from acmednsauth.authenticate import Authenticate
from mock import call


def test_valid_data_calls_digital_ocean_record_creation(
        mocker, api_key, hostname, domain, fqdn, auth_token):
    create_environment = {
        'DO_API_KEY': api_key,
        'DO_DOMAIN': domain,
        'CERTBOT_DOMAIN': fqdn,
        'CERTBOT_VALIDATION': auth_token,
    }

    record = mocker.patch('acmednsauth.authenticate.Record')

    Authenticate(environment=create_environment)

    record.assert_called_once_with(api_key, domain, hostname)
    record.has_calls([call().create(auth_token)])

"""Test the DigitalOcean backed ACME DNS Authentication Class."""

from acmednsauth.authenticate import Authenticate
from mock import call


def test_valid_data_calls_digital_ocean_record_creation(
        mocker, api_key, hostname, domain, fqdn, auth_token):
    create_environment = {
        'DO_API_KEY': api_key,
        'DO_DOMAIN': domain,
        'CERTBOT_DOMAIN': fqdn,
        'CERTBOT_VALIDATION': auth_token,
    }

    record = mocker.patch('acmednsauth.authenticate.Record')

    Authenticate(environment=create_environment)

    record.assert_called_once_with(api_key, domain, hostname)
    assert call().create(auth_token) in record.mock_calls

Fix Bug in Test Assertion
Fix Bug in Test Assertion

Need to train myself better on red-green-refactor. The previous assert
always passed, because I wasn't triggering an actual Mock method. I had
to change to verifying that the call is in the list of calls. I've
verified that it fails when the call isn't made from the code under
test and that it passes when it is.

  """Test the DigitalOcean backed ACME DNS Authentication Class."""
  
  from acmednsauth.authenticate import Authenticate
  from mock import call
  
  
  def test_valid_data_calls_digital_ocean_record_creation(
          mocker, api_key, hostname, domain, fqdn, auth_token):
      create_environment = {
          'DO_API_KEY': api_key,
          'DO_DOMAIN': domain,
          'CERTBOT_DOMAIN': fqdn,
          'CERTBOT_VALIDATION': auth_token,
      }
  
      record = mocker.patch('acmednsauth.authenticate.Record')
  
      Authenticate(environment=create_environment)
  
      record.assert_called_once_with(api_key, domain, hostname)
-     record.has_calls([call().create(auth_token)])
+     assert call().create(auth_token) in record.mock_calls
  
Fix Bug in Test Assertion
## Code Before:
"""Test the DigitalOcean backed ACME DNS Authentication Class."""

from acmednsauth.authenticate import Authenticate
from mock import call


def test_valid_data_calls_digital_ocean_record_creation(
        mocker, api_key, hostname, domain, fqdn, auth_token):
    create_environment = {
        'DO_API_KEY': api_key,
        'DO_DOMAIN': domain,
        'CERTBOT_DOMAIN': fqdn,
        'CERTBOT_VALIDATION': auth_token,
    }

    record = mocker.patch('acmednsauth.authenticate.Record')

    Authenticate(environment=create_environment)

    record.assert_called_once_with(api_key, domain, hostname)
    record.has_calls([call().create(auth_token)])

## Instruction:
Fix Bug in Test Assertion
## Code After:
"""Test the DigitalOcean backed ACME DNS Authentication Class."""

from acmednsauth.authenticate import Authenticate
from mock import call


def test_valid_data_calls_digital_ocean_record_creation(
        mocker, api_key, hostname, domain, fqdn, auth_token):
    create_environment = {
        'DO_API_KEY': api_key,
        'DO_DOMAIN': domain,
        'CERTBOT_DOMAIN': fqdn,
        'CERTBOT_VALIDATION': auth_token,
    }

    record = mocker.patch('acmednsauth.authenticate.Record')

    Authenticate(environment=create_environment)

    record.assert_called_once_with(api_key, domain, hostname)
    assert call().create(auth_token) in record.mock_calls
