<commit_before>from twisted.internet.defer import inlineCallbacks

from vumi.tests.helpers import VumiTestCase, PersistenceHelper

from go.vumitools.account.models import AccountStore
from go.vumitools.contact.old_models import (
    ContactStoreVNone, ContactStoreV1)


class TestContact(VumiTestCase):

    @inlineCallbacks
    def setUp(self):
        self.persistence_helper = self.add_helper(
            PersistenceHelper(use_riak=True))
        riak_manager = self.persistence_helper.get_riak_manager()
        self.account_store = AccountStore(riak_manager)
        self.user = yield self.account_store.new_user(u'testuser')

        # Some old stores for testing migrations.
        self.contacts_store_vnone = ContactStoreVNone(
            riak_manager, self.user.key)
        # Some old stores for testing migrations.
        self.contacts_store_v1 = ContactStoreV1(
            riak_manager, self.user.key)

    @inlineCallbacks
    def test_contact_vnone(self):
        contact = yield self.contacts_store_vnone.new_contact(
            name=u'name', msisdn=u'msisdn')
        self.assertEqual(contact.name, 'name')
        self.assertEqual(contact.msisdn, 'msisdn')

    @inlineCallbacks
    def test_contact_v1(self):
        contact = yield self.contacts_store_v1.new_contact(
            msisdn=u'msisdn', mxit_id=u'mxit', wechat_id=u'wechat')
        self.assertEqual(contact.msisdn, 'msisdn')
        self.assertEqual(contact.mxit_id, 'mxit')
        self.assertEqual(contact.wechat_id, 'wechat')<commit_msg>test for vnone to v1 (thanks @hodgestar)<commit_after>from twisted.internet.defer import inlineCallbacks

from vumi.tests.helpers import VumiTestCase, PersistenceHelper

from go.vumitools.account.models import AccountStore
from go.vumitools.contact.old_models import (
    ContactStoreVNone, ContactStoreV1)


class TestContact(VumiTestCase):

    @inlineCallbacks
    def setUp(self):
        self.persistence_helper = self.add_helper(
            PersistenceHelper(use_riak=True))
        riak_manager = self.persistence_helper.get_riak_manager()
        self.account_store = AccountStore(riak_manager)
        self.user = yield self.account_store.new_user(u'testuser')

        # Some old stores for testing migrations.
        self.contacts_store_vnone = ContactStoreVNone(
            riak_manager, self.user.key)
        # Some old stores for testing migrations.
        self.contacts_store_v1 = ContactStoreV1(
            riak_manager, self.user.key)

    @inlineCallbacks
    def test_contact_vnone(self):
        contact = yield self.contacts_store_vnone.new_contact(
            name=u'name', msisdn=u'msisdn')
        self.assertEqual(contact.name, 'name')
        self.assertEqual(contact.msisdn, 'msisdn')

    @inlineCallbacks
    def test_contact_vnone_to_v1(self):
        contact_vnone = yield self.contacts_store_vnone.new_contact(
            name=u'name', msisdn=u'msisdn')
        contact_v1 = yield self.contacts_store_v1.get_contact_by_key(
            contact_vnone.key)
        self.assertEqual(contact_v1.name, 'name')
        self.assertEqual(contact_v1.msisdn, 'msisdn')
        self.assertEqual(contact_v1.mxit_id, None)
        self.assertEqual(contact_v1.wechat_id, None)

    @inlineCallbacks
    def test_contact_v1(self):
        contact = yield self.contacts_store_v1.new_contact(
            msisdn=u'msisdn', mxit_id=u'mxit', wechat_id=u'wechat')
        self.assertEqual(contact.msisdn, 'msisdn')
        self.assertEqual(contact.mxit_id, 'mxit')
        self.assertEqual(contact.wechat_id, 'wechat')
{'fraction_non_alphanumeric': 0.0911129800953182, 'fraction_numerical': 0.005046257359125316, 'mean_word_length': 3.377914110429448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1360598', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1134, 'n_words': 185}