<commit_before>from django.test import TestCase

# Create your tests here.<commit_msg>ticket:25 Added tests for EventResource<commit_after># -*- coding: utf-8 -*-
import json

from django.test import TestCase
from django.contrib.auth.models import User

from mock import patch
from factory.django import DjangoModelFactory

from django.core.urlresolvers import reverse


class UserFactory(DjangoModelFactory):
    FACTORY_FOR = User


class EventTestCase(TestCase):

    @patch('events.api.resources.get_backend')
    def test_events_post(self, back_mock):
        url = reverse('api_dispatch_list',
            kwargs={'resource_name': 'events', 'api_name': 'v1'})
        user = UserFactory()
        back_mock().social_auth_backend().do_auth.return_value = user

        # wrong request type
        resp = self.client.get(url, content_type='application/json')
        self.assertEqual(resp.status_code, 405)

        # no params
        resp = self.client.post(url, content_type='application/json')
        self.assertEqual(resp.status_code, 400)

        data = {
            'provider': 'bad_provider',
            'access_token': '<PASSWORD>',
        }

        # bad params
        resp = self.client.post(url, data=json.dumps(data), content_type='application/json')
        self.assertEqual(resp.status_code, 404)

        data['provider'] = 'facebook'
        resp = self.client.post(url, data=json.dumps(data), content_type='application/json')
        self.assertEqual(resp.status_code, 200)

        event = Event.objects.latest('id')
        self.assertEqual(event.status, 'P')
        self.assertEqual(event.user, user)

        resp = self.client.post(url, data=json.dumps(data), content_type='application/json')
        self.assertEqual(resp.status_code, 200)
        new_event = Event.objects.latest('id')
        self.assertEqual(new_event.status, 'P')
        self.assertEqual(Event.objects.get(id=event.id).status, 'F')
        self.assertEqual(new_event.user, user)


class EventUpdateTestCase(TestCase):
    pass
{'fraction_non_alphanumeric': 0.12137592137592138, 'fraction_numerical': 0.009336609336609337, 'mean_word_length': 3.2505219206680587, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '646816', 'n_tokens_mistral': 613, 'n_tokens_neox': 584, 'n_words': 115}