示例#1
0
 def test_status_code(self):
     """
     El status code de la respuesta de deberia de ser 404
     """
     request = Mock()
     response = page_not_found(request)
     assert_status_code(response, status.HTTP_404_NOT_FOUND)
示例#2
0
 def test_status_code(self):
     """
     El status code de la respuesta de deberia de ser 404
     """
     request = Mock()
     response = server_error(request)
     assert_status_code(response, status.HTTP_500_INTERNAL_SERVER_ERROR)
示例#3
0
    def test_should_return_the_url_to_get_the_profile( self ):
        url = reverse(
            self.url_name, kwargs={ 'package_pk': self.package.pk } )
        response = self.client.post(
            url, data={ 'ssn': '123456789', '_use_factory': 'default' } )
        assert_status_code( response, status.HTTP_201_CREATED )

        response_profile = get_location( response, client=self.client )
        assert_status_code( response_profile, status.HTTP_200_OK )
示例#4
0
 def test_validate_should_the_error( self ):
     url = reverse(
         self.url_name, kwargs={ 'package_pk': self.package.pk } )
     response = self.client.post( url, data={ 'ssn': '1' } )
     assert_status_code( response, status.HTTP_400_BAD_REQUEST )
     self.assertIn( self.background_check.name, response.data )
     validate_errors = response.data[ self.background_check.name ]
     self.assertIn( 'ssn', validate_errors )
     self.assertEqual( validate_errors[ 'ssn' ][0].code, 'min_length' )
示例#5
0
 def test_should_be_a_list(self):
     url = reverse(self.url_name)
     response = self.client.get(url)
     assert_status_code(response, status.HTTP_200_OK)
     self.assertIsInstance(response.data, list)
     self.assertTrue(response.data)
     assert_has_pages(response)
     for data in response.data:
         self.assertIn('pk', data)
         self.assertIn('fields', data)
         self.assertIsInstance(data['fields'], list)
示例#6
0
    def test_should_be_a_dict(self):
        catalog = Catalog.search()[:1].execute()[0]

        url = reverse(self.url_name, kwargs={'pk': catalog.meta.id})
        response = self.client.get(url)
        assert_status_code(response, status.HTTP_200_OK)
        self.assertIsInstance(response.data, dict)
        self.assertTrue(response.data)
        self.assertIn('pk', response.data)
        self.assertIn('fields', response.data)
        self.assertIsInstance(response.data['fields'], list)
        self.assertTrue(response.data['fields'])
示例#7
0
 def test_should_create_the_new_element(self):
     url = reverse(self.url_name)
     data = factory.build(dict, FACTORY_CLASS=Catalog_from_cdmx_api_factory)
     response = self.client.post(url, data=data)
     assert_status_code(response, status.HTTP_201_CREATED)
     response = get_location(response)
     self.assertIsInstance(response.data, dict)
     self.assertTrue(response.data)
     self.assertIn('pk', response.data)
     self.assertIn('endpoint', response.data)
     self.assertIn('origin_url', response.data)
     self.assertIn('fields', response.data)
     self.assertTrue(response.data['fields'])
示例#8
0
    def test_create_user(self):
        auth = str(self.super_token)
        response = self.client.post('/users/',
                                    HTTP_AUTHORIZATION=auth,
                                    data={
                                        'first_name': fake.first_name(),
                                        'last_name': fake.last_name(),
                                        'email': fake.email(),
                                        'username': fake.user_name(),
                                    })

        self.assertEqual(response.status_code, status.HTTP_201_CREATED,
                         ("the status code should be 200 instead "
                          "of {}\ndata:{}").format(response.status_code,
                                                   response.data))
        assert_status_code(response, status.HTTP_201_CREATED)
        response = get_location(response, client=self.client)

        self.assertIsInstance(response.data['pk'], str)
        self.assertIn('token', response.data)
        self.assertIn('key', response.data['token'])
        self.assertIsInstance(response.data['token']['key'], str)
        return response.data
示例#9
0
 def test_create(self):
     url_kw = self.get_url_kw()
     url = reverse(self.url_name, kwargs=url_kw)
     post_data = self.get_post_data()
     response = self.client.post(url, data=post_data)
     assert_status_code(response, self.expected_status_code)
示例#10
0
 def test_retrieve(self):
     url_kw = self.get_url_kw()
     url = reverse(self.url_name, kwargs=url_kw)
     response = self.client.get(url)
     assert_status_code(response, self.expected_status_code)
示例#11
0
    def test_fail_with_normal_user(self):
        response = self.client.get('/users/',
                                   HTTP_AUTHORIZATION=str(self.user_token))

        assert_status_code(response, status.HTTP_403_FORBIDDEN)
示例#12
0
    def test_should_return_404(self):
        catalog = Catalog.search()[:1].execute()[0]

        url = reverse(self.url_name, kwargs={'pk': '1'})
        response = self.client.get(url)
        assert_status_code(response, status.HTTP_404_NOT_FOUND)
示例#13
0
 def test_should_return(self):
     url = reverse(self.url_name)
     data = factory.build(dict, FACTORY_CLASS=Catalog_from_cdmx_api_factory)
     response = self.client.post(url, data=data)
     assert_status_code(response, status.HTTP_401_UNAUTHORIZED)