<commit_before>import time
import json
import datetime
import urllib

from django.test import TestCase
from django.core.urlresolvers import reverse
from django_dynamic_fixture import G
from django.utils.dateformat import format
from .utils import datetime_to_timestamp, timestamp_to_datetime

from .models import Message, Channel


def create_message(text, timestamp, username, channel):
    """
    Creates a message with the given text, datetime,
    username, channel and with typing set to True.
    """
    message = Message(
        text=text,
        datetime_start=timestamp_to_datetime(timestamp),
        username=username,
        typing=True,
        channel=channel
    )
    message.save()
    return message


class ChatTests(TestCase):
    def setUp(self):
        super(ChatTests, self).setUp()
        self.channel = G(Channel, name='Channel')


class MessageViewPOSTTests(ChatTests):
    def post_and_get_response(self, text, timestamp, username, typing):
        """
        Posts a message on chat:message and returns the response
        """
        return self.client.post(
            reverse('chat:message', args=(self.channel.name,)),
            {'text': text, 'username': username, 'datetime_start': timestamp, 'typing': typing}
        )

    def test_post_valid_message(self):
        """
        When a valid message is sent, the view should
        save the message in the database and return
        the id of the message.
        """
        timestamp = 10 ** 11
        username = 'vitsalisa'
        text = 'Message'
<commit_msg>Use objects.create() on create_message()<commit_after>import time
import json
import datetime
import urllib

from django.test import TestCase
from django.core.urlresolvers import reverse
from django_dynamic_fixture import G
from django.utils.dateformat import format
from .utils import datetime_to_timestamp, timestamp_to_datetime

from .models import Message, Channel


def create_message(text, timestamp, username, channel):
    """
    Creates a message with the given text, datetime,
    username, channel and with typing set to True.
    """
    return Message.objects.create(
        text=text,
        datetime_start=timestamp_to_datetime(timestamp),
        username=username,
        typing=True,
        channel=channel
    )


class ChatTests(TestCase):
    def setUp(self):
        super(ChatTests, self).setUp()
        self.channel = G(Channel, name='Channel')


class MessageViewPOSTTests(ChatTests):
    def post_and_get_response(self, text, timestamp, username, typing):
        """
        Posts a message on chat:message and returns the response
        """
        return self.client.post(
            reverse('chat:message', args=(self.channel.name,)),
            {'text': text, 'username': username, 'datetime_start': timestamp, 'typing': typing}
        )

    def test_post_valid_message(self):
        """
        When a valid message is sent, the view should
        save the message in the database and return
        the id of the message.
        """
        timestamp = 10 ** 11
        username = 'vitsalisa'
        text = 'Message'

{'fraction_non_alphanumeric': 0.08783136378153944, 'fraction_numerical': 0.0025550942190993293, 'mean_word_length': 2.9346733668341707, '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': '1255172', 'n_tokens_mistral': 839, 'n_tokens_neox': 824, 'n_words': 268}