Esempio n. 1
0
    def test_person_address_filter_with_pagination_error(self):
        model_address_1 = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='SP',
            city='São Paulo',
            number=321,
            complement='Apartamento',
            invoice=False,
            delivery=False,
        )
        model_address_1.save()

        model_address_2 = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='RS',
            city='Porto Alegre',
            number=123,
            complement='Casa',
            invoice=True,
            delivery=True,
        )
        model_address_2.save()

        data_get = {
            'page': '3',
            'limit': '1',
            'address_id': '',
            'person_id': self.model_person_client.person_id,
            'state': '',
            'city': '',
            'number': '',
            'complement': '',
            'invoice': '',
            'delivery': '',
        }

        response = self.client.get(
            '/api/v1/person/address/',
            data_get,
            REMOTE_ADDR='127.0.0.8',
            HTTP_API_KEY=self.model_login_director.token,
        )

        self.assertEqual(response.status_code, 400)
        self.assertIsNotNone(response.json())
        self.assertIsInstance(response.json(), dict)
        self.assertEqual({'message': 'Nenhum registro encontrado![80]'},
                         response.json())
Esempio n. 2
0
    def test_person_address_delete_invoice_error(self):
        model_address_1 = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='SP',
            city='São Paulo',
            number=321,
            complement='Apartamento',
            invoice=True,
            delivery=False,
        )
        model_address_1.save()

        data_delete = {
            'address_id': model_address_1.address_id,
        }

        response = self.client.delete(
            '/api/v1/person/address/',
            json.dumps(data_delete),
            content_type='application/json',
            REMOTE_ADDR='127.0.0.8',
            HTTP_API_KEY=self.model_login_director.token)

        self.assertEqual(response.status_code, 400)
        self.assertIsNotNone(response.json())
        self.assertIsInstance(response.json(), dict)
        self.assertEqual(
            {
                'message':
                'Não é possível remover endereço de cobrança ou entrega![52]'
            }, response.json())
Esempio n. 3
0
    def test_person_address_update_param_invoice_or_delivery_error(self):
        model_address_1 = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='SP',
            city='São Paulo',
            number=321,
            complement='Apartamento',
            invoice=False,
            delivery=False,
        )
        model_address_1.save()

        data_post = {
            'address_id': model_address_1.address_id,
            'state': 'RS',
            'city': 'Porto Alegre',
            'number': '134567890',
            'complement': 'Apartamento',
            'invoice': 'error',
            'delivery': '1',
        }

        response = self.client.put(
            '/api/v1/person/address/',
            json.dumps(data_post),
            content_type='application/json',
            REMOTE_ADDR='127.0.0.8',
            HTTP_API_KEY=self.model_login_director.token)

        self.assertEqual(response.status_code, 400)
        self.assertIsNotNone(response.json())
        self.assertIsInstance(response.json(), dict)
        self.assertEqual({'message': 'Valor incorreto![48]'}, response.json())
Esempio n. 4
0
    def test_person_address_update_param_missing(self):
        model_address_1 = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='SP',
            city='São Paulo',
            number=321,
            complement='Apartamento',
            invoice=False,
            delivery=False,
        )
        model_address_1.save()

        data_post = {
            'address_id': model_address_1.address_id,
            'state': '',
            'city': '',
            'number': '',
            'complement': '',
            'invoice': '',
            'delivery': '',
        }

        response = self.client.put(
            '/api/v1/person/address/',
            json.dumps(data_post),
            content_type='application/json',
            REMOTE_ADDR='127.0.0.8',
            HTTP_API_KEY=self.model_login_director.token)

        self.assertEqual(response.status_code, 400)
        self.assertIsNotNone(response.json())
        self.assertIsInstance(response.json(), dict)
        self.assertEqual({'message': 'Nenhum dado para alterar![47]'},
                         response.json())
Esempio n. 5
0
    def test_person_address_add_error(self):
        model_address_1 = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='SP',
            city='São Paulo',
            number=321,
            complement='Apartamento',
            invoice=False,
            delivery=False,
        )
        model_address_1.save()

        model_address_2 = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='RS',
            city='Porto Alegre',
            number=123,
            complement='Casa',
            invoice=True,
            delivery=True,
        )
        model_address_2.save()

        data_post = {
            'person_id': self.model_person_client.person_id,
            'state': 'RS',
            'city': 'Porto Alegre',
            'number': '123',
            'complement': 'Casa',
            'invoice': '0',
            'delivery': '0',
        }

        response = self.client.post(
            '/api/v1/person/address/',
            json.dumps(data_post),
            content_type='application/json',
            REMOTE_ADDR='127.0.0.8',
            HTTP_API_KEY=self.model_login_director.token,
        )

        self.assertEqual(response.status_code, 400)
        self.assertIsNotNone(response.json())
        self.assertIsInstance(response.json(), dict)
        self.assertEqual({'message': 'Endereço duplicado![46]'},
                         response.json())
