Ejemplo n.º 1
0
 def test_list_printer_view_one_printer(self):
     org = OrganizationFactory()
     UserOrganizationFactory(user=self.user, organization=org)
     event = EventFactory(organization=org, name="Evento")
     printer = PrinterFactory(name="Printer HP", event=event)
     response = self.client.get(
         '/event/{}/configuration/printer/list/'.format(event.eb_event_id))
     self.assertContains(response, printer.name)
Ejemplo n.º 2
0
 def test_delete_printer(self):
     org = OrganizationFactory()
     UserOrganizationFactory(user=self.user, organization=org)
     event = EventFactory(organization=org, name="Evento")
     printer = PrinterFactory(name="Printer HP", event=event)
     self.assertEqual(len(Printer.objects.all()), 1)
     self.client.post('/event/{}/configuration/printer/{}/delete/'.format(
         event.eb_event_id, printer.id))
     self.assertEqual(len(Printer.objects.all()), 0)
Ejemplo n.º 3
0
 def test_reset_printer(self):
     org = OrganizationFactory()
     UserOrganizationFactory(user=self.user, organization=org)
     event = EventFactory(organization=org, name="Evento")
     printer = PrinterFactory(name="Printer HP", event=event)
     first_key = printer.key
     response = self.client.get(
         '/event/{}/configuration/printer/{}/reset/'.format(
             event.eb_event_id, printer.id))
     printer = Printer.objects.get(id=printer.id)
     self.assertEqual(printer.secret_key, None)
     self.assertNotEqual(printer.key, first_key)
Ejemplo n.º 4
0
 def setUp(self):
     self.printer = PrinterFactory(id=1, name="Printer HP")
Ejemplo n.º 5
0
class TestApi(TestCase):
    def setUp(self):
        self.printer = PrinterFactory(id=1, name="Printer HP")

    def test_get_name(self):
        result = self.client.get('/api/printer/{}/'.format(self.printer.key))
        expected = b'{"id":1,"name":"Printer HP"}'
        self.assertEqual(expected, result.content)

    def test_set_name(self):
        self.client.post('/api/printer/{}/'.format(self.printer.key),
                         data={
                             'name': 'Zebra',
                             'secret_key': self.printer.secret_key
                         })
        result = Printer.objects.get(id=self.printer.id)
        expected = 'Zebra'
        self.assertEqual(expected, result.name)

    def test_printer_json(self):
        result = printer_json(self.printer.key, )
        expected = b'{"id":1,"name":"Printer HP"}'
        self.assertEqual(expected, result.content)

    def test_printer_json_not(self):
        result = printer_json(12312312)
        expected = b'{"Error": "Public key does not match or Printer does not exist"}'
        self.assertEqual(expected, result.content)

    def test_update_printer_name(self):
        result = update_printer_name(self.printer.key, self.printer.secret_key,
                                     "new_name")
        expected = b'{"id":1,"name":"new_name"}'
        self.assertEqual(expected, result.content)

    def test_update_printer_name_not(self):
        result = update_printer_name(self.printer.key, 123123, "new_name")
        expected = b'{"Error": "Public and Private key does not match"}'
        self.assertEqual(expected, result.content)

    def test_configure_printer(self):
        self.printer.secret_key = None
        self.printer.save()
        self.assertFalse(self.printer.secret_key)
        configure_printer(self.printer.key)
        printer = Printer.objects.get(id=self.printer.id)
        self.assertTrue(printer.secret_key)

    def test_configure_printer_error(self):
        self.assertTrue(self.printer.secret_key)
        result = configure_printer(self.printer.key)
        expected = b'{"Error": "Public key incorrect, or Printer already configured"}'
        self.assertTrue(expected, result.content)

    @patch('badges_app.utils.redis_conn', return_value=fakeredis.FakeRedis())
    def test_printer_queue(self, mock_redis):
        rc = fakeredis.FakeStrictRedis()
        organization = OrganizationFactory(name='Org1')
        event = EventFactory(name="Event", organization=organization)
        order = OrderFactory(event=event, email='*****@*****.**')
        attendee = AttendeeFactory(
            first_name='Test',
            last_name='Mock',
            order=order,
        )
        job_key = "job_{}".format(1)
        job_data = {
            'job_key': job_key,
            'attendee_id': attendee.id,
        }
        rc.set(job_key, pickle.dumps(job_data))
        printer_key = 'printer_{}'.format(self.printer.id)
        rc.rpush(printer_key, job_key)
        result = printer_queue(self.printer.key)
        expected = b'[{"job_key": "job_1", "content": "^XA^FX^CFA,30^FO50,100^FD^F^AV,20,20^FO40,30^FDTest^FS^AV,20,20^FO40,100^FDMock^FS^CFA,15^FO50,350^GB500,1,3^FS^FS^FS^FS^FS^FO^FO^FO^FO^FS^FO370,30^BQN,2,8^FD , Test , Mock , [email protected] , Org1 ^XZ"}]'
        self.assertEqual(result.content, expected)

    @patch('badges_app.utils.redis_conn',
           return_value=fakeredis.FakeStrictRedis())
    def test_printer_queue_not_items(self, mock_redis):
        rc = fakeredis.FakeStrictRedis()
        rc.flushdb()
        result = printer_queue(self.printer.key)
        expected = b'{"Error": "the queue is empty"}'
        self.assertEqual(result.content, expected)

    @patch('badges_app.utils.redis_conn', return_value=fakeredis.FakeRedis())
    def test_confirm_jobs(self, mock_redis):
        rc = fakeredis.FakeStrictRedis()
        job_key = "job_{}".format(1)
        job_data = {
            'job_key': job_key,
            'first_name': "Test",
            'last_name': "Mock"
        }
        rc.set(job_key, pickle.dumps(job_data))
        printer_key = 'printer_{}'.format(self.printer.id)
        rc.rpush(printer_key, job_key)
        result = confirm_job(self.printer.key, self.printer.secret_key,
                             job_key)
        expected = b'{"job_key": "job_1", "delete": "ok"}'
        self.assertEqual(result.content, expected)
Ejemplo n.º 6
0
 def test_create_printer_with_name(self):
     printer = PrinterFactory(name="Printer HP")
     self.assertIsInstance(printer, Printer)
Ejemplo n.º 7
0
 def test_create_printer(self):
     printer = PrinterFactory()
     self.assertIsInstance(printer, Printer)