Esempio n. 1
0
    def test_filters(self):
        self.login()
        ProductFactory(id=1, name="A1")
        ProductFactory(id=2,
                       name="A2",
                       company=CompanyFactory(name="PrefixB2"))
        ProductFactory(id=3,
                       name="A3",
                       company=CompanyFactory(official_name="B3Suffix"))
        ProductFactory(id=4,
                       name="A4",
                       company=CompanyFactory(common_name="PefixB4Suffix"))

        response = self.client.get("{}?q={}".format(self.url, "A1"))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json(),
                         self._get_expected_result([('1', 'A1')]))

        response = self.client.get("{}?q={}".format(self.url, "B2"))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json(),
                         self._get_expected_result([('2', 'A2')]))

        response = self.client.get("{}?q={}".format(self.url, "B3"))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json(),
                         self._get_expected_result([('3', 'A3')]))

        response = self.client.get("{}?q={}".format(self.url, "B4"))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json(),
                         self._get_expected_result([('4', 'A4')]))
Esempio n. 2
0
    def test_should_return_200_when_one_comand_in_brand_and_product(self):
        c1 = CompanyFactory(
            plCapital=100,
            plWorkers=0,
            plRnD=100,
            plRegistered=100,
            plNotGlobEnt=100,
            description="TEST",
            sources="TEST|BBBB",
            verified=True,
            is_friend=True,
            plCapital_notes="AAA",
            plWorkers_notes="BBB",
            plRnD_notes="CCC",
            plRegistered_notes="DDD",
            plNotGlobEnt_notes="EEE",
        )

        p = ProductFactory.create(code=5900049011829, company=c1, brand__company=c1)
        response = self.json_request(self.url + "?device_id=TEST-DEVICE-ID&code=" + str(p.code))
        self.assertEqual(200, response.status_code, response.content)
        self.maxDiff = None
        self.assertEqual(
            {
                'altText': None,
                'card_type': 'type_white',
                'code': '5900049011829',
                'description': 'TEST',
                'donate': {
                    'show_button': True,
                    'title': 'Potrzebujemy 1 zł',
                    'url': 'https://klubjagiellonski.pl/zbiorka/wspieraj-aplikacje-pola/',
                },
                'friend_text': 'To jest przyjaciel Poli',
                'is_friend': True,
                'name': 'company_official_125',
                'plCapital': 100,
                'plCapital_notes': 'AAA',
                'plNotGlobEnt': 100,
                'plNotGlobEnt_notes': 'EEE',
                'plRegistered': 100,
                'plRegistered_notes': 'DDD',
                'plRnD': 100,
                'plRnD_notes': 'CCC',
                'plScore': 70,
                'plWorkers': 0,
                'plWorkers_notes': 'BBB',
                'product_id': p.pk,
                'report_button_text': 'Zgłoś',
                'report_button_type': 'type_white',
                'report_text': 'Zgłoś jeśli posiadasz bardziej aktualne dane na temat tego produktu',
                'sources': {'TEST': 'BBBB'},
            },
            json.loads(response.content),
        )
