예제 #1
0
 def setUp(self):
     self.fixture = fixtures.CustomerFixture()
     self.division_1 = factories.DivisionFactory()
     self.division_2 = factories.DivisionFactory()
     self.fixture.customer.division = self.division_1
     self.fixture.customer.save()
     self.url = factories.CustomerFactory.get_url(self.fixture.customer)
예제 #2
0
    def test_if_divisions_do_not_match_order_validation_fails(self):
        user = self.fixture.staff
        offering = factories.OfferingFactory(
            state=models.Offering.States.ACTIVE)
        division = structure_factories.DivisionFactory()
        offering.divisions.add(division)

        response = self.create_order(user, offering)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
예제 #3
0
    def test_if_divisions_match_order_validation_passes(self):
        user = self.fixture.staff
        offering = factories.OfferingFactory(
            state=models.Offering.States.ACTIVE)
        division = structure_factories.DivisionFactory()
        offering.divisions.add(division)
        self.fixture.customer.division = division
        self.fixture.customer.save()

        response = self.create_order(user, offering)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertTrue(models.Order.objects.filter(created_by=user).exists())
        self.assertEqual(1, len(response.data['items']))
예제 #4
0
    def test_list_filters(self):
        """Test of divisions' list filter by name, type and parent UUID."""
        division_parent = factories.DivisionFactory()
        self.division_1.parent = division_parent
        self.division_1.save()
        rows = [
            {
                'name': 'name',
                'valid': self.division_1.name[2:],
                'invalid': 'AAA'
            },
            {
                'name': 'name_exact',
                'valid': self.division_1.name,
                'invalid': self.division_1.name[2:]
            },
            {
                'name': 'type',
                'valid': self.division_1.type.name,
                'invalid': self.division_1.type.name[2:]
            },
            {
                'name': 'parent',
                'valid': division_parent.uuid.hex,
                'invalid': division_parent.uuid.hex[2:]
            },
        ]
        self.client.force_authenticate(user=self.fixture.staff)

        for row in rows:
            response = self.client.get(self.url,
                                       data={row['name']: row['valid']})
            self.assertEqual(status.HTTP_200_OK, response.status_code)
            self.assertEqual(len(response.data), 1)

            response = self.client.get(self.url,
                                       data={row['name']: row['invalid']})
            if row['name'] == 'parent':
                self.assertEqual(status.HTTP_400_BAD_REQUEST,
                                 response.status_code)
            else:
                self.assertEqual(status.HTTP_200_OK, response.status_code)
                self.assertEqual(len(response.data), 0)
예제 #5
0
    def test_list_filters(self):
        """Test of divisions' list filter by name, type and parent UUID."""
        division_parent = factories.DivisionFactory()
        self.division_1.parent = division_parent
        self.division_1.save()
        filters = [
            {
                'name': 'name',
                'correct': self.division_1.name[2:],
                'uncorrect': 'AAA'
            },
            {
                'name': 'name_exact',
                'correct': self.division_1.name,
                'uncorrect': self.division_1.name[2:]
            },
            {
                'name': 'type',
                'correct': self.division_1.type.name,
                'uncorrect': self.division_1.type.name[2:]
            },
            {
                'name': 'parent',
                'correct': division_parent.uuid.hex,
                'uncorrect': division_parent.uuid.hex[2:]
            },
        ]
        self.client.force_authenticate(user=self.fixture.staff)

        for f in filters:
            response = self.client.get(self.url,
                                       data={f['name']: f['correct']})
            self.assertEqual(status.HTTP_200_OK, response.status_code)
            self.assertEqual(len(response.data), 1)
            response = self.client.get(self.url,
                                       data={f['name']: f['uncorrect']})
            self.assertEqual(status.HTTP_200_OK, response.status_code)
            self.assertEqual(len(response.data), 0)
예제 #6
0
 def setUp(self):
     self.division = factories.DivisionFactory()
     self.customer1 = factories.CustomerFactory()
     self.customer2 = factories.CustomerFactory(division=self.division)
     self.user = fixtures.UserFixture().staff
     self.url = factories.CustomerFactory.get_list_url()
예제 #7
0
 def setUp(self):
     self.fixture = fixtures.UserFixture()
     self.division_1 = factories.DivisionFactory()
     self.division_2 = factories.DivisionFactory()
     self.url = factories.DivisionFactory.get_list_url()