<commit_before>"""Tests for letsencrypt.account."""
import datetime
import os
import shutil
import stat
import tempfile
import unittest

import mock
import pytz

from acme import jose
from acme import messages

from letsencrypt import errors

from letsencrypt.tests import test_util


KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key_2.pem"))


class AccountTest(unittest.TestCase):
    """Tests for letsencrypt.account.Account."""

    def setUp(self):
        from letsencrypt.account import Account
        self.regr = mock.MagicMock()
        self.meta = Account.Meta(
            creation_host="test.letsencrypt.org",
            creation_dt=datetime.datetime(
                2015, 7, 4, 14, 4, 10, tzinfo=pytz.UTC))
        self.acc = Account(self.regr, KEY, self.meta)

        with mock.patch("letsencrypt.account.socket") as mock_socket:
            mock_socket.getfqdn.return_value = "test.letsencrypt.org"
            with mock.patch("letsencrypt.account.datetime") as mock_dt:
                mock_dt.datetime.now.return_value = self.meta.creation_dt
                self.acc_no_meta = Account(self.regr, KEY)

    def test_init(self):
        self.assertEqual(self.regr, self.acc.regr)
        self.assertEqual(KEY, self.acc.key)
        self.assertEqual(self.meta, self.acc_no_meta.meta)

    def test_id(self):
        self.assertEqual(
            self.acc.id, "2ba35a3bdf380ed76a5ac9e740568395")

    def test_slug(self):
        self.assertEqual(
            self.acc.slug, "test.letsencrypt.org@2015-07-04T14:04:10Z (2ba3)")

    def test_repr(self):
        self.assertEqual(
            repr(self.acc),
            "<Account(2ba35a3bdf380ed76a5ac9e740568395)>")


class ReportNewAccountTest(unittest.TestCase):
    """Tests for letsencrypt.account.report_new_account."""

    def setUp(self):
        self.config = mock.MagicMock(config_dir="/etc/letsencrypt")
        reg = messages.Registration.from_data(email="<EMAIL>")
        self.acc = mock.MagicMock(regr=messages.RegistrationResource(
            uri=None, new_authzr_uri=None, body=reg))

    def _call(self):
        from letsencrypt.account import report_new_account
        report_new_account(self.acc, self.config)

    @mock.patch("letsencrypt.client.zope.component.queryUtility")
    def test_no_reporter(self, mock_zope):
        mock_zope.return_value = None
        self._call()

    @mock.patch("letsencrypt.client.zope.component.queryUtility")
    def test_it(self, mock_zope):
        self._call()
        call_list = mock_zope().add_message.call_args_list
        self.assertTrue(self.config.config_dir in call_list[0][0][0])
        self.assertTrue(
            ", ".join(self.acc.regr.body.emails) in call_list[1][0][0])


class AccountMemoryStorageTest(unittest.TestCase):
    """Tests for letsencrypt.account.AccountMemoryStorage."""

    def setUp(self):
        from letsencrypt.account import AccountMemoryStorage
        self.storage = AccountMemoryStorage()

    def test_it(self):
        account = mock.Mock(id="x")
        self.assertEqual([], self.storage.find_all())
        self.assertRaises(errors.AccountNotFound, self.storage.load, "x")
        self.storage.save(account)
        self.assertEqual([account], self.storage.find_all())
        self.assertEqual(account, self.storage.load("x"))
        self.storage.save(account)
        self.assertEqual([account], self.storage.find_all())<commit_msg>Mock account not client<commit_after>"""Tests for letsencrypt.account."""
import datetime
import os
import shutil
import stat
import tempfile
import unittest

import mock
import pytz

from acme import jose
from acme import messages

from letsencrypt import errors

from letsencrypt.tests import test_util


KEY = jose.JWKRSA.load(test_util.load_vector("rsa512_key_2.pem"))


class AccountTest(unittest.TestCase):
    """Tests for letsencrypt.account.Account."""

    def setUp(self):
        from letsencrypt.account import Account
        self.regr = mock.MagicMock()
        self.meta = Account.Meta(
            creation_host="test.letsencrypt.org",
            creation_dt=datetime.datetime(
                2015, 7, 4, 14, 4, 10, tzinfo=pytz.UTC))
        self.acc = Account(self.regr, KEY, self.meta)

        with mock.patch("letsencrypt.account.socket") as mock_socket:
            mock_socket.getfqdn.return_value = "test.letsencrypt.org"
            with mock.patch("letsencrypt.account.datetime") as mock_dt:
                mock_dt.datetime.now.return_value = self.meta.creation_dt
                self.acc_no_meta = Account(self.regr, KEY)

    def test_init(self):
        self.assertEqual(self.regr, self.acc.regr)
        self.assertEqual(KEY, self.acc.key)
        self.assertEqual(self.meta, self.acc_no_meta.meta)

    def test_id(self):
        self.assertEqual(
            self.acc.id, "2ba35a3bdf380ed76a5ac9e740568395")

    def test_slug(self):
        self.assertEqual(
            self.acc.slug, "test.letsencrypt.org@2015-07-04T14:04:10Z (2ba3)")

    def test_repr(self):
        self.assertEqual(
            repr(self.acc),
            "<Account(2ba35a3bdf380ed76a5ac9e740568395)>")


class ReportNewAccountTest(unittest.TestCase):
    """Tests for letsencrypt.account.report_new_account."""

    def setUp(self):
        self.config = mock.MagicMock(config_dir="/etc/letsencrypt")
        reg = messages.Registration.from_data(email="<EMAIL>")
        self.acc = mock.MagicMock(regr=messages.RegistrationResource(
            uri=None, new_authzr_uri=None, body=reg))

    def _call(self):
        from letsencrypt.account import report_new_account
        report_new_account(self.acc, self.config)

    @mock.patch("letsencrypt.account.zope.component.queryUtility")
    def test_no_reporter(self, mock_zope):
        mock_zope.return_value = None
        self._call()

    @mock.patch("letsencrypt.account.zope.component.queryUtility")
    def test_it(self, mock_zope):
        self._call()
        call_list = mock_zope().add_message.call_args_list
        self.assertTrue(self.config.config_dir in call_list[0][0][0])
        self.assertTrue(
            ", ".join(self.acc.regr.body.emails) in call_list[1][0][0])


class AccountMemoryStorageTest(unittest.TestCase):
    """Tests for letsencrypt.account.AccountMemoryStorage."""

    def setUp(self):
        from letsencrypt.account import AccountMemoryStorage
        self.storage = AccountMemoryStorage()

    def test_it(self):
        account = mock.Mock(id="x")
        self.assertEqual([], self.storage.find_all())
        self.assertRaises(errors.AccountNotFound, self.storage.load, "x")
        self.storage.save(account)
        self.assertEqual([account], self.storage.find_all())
        self.assertEqual(account, self.storage.load("x"))
        self.storage.save(account)
        self.assertEqual([account], self.storage.find_all())
{'fraction_non_alphanumeric': 0.11678832116788321, 'fraction_numerical': 0.022481751824817518, 'mean_word_length': 3.0925925925925926, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4871393', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2153, 'n_words': 360}