<commit_before># -*- coding: utf-8 -*-
import json
import unittest
from datetime import datetime

from twitter_watcher import server
from twitter_watcher.db.models import Listener


class DetailViewListenerTestCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.api = server.api.test_client()
    
    def setUp(self):
        self.listener = Listener(usernames=['@teste'],
                                 hashtags=['#123'],
                                 start_date=datetime.now(),
                                 end_data=datetime.now())
        self.listener.save()

    def tearDown(self):
        self.listener.delete()

    def test_return_json_listener(self):
        url = '/listener/{}'.format(self.listener.id)
        response = self.api.get(url)
        self.assertEquals(response.status_code, 200)
        expected = self.listener.to_json()
        returned = json.loads(response.data)
        self.assertEquals(returned['id'], expected['id']) 
        self.assertEquals(returned['usernames'], expected['usernames']) 
        self.assertEquals(returned['hashtags'], expected['hashtags']) 

    def test_400_for_invalid_object_id(self):
        url = '/listener/222222222222'
        response = self.api.get(url)
        self.assertEquals(response.status_code, 400)

    def test_404_for_not_found(self):
        url = '/listener/111111111111111111111111'
        response = self.api.get(url)
        self.assertEquals(response.status_code, 404)



class CreateListenerViewsTestCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.api = server.api.test_client()

    def tearDown(self):
        Listener.objects.all().delete()

    def test_not_send_application_json_header(self):
        response = self.api.post('/listeners', data='not valid json')
        self.assertEquals(response.status_code, 406)

    def test_send_not_valid_json(self):
        response = self.api.post('/listeners',
                                 data='not valid json',
                                 content_type='application/json')

        self.assertEquals(response.status_code, 400)
<commit_msg>Fixing Pep8: removing extra line in file<commit_after># -*- coding: utf-8 -*-
import json
import unittest
from datetime import datetime

from twitter_watcher import server
from twitter_watcher.db.models import Listener


class DetailViewListenerTestCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.api = server.api.test_client()
    
    def setUp(self):
        self.listener = Listener(usernames=['@teste'],
                                 hashtags=['#123'],
                                 start_date=datetime.now(),
                                 end_data=datetime.now())
        self.listener.save()

    def tearDown(self):
        self.listener.delete()

    def test_return_json_listener(self):
        url = '/listener/{}'.format(self.listener.id)
        response = self.api.get(url)
        self.assertEquals(response.status_code, 200)
        expected = self.listener.to_json()
        returned = json.loads(response.data)
        self.assertEquals(returned['id'], expected['id']) 
        self.assertEquals(returned['usernames'], expected['usernames']) 
        self.assertEquals(returned['hashtags'], expected['hashtags']) 

    def test_400_for_invalid_object_id(self):
        url = '/listener/222222222222'
        response = self.api.get(url)
        self.assertEquals(response.status_code, 400)

    def test_404_for_not_found(self):
        url = '/listener/111111111111111111111111'
        response = self.api.get(url)
        self.assertEquals(response.status_code, 404)


class CreateListenerViewsTestCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.api = server.api.test_client()

    def tearDown(self):
        Listener.objects.all().delete()

    def test_not_send_application_json_header(self):
        response = self.api.post('/listeners', data='not valid json')
        self.assertEquals(response.status_code, 406)

    def test_send_not_valid_json(self):
        response = self.api.post('/listeners',
                                 data='not valid json',
                                 content_type='application/json')

        self.assertEquals(response.status_code, 400)

{'fraction_non_alphanumeric': 0.11344731977818855, 'fraction_numerical': 0.02841959334565619, 'mean_word_length': 2.5425531914893615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4360053', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1189, 'n_words': 206}