Ejemplo n.º 1
0
    def test_list_with_username_filter(self):
        """ Verify the list endpoint supports filter data by username."""
        factories.UserCredentialFactory(username="******")
        response = self.client.get(
            self.list_path, data={'username': self.user_credential.username})
        self.assertEqual(response.status_code, 200)

        # after filtering it is only one related record
        expected = UserCredentialSerializer(self.user_credential,
                                            context={
                                                'request': self.request
                                            }).data

        self.assertEqual(response.data, {
            'count': 1,
            'next': None,
            'previous': None,
            'results': [expected]
        })
Ejemplo n.º 2
0
    def _assert_usercredential_fields(self, response, username,
                                      expected_attrs):
        """ Verify the fields on a UserCredential object match expectations. """

        user_credential = UserCredential.objects.filter(username=username)
        self.assertEqual(user_credential.count(), 1)
        self.assertEqual(
            dict(response.data),
            dict(
                UserCredentialSerializer(user_credential[0],
                                         context={
                                             'request': self.request
                                         }).data))

        actual_attributes = [{
            "name": attr.name,
            "value": attr.value
        } for attr in user_credential[0].attributes.all()]
        self.assertEqual(actual_attributes, expected_attrs)
Ejemplo n.º 3
0
 def assert_list_with_id_filter(self, data):
     """Helper method used for making request and assertions. """
     expected = {
         'count':
         1,
         'next':
         None,
         'previous':
         None,
         'results': [
             UserCredentialSerializer(self.user_credential,
                                      context={
                                          'request': self.request
                                      }).data
         ]
     }
     response = self.client.get(self.list_path, data)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, expected)