Esempio n. 3
0
 def test_should_return_200_when_polish_and_known_product(self):
     c = CompanyFactory(
         plCapital=100,
         plWorkers=0,
         plRnD=100,
         plRegistered=100,
         plNotGlobEnt=100,
         description="TEST",
         sources="TEST|BBBB",
         verified=True,
         is_friend=True,
         plCapital_notes="AAA",
         plWorkers_notes="BBB",
         plRnD_notes="CCC",
         plRegistered_notes="DDD",
         plNotGlobEnt_notes="EEE",
     )
     p = ProductFactory.create(code=5900049011829, company=c, brand=None)
     response = self.json_request(self.url + "?device_id=TEST-DEVICE-ID&code=" + str(p.code))
     self.assertEqual(200, response.status_code, response.content)
     self.maxDiff = None
     self.assertEqual(
         {
             "product_id": p.id,
             "code": "5900049011829",
             "name": c.official_name,
             "card_type": "type_white",
             "plScore": 70,
             "altText": None,
             "plCapital": 100,
             "plCapital_notes": "AAA",
             "plWorkers": 0,
             "plWorkers_notes": "BBB",
             "plRnD": 100,
             "plRnD_notes": "CCC",
             "plRegistered": 100,
             "plRegistered_notes": "DDD",
             "plNotGlobEnt": 100,
             "plNotGlobEnt_notes": "EEE",
             "report_text": "Zg\u0142o\u015b je\u015bli posiadasz bardziej aktualne dane na temat tego produktu",
             "report_button_text": "Zg\u0142o\u015b",
             "report_button_type": "type_white",
             "is_friend": True,
             "friend_text": "To jest przyjaciel Poli",
             "description": "TEST",
             "sources": {"TEST": "BBBB"},
             "donate": {
                 "show_button": True,
                 "url": "https://klubjagiellonski.pl/zbiorka/wspieraj-aplikacje-pola/",
                 "title": "Potrzebujemy 1 zł",
             },
         },
         json.loads(response.content),
     )
 def test_example_file(self):
     CompanyFactory(nip="1234566789")
     CompanyFactory(nip="7220002329")
     out = StringIO()
     call_command('import_brands', EXAMPLE_FILE, "1234566789", interactive=False, stdout=out)
     self.assertIn(
         'Successfully created brand Pilos \n'
         'Company with nip 7010399415 does not exist. Script will create a new company with name: '
         'Mazowiecka Sp.Mlecz. nip: 7010399415\n'
         'Successfully created product Jogurt pitny 1,5%, czerwona pomarańcza\n'
         'Successfully created product Jogurt pitny 1,5%, żurawina\n'
         'Product with name Serek twarogowy plastry, z ziołami has multiple ean codes: '
         '20387754, 20980368. Script will create/update multiple products, one for each code.\n'
         'Successfully created product Serek twarogowy plastry, z ziołami\n'
         'Successfully created product Serek twarogowy plastry, z ziołami\n'
         'Processed 3 products successful.',
         strip_ansi_escape_sequence(out.getvalue()).strip(),
     )
     self.assertTrue(Company.objects.filter(nip="7010399415", name="Mazowiecka Sp.Mlecz.").exists())
     self.assertTrue(Company.objects.filter(nip="7220002329").exists())
     self.assertEqual(4, Product.objects.filter(code__in=["20268190", "20268176", "20387754", "20980368"]).count())
     self.assertTrue(Brand.objects.filter(common_name="Pilos").exists())
Esempio n. 5
0
    def test_increment_company_query_counter(self, get_by_code_mock):
        c = CompanyFactory()
        p = ProductFactory(code=self.code, company=c)
        get_by_code_mock.return_value = p

        self.assertEqual(c.query_count, 0)
        self.client.get(self.url, {'device_id': 123})

        c.refresh_from_db()
        self.assertEqual(c.query_count, 1)

        self.client.get(self.url, {'device_id': 123})

        c.refresh_from_db()
        self.assertEqual(c.query_count, 2)
Esempio n. 6
0
 def setUp(self):
     super().setUp()
     self.instance = ProductFactory(code="123")
     self.company = CompanyFactory()
     self.url = reverse('product:edit', args=[self.instance.code])
Esempio n. 7
0
 def setUp(self):
     super().setUp()
     self.company = CompanyFactory()
Esempio n. 8
0
 def setUp(self):
     super().setUp()
     self.instance = CompanyFactory(name="company_name")
     self.url = reverse('company:edit', kwargs={'pk': self.instance.pk})
     self.user = StaffFactory()
Esempio n. 9
0
 def setUp(self):
     super().setUp()
     self.instance = CompanyFactory()
Esempio n. 10
0
 def setUp(self):
     super(InstanceMixin, self).setUp()
     self.instance = CompanyFactory()
Esempio n. 11
0
 def test_existings_compnay_in_db(self, mock_tool):
     CompanyFactory(nip=123)
     mock_tool.return_value = [self._get_mock()]
     data = {'is_krs' : '1', 'no': 123}
     form = CompanyCreateFromKRSForm(data=data)
     self.assertFalse(form.is_valid())
Esempio n. 12
0
 def setUp(self):
     super(ConcurencyComapnyUpdateTestCase, self).setUp()
     self.instance = CompanyFactory()
 def test_empty_file(self):
     CompanyFactory(nip="1234566789")
     out = StringIO()
     with NamedTemporaryFile() as tmp_file:
         call_command('import_brands', tmp_file.name, "1234566789", interactive=False, stdout=out)
     self.assertIn("Empty file. Nothing to do", strip_ansi_escape_sequence(out.getvalue()))