Esempio n. 6
0
    def test_person_address_delete_ok(self):
        model_address_1 = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='SP',
            city='São Paulo',
            number=321,
            complement='Apartamento',
            invoice=False,
            delivery=False,
        )
        model_address_1.save()

        model_address_2 = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='RS',
            city='Porto Alegre',
            number=123,
            complement='Casa',
            invoice=False,
            delivery=False,
        )
        model_address_2.save()

        data_delete = {
            'address_id': model_address_2.address_id,
        }

        response = self.client.delete(
            '/api/v1/person/address/',
            json.dumps(data_delete),
            content_type='application/json',
            REMOTE_ADDR='127.0.0.8',
            HTTP_API_KEY=self.model_login_director.token)

        self.assertEqual(response.status_code, 200)
        self.assertIsNotNone(response.json())
        self.assertIsInstance(response.json(), dict)
        self.assertEqual({'result': True}, response.json())

        self.assertEqual(ModelAddress.objects.filter().count(), 1)
Esempio n. 7
0
    def test_person_address_update_ok(self):
        model_address_1 = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='SP',
            city='São Paulo',
            number=321,
            complement='Apartamento',
            invoice=False,
            delivery=False,
        )
        model_address_1.save()

        data_post = {
            'address_id': model_address_1.address_id,
            'state': 'RS',
            'city': 'Porto Alegre',
            'number': '134567890',
            'complement': 'Apartamento',
            'invoice': '1',
            'delivery': '1',
        }

        response = self.client.put(
            '/api/v1/person/address/',
            json.dumps(data_post),
            content_type='application/json',
            REMOTE_ADDR='127.0.0.8',
            HTTP_API_KEY=self.model_login_director.token)

        self.assertEqual(response.status_code, 200)
        self.assertIsNotNone(response.json())
        self.assertIsInstance(response.json(), dict)
        self.assertEqual(
            {
                'complement': data_post['complement'],
                'address_id': data_post['address_id'],
                'city': data_post['city'],
                'state': data_post['state'],
                'delivery': True,
                'number': data_post['number'],
                'person_id': model_address_1.person_id,
                'invoice': True
            }, response.json())

        self.assertEqual(
            ModelAddress.objects.filter(address_id=model_address_1.address_id,
                                        invoice=True,
                                        delivery=True).count(), 1)
Esempio n. 8
0
    def test_person_address_get_ok(self):
        model_address = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='RS',
            city='Porto Alegre',
            number=123,
            complement='Casa',
            invoice=True,
            delivery=True,
        )
        model_address.save()

        data_get = {
            'address_id': model_address.address_id,
            'person_id': '',
            'state': '',
            'city': '',
            'number': '',
            'complement': '',
            'invoice': '',
            'delivery': '',
        }

        response = self.client.get(
            '/api/v1/person/address/',
            data_get,
            REMOTE_ADDR='127.0.0.8',
            HTTP_API_KEY=self.model_login_director.token,
        )

        self.assertEqual(response.status_code, 200)
        self.assertIsNotNone(response.json())
        self.assertIsInstance(response.json(), dict)
        self.assertEqual(
            {
                'person_id': model_address.person_id,
                'complement': model_address.complement,
                'number': model_address.number,
                'delivery': model_address.delivery,
                'invoice': model_address.invoice,
                'address_id': model_address.address_id,
                'state': model_address.state,
                'city': model_address.city
            }, response.json())
Esempio n. 9
0
    def test_person_address_filter_with_pagination_ok(self):
        model_address_1 = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='SP',
            city='São Paulo',
            number=321,
            complement='Apartamento',
            invoice=False,
            delivery=False,
        )
        model_address_1.save()

        model_address_2 = ModelAddress(
            person_id=self.model_person_client.person_id,
            state='RS',
            city='Porto Alegre',
            number=123,
            complement='Casa',
            invoice=True,
            delivery=True,
        )
        model_address_2.save()

        data_get = {
            'page': '1',
            'limit': '1',
            'address_id': '',
            'person_id': self.model_person_client.person_id,
            'state': '',
            'city': '',
            'number': '',
            'complement': '',
            'invoice': '',
            'delivery': '',
        }

        response = self.client.get(
            '/api/v1/person/address/',
            data_get,
            REMOTE_ADDR='127.0.0.8',
            HTTP_API_KEY=self.model_login_director.token,
        )

        self.assertEqual(response.status_code, 200)
        self.assertIsNotNone(response.json())
        self.assertIsInstance(response.json(), dict)
        self.assertEqual(
            {
                'total':
                2,
                'has_next':
                True,
                'count':
                2,
                'has_previous':
                False,
                'limit':
                1,
                'data': [
                    {
                        'address_id': model_address_2.address_id,
                        'person_id': model_address_2.person_id,
                        'number': model_address_2.number,
                        'state': model_address_2.state,
                        'complement': model_address_2.complement,
                        'city': model_address_2.city,
                        'delivery': model_address_2.delivery,
                        'invoice': model_address_2.invoice
                    },
                ],
                'num_pages':
                2
            }, response.json())