def setUpTestData(cls):
        cls.factory = APIRequestFactory()
        cls.test_user = User.objects.create_user(username='******',
                                                 password='******')

        cls.test_admin = User.objects.create_superuser(
            username='******',
            email='*****@*****.**',
            password='******')

        cls.report_name = "Q2 2019 Report"
        cls.test_supply1 = Supply(name="3D printer",
                                  state="Brand new",
                                  description="User manual is lost")
        cls.test_supply1.save()
        cls.test_supply2 = Supply(name="Screwdriver",
                                  state="Worn out",
                                  description="Handle is broken")
        cls.test_supply2.save()

        # Report has to be generated through view to make sure it's populated with supplies
        cls.test_report_name = 'Test report'
        request = cls.factory.post('/api/inventories/',
                                   {'name': cls.test_report_name})
        force_authenticate(request, user=cls.test_admin)
        InventoryReportListCreateView.as_view()(request)
        cls.test_report = InventoryReport.objects.get(
            name=cls.test_report_name)
    def setUpTestData(cls):
        cls.factory = APIRequestFactory()
        cls.test_user = User.objects.create_user(username='******',
                                                 password='******')

        cls.test_admin = User.objects.create_superuser(
            username='******',
            email='*****@*****.**',
            password='******')

        cls.report_name = "Q2 2019 Report"
        cls.test_supply_name = "3D printer"
        cls.test_supply_state = "Brand new"
        cls.test_supply_description = "User manual is lost"
        cls.test_supply = Supply(name=cls.test_supply_name,
                                 state=cls.test_supply_state,
                                 description=cls.test_supply_description)
        cls.test_supply.save()

        cls.test_report = InventoryReport(name=cls.report_name)
        cls.test_report.save()

        cls.test_inventory_supply = InventorySupply(
            inventory_supply=cls.test_supply, inventory_report=cls.test_report)
        cls.test_inventory_supply.save()
    def setUpTestData(cls):
        cls.factory = APIRequestFactory()
        cls.test_user = User.objects.create_user(username='******',
                                                 password='******')

        cls.test_admin = User.objects.create_superuser(
            username='******',
            email='*****@*****.**',
            password='******')

        cls.report_name = "Q2 2019 Report"
        cls.test_supply1 = Supply(name="3D printer",
                                  state="Brand new",
                                  description="User manual is lost")
        cls.test_supply1.save()
        cls.test_supply2 = Supply(name="Screwdriver",
                                  state="Worn out",
                                  description="Handle is broken")
        cls.test_supply2.save()
Exemplo n.º 4
0
 def setUp(self):
     """
     Sets up for tests
     """
     super(ProjectResourceTestCase, self).setUp()
     
     self.create_user()
     #self.api_client.client.login(username='******', password='******')
     
     #self.customer = Customer.create(**base_customer)
     #self.project = Project.create(**base_project)
     self.project = Project(codename="Ladawan")
     self.project.save()
     self.supply = Supply(description='Grommet')
     self.supply.save()
     self.supply2 = Supply(description='Hinge')
     self.supply2.save()
     self.project_supply = ProjectSupply(supply=self.supply,
                                         project=self.project,
                                         quantity=2)
     self.project_supply.save()
Exemplo n.º 5
0
def work():
    data = []
    review = []
    supplier = Supplier.objects.get(name__icontains="blue international")
    with open("/Users/Charlie/Sites/employee/backend/blue-inter.csv",
              'r') as f:
        reader = csv.reader(f)
        for row in reader:
            data.append({
                'reference': row[0],
                'description': row[1],
                'cost': row[2],
                'units': row[3]
            })

    for index, d in enumerate(data):
        for key in d.keys():
            try:
                d[key] = d[key].encode('utf-8')
            except UnicodeDecodeError as e:
                pass

            if key == "cost":
                try:
                    d[key] = Decimal(d[key].replace(',', ''))
                except InvalidOperation as e:
                    review.append(data.pop(index))

            if key == "units":
                if not d[key]:
                    review.append(data.pop(index))

    for index, d in enumerate(data):
        try:
            try:
                supply = Supply.objects.get(description=d['description'])
            except Supply.DoesNotExist:
                supply = Supply()

            supply.description = d['description']
            supply.units = d['units']
            supply.full_clean()
            supply.save()

            try:
                product = Product.objects.get(supply=supply)
            except Product.DoesNotExist:
                product = Product(supply=supply, supplier=supplier)

            product.supplier = supplier
            product.supply = supply
            product.reference = d['reference']
            product.cost = d['cost']
            product.purchasing_units = d['units']
            product.full_clean()
            product.save()

        except ValidationError as e:
            print e
            review.append(data.pop(index))

        assert Supply.objects.filter(description=d['description']).count() == 1

    with open('blue-inter-review.csv', 'w') as f:
        fieldnames = ['reference', 'description', 'cost', 'units']
        writer = csv.DictWriter(f)
        writer.write_header()
        for d in review:
            writer.writerow(d)

    assert supplier.supplies.all().count() == len(data)