<commit_before>from casepro.contacts.models import Contact, Field, Group
from casepro.msgs.models import Label, Message
from casepro.test import BaseCasesTest
from django.test import override_settings
import json
import responses

from ..junebug import IdentityStore, JunebugBackend, JunebugMessageSendingError


class JunebugBackendTest(BaseCasesTest):
    def setUp(self):
        super(JunebugBackendTest, self).setUp()
        self.backend = JunebugBackend()

    def test_pull_contacts(self):
        '''
        Pulling all of the contacts should be a noop.
        '''
        Contact.objects.all().delete()

        (created, updated, deleted, ignored) = self.backend.pull_contacts(
            self.unicef, None, None)

        self.assertEqual(created, 0)
        self.assertEqual(updated, 0)
        self.assertEqual(deleted, 0)
        self.assertEqual(ignored, 0)
        self.assertEqual(Contact.objects.count(), 0)

    def test_pull_fields(self):
        '''
        Pulling all the fields should be a noop.<commit_msg>added a test for syncing from the identity store<commit_after>from casepro.contacts.models import Contact, Field, Group
from casepro.msgs.models import Label, Message
from casepro.test import BaseCasesTest
from django.test import override_settings
import json
import responses

from ..junebug import IdentityStore, JunebugBackend, JunebugMessageSendingError


class JunebugBackendTest(BaseCasesTest):
    def setUp(self):
        super(JunebugBackendTest, self).setUp()
        self.backend = JunebugBackend()

    @responses.activate
    def test_pull_contacts(self):
        '''
        Pulling all of the contacts should be a noop.
        '''
        Contact.objects.all().delete()

        def identity_store_callback(request):
            headers = {'Content-Type': 'application/json'}
            resp = {
                "count": 1,
                "next": None,
                "previous": None,
                "results": [
                    {
                        "id": "test_id",
                        "version": 1,
                        "details": {
                            "name": "test",
                            "addresses": {
                                "msisdn": {
                                    "+1234": {}
                                }
                            }
                        },
                        "communicate_through": None,
                        "operator": None,
                        "created_at": "2016-03-14T10:21:00.258406Z",
                        "created_by": 1,
                        "updated_at": "2016-03-14T10:21:00.258441Z",
                        "updated_by": 1
                    }
                ]
            }
            return (201, headers, json.dumps(resp))
        responses.add_callback(
            responses.GET,
            'http://localhost:8081/api/v1/identities/search/',
            callback=identity_store_callback, content_type='application/json')

        (created, updated, deleted, ignored) = self.backend.pull_contacts(
            self.unicef, None, None)
        self.assertEqual(created, 1)
        self.assertEqual(updated, 0)
        self.assertEqual(deleted, 0)
        self.assertEqual(ignored, 0)
        self.assertEqual(Contact.objects.count(), 1)

    def test_pull_fields(self):
        '''
        Pulling all the fields should be a noop.
{'fraction_non_alphanumeric': 0.09632892804698973, 'fraction_numerical': 0.019383259911894272, 'mean_word_length': 1.7578947368421052, 'pattern_counts': {'":': 17, '<': 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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '350466', 'n_tokens_mistral': 947, 'n_tokens_neox': 891, 'n_words': 206}