<commit_before>from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase

import dateutil.parser

from measure_mate.models import Team
from measure_mate.tests.factories import TeamFactory, TagFactory


class TeamAPITestCases(APITestCase):
    def test_list_team(self):
        """
        List all teams and check that all fields are returned
        """
        team = TeamFactory()
        team2 = TeamFactory()

        url = reverse('team-list')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), Team.objects.count())
        self.assertEqual(response.data[0]['id'], team.id)
        self.assertEqual(response.data[0]['name'], team.name)
        self.assertEqual(response.data[0]['short_desc'], team.short_desc)
        self.assertEqual(dateutil.parser.parse(response.data[0]['created']), team.created)
        self.assertEqual(dateutil.parser.parse(response.data[0]['updated']), team.updated)

    def test_create_team(self):
        """
        Ensure we can create a new team object.
        """
        tag = TagFactory()

        url = reverse('team-list')
        data = {"name": "Test Team", "short_desc": "A team for testing with", "tags": [tag.id]}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(Team.objects.count(), 1)

    def test_fail_create_team(self):
        """
        Ensure that missing name returns a 400.
        """
        tag = TagFactory()

        url = reverse('team-list')
        data = {"short_desc": "A team for testing with", "tags": [tag.id]}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(Team.objects.count(), 0)

    def test_fail_create_team_no_tag(self):
        """
        Ensure that request fails when no tag is specified.
        """
        tag = TagFactory()

        url = reverse('team-list')
        data = {"name": "<NAME>", "short_desc": "A team for testing with"}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(Team.objects.count(), 0)


<commit_msg>use the same date comparison as existing tests<commit_after>import datetime
from time import timezone

from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase

from measure_mate.models import Team
from measure_mate.tests.factories import TeamFactory, TagFactory


class TeamAPITestCases(APITestCase):
    def test_list_team(self):
        """
        List all teams and check that all fields are returned
        """
        team = TeamFactory()
        team2 = TeamFactory()

        url = reverse('team-list')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), Team.objects.count())
        self.assertEqual(response.data[0]['id'], team.id)
        self.assertEqual(response.data[0]['name'], team.name)
        self.assertEqual(response.data[0]['short_desc'], team.short_desc)
        self.assertEqual(datetime.datetime.strptime(response.data[0]['created'], '%Y-%m-%dT%H:%M:%S.%fZ'),
                         team.created.replace(tzinfo=None))
        self.assertEqual(datetime.datetime.strptime(response.data[0]['updated'], '%Y-%m-%dT%H:%M:%S.%fZ'),
                         team.updated.replace(tzinfo=None))

    def test_create_team(self):
        """
        Ensure we can create a new team object.
        """
        tag = TagFactory()

        url = reverse('team-list')
        data = {"name": "<NAME>", "short_desc": "A team for testing with", "tags": [tag.id]}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(Team.objects.count(), 1)

    def test_fail_create_team(self):
        """
        Ensure that missing name returns a 400.
        """
        tag = TagFactory()

        url = reverse('team-list')
        data = {"short_desc": "A team for testing with", "tags": [tag.id]}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(Team.objects.count(), 0)

    def test_fail_create_team_no_tag(self):
        """
        Ensure that request fails when no tag is specified.
        """
        tag = TagFactory()

        url = reverse('team-list')
        data = {"name": "<NAME>", "short_desc": "A team for testing with"}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(Team.objects.count(), 0)



{'fraction_non_alphanumeric': 0.1289489370156964, 'fraction_numerical': 0.009537055434134712, 'mean_word_length': 2.945141065830721, 'pattern_counts': {'":': 14, '<': 6, '<?xml version=': 0, '>': 6, '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': '2119372', 'n_tokens_mistral': 1472, 'n_tokens_neox': 1432, 'n_words': 322}