Exemplo n.º 1
0
    def test_update_team(self):
        """
        Update an existing team's name and description
        """
        tag1 = TagFactory()
        tag2 = TagFactory()
        team = TeamFactory(tags=[tag1, tag2])

        tag3 = TagFactory()

        newtags = [tag1.id, tag3.id]

        url = reverse('team-detail', args=[team.id])
        data = {
            "id": team.id,
            "name": team.name + " updated",
            "short_desc": team.name + " updated",
            "tags": newtags
        }
        response = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['id'], data['id'])
        self.assertEqual(response.data['name'], data['name'])
        self.assertEqual(response.data['short_desc'], data['short_desc'])
        self.assertEqual(len(response.data['tags']), 2)
        six.assertCountEqual(self, response.data['tags'], [tag1.id, tag3.id])
Exemplo n.º 2
0
    def test_search_tag(self):
        """
        List all tags that match a search criteria
        """
        tag = TagFactory(name="foo")
        tag2 = TagFactory(name="bar")

        url = "%s?search=%s" % (reverse('tag-list'), tag.name)
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data[0]['id'], tag.id)
        self.assertEqual(response.data[0]['name'], tag.name)
        self.assertEqual(len(response.data), 1)
Exemplo n.º 3
0
    def test_update_tags(self):
        """
        Ensure you can update the tags
        """
        tag1 = TagFactory()
        tag2 = TagFactory()
        assessment = AssessmentFactory(tags=[tag1, tag2])

        tag3 = TagFactory()

        url = reverse('assessment-detail', args=(assessment.id,))
        data = {"id": assessment.id, "template": assessment.template.id, "status": assessment.status,
                "tags": [tag1.id, tag3.id]}
        response = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['id'], data['id'])
        self.assertEqual(len(response.data['tags']), 2)
        self.assertCountEqual(response.data['tags'], [tag1.id, tag3.id])
Exemplo n.º 4
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": "Test Team", "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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    def test_list_tags(self):
        """
        List all tags and check that all fields are returned
        """
        tag = TagFactory()

        url = reverse('tag-list')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data[0]['id'], tag.id)
        self.assertEqual(response.data[0]['name'], tag.name)
        self.assertEqual(len(response.data), Tag.objects.count())
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    def test_team(self):
        """
        Fetch a team and check that all fields are returned
        """
        tag1 = TagFactory()
        tag2 = TagFactory()
        team = TeamFactory(tags=[tag1, tag2])

        url = reverse('team-detail', args=[team.id])
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['id'], team.id)
        self.assertEqual(response.data['name'], team.name)
        self.assertEqual(response.data['short_desc'], team.short_desc)
        self.assertEqual(
            datetime.datetime.strptime(response.data['created'],
                                       '%Y-%m-%dT%H:%M:%S.%fZ'),
            team.created.replace(tzinfo=None))
        self.assertEqual(
            datetime.datetime.strptime(response.data['updated'],
                                       '%Y-%m-%dT%H:%M:%S.%fZ'),
            team.updated.replace(tzinfo=None))
        self.assertEqual(len(response.data['tags']), 2)
        six.assertCountEqual(self, response.data['tags'], [tag1.id, tag2.id])
Exemplo n.º 9
0
 def test_creation_of_team_with_two_tags(self):
     tag1 = TagFactory()
     tag2 = TagFactory()
     team = TeamFactory(tags=(tag1, tag2))
     team.clean()
     self.assertEqual(2, len(team.tags.all()))
Exemplo n.º 10
0
 def test_str_name_tag(self):
     tag = TagFactory()
     tag.clean()
     self.assertEqual(tag.name, str(tag))