コード例 #1
0
    def test_post_insert(self):
        payload = [
            {
                'vendor_hex': '0x1002',
                'adapter_hex': '0x0166',
                'vendor_name': 'Logitech Inc.',
                'adapter_name': 'Unknown Webcam Pro 9000'
            },
        ]

        api = GraphicsDevices(config=self.config)
        res = api.post(data=json.dumps(payload))
        eq_(res, True)

        cursor = self.connection.cursor()
        cursor.execute("""
            select vendor_hex, adapter_hex, vendor_name, adapter_name
            from graphics_device
            order by vendor_hex, adapter_hex
        """)
        expect = []
        keys = 'vendor_hex', 'adapter_hex', 'vendor_name', 'adapter_name'
        for row in cursor.fetchall():
            expect.append(dict(zip(keys, row)))

        eq_(expect, payload)
コード例 #2
0
    def test_post_update(self):
        self._insert(
            '0x1002', '0x0166',
            vendor_name='Logitech Inc.',
            adapter_name='Unknown Webcam Pro 9000'
        )

        payload = [
            {
                'vendor_hex': '0x1002',
                'adapter_hex': '0x0166',
                'vendor_name': 'Logitech Inc.',
                'adapter_name': 'Known Webcam Pro 10000'  # the change
            }
        ]

        api = GraphicsDevices(config=self.config)
        res = api.post(data=payload)
        eq_(res, True)

        cursor = self.connection.cursor()
        cursor.execute("""
            select vendor_hex, adapter_hex, vendor_name, adapter_name
            from graphics_device
            order by vendor_hex, adapter_hex
        """)
        expect = []
        keys = 'vendor_hex', 'adapter_hex', 'vendor_name', 'adapter_name'
        for row in cursor.fetchall():
            expect.append(dict(zip(keys, row)))

        eq_(expect, payload)
コード例 #3
0
    def test_post_insert(self):
        payload = [
            {
                'vendor_hex': '0x1002',
                'adapter_hex': '0x0166',
                'vendor_name': 'Logitech Inc.',
                'adapter_name': 'Unknown Webcam Pro 9000'
            },
        ]

        api = GraphicsDevices(config=self.config)
        res = api.post(data=json.dumps(payload))
        self.assertEqual(res, True)

        cursor = self.connection.cursor()
        cursor.execute("""
            select vendor_hex, adapter_hex, vendor_name, adapter_name
            from graphics_device
            order by vendor_hex, adapter_hex
        """)
        expect = []
        keys = 'vendor_hex', 'adapter_hex', 'vendor_name', 'adapter_name'
        for row in cursor.fetchall():
            expect.append(dict(zip(keys, row)))

        self.assertEqual(expect, payload)
コード例 #4
0
    def test_post_update(self):
        self._insert('0x1002',
                     '0x0166',
                     vendor_name='Logitech Inc.',
                     adapter_name='Unknown Webcam Pro 9000')

        payload = [{
            'vendor_hex': '0x1002',
            'adapter_hex': '0x0166',
            'vendor_name': 'Logitech Inc.',
            'adapter_name': 'Known Webcam Pro 10000'  # the change
        }]

        api = GraphicsDevices(config=self.config)
        res = api.post(data=payload)
        assert res is True

        cursor = self.connection.cursor()
        cursor.execute("""
            select vendor_hex, adapter_hex, vendor_name, adapter_name
            from graphics_device
            order by vendor_hex, adapter_hex
        """)
        expect = []
        keys = 'vendor_hex', 'adapter_hex', 'vendor_name', 'adapter_name'
        for row in cursor.fetchall():
            expect.append(dict(zip(keys, row)))

        assert expect == payload
コード例 #5
0
 def test_post_fail(self):
     payload = [
         {
             'rubbish': 'Crap'
         },
     ]
     api = GraphicsDevices(config=self.config)
     res = api.post(data=payload)
     eq_(res, False)
コード例 #6
0
 def test_post_fail(self):
     payload = [
         {
             'rubbish': 'Crap'
         },
     ]
     api = GraphicsDevices(config=self.config)
     res = api.post(data=json.dumps(payload))
     eq_(res, False)
コード例 #7
0
 def test_post_fail(self):
     payload = [
         {
             'rubbish': 'Crap'
         },
     ]
     api = GraphicsDevices(config=self.config)
     res = api.post(data=json.dumps(payload))
     self.assertEqual(res, False)
コード例 #8
0
 def test_post_fail(self):
     payload = [
         {
             'rubbish': 'Crap'
         },
     ]
     api = GraphicsDevices(config=self.config)
     res = api.post(data=payload)
     assert res is False
コード例 #9
0
    def test_post_upsert(self):
        """on .post() every item you send in the payload causes an upsert"""
        # first, insert something that we're going have to do nothing with
        # or do an "upsert"
        self._insert(
            '0x1002', '0x0166',
            vendor_name='Logitech Inc.',
            adapter_name='Unknown Webcam Pro 9000'
        )
        self._insert(
            '0x1222', '0x0166',
            vendor_name='Chicony Electronics Co.',
            adapter_name='Unknown Webcam Pro 9000'
        )

        # note, this is conveniently sorted by
        # vendor_hex followed by adapter_hex
        payload = [
            {
                'vendor_hex': '0x1002',
                'adapter_hex': '0x0166',
                'vendor_name': 'Logitech Inc.',
                'adapter_name': 'Unknown Webcam Pro 9000'
            },
            {
                'vendor_hex': '0x1222',
                'adapter_hex': '0x0166',
                'vendor_name': 'Chicony Electronics Co.',
                'adapter_name': 'Something else'
            },
            {
                'vendor_hex': '0x1333',
                'adapter_hex': '0x0177',
                'vendor_name': 'IBM',
                'adapter_name': ''
            },
        ]

        api = GraphicsDevices(config=self.config)
        res = api.post(data=payload)
        eq_(res, True)

        cursor = self.connection.cursor()
        cursor.execute("""
            select vendor_hex, adapter_hex, vendor_name, adapter_name
            from graphics_device
            order by vendor_hex, adapter_hex
        """)
        expect = []
        keys = 'vendor_hex', 'adapter_hex', 'vendor_name', 'adapter_name'
        for row in cursor.fetchall():
            expect.append(dict(zip(keys, row)))

        eq_(expect, payload)
コード例 #10
0
    def test_post_upsert(self):
        """on .post() every item you send in the payload causes an upsert"""
        # first, insert something that we're going have to do nothing with
        # or do an "upsert"
        self._insert(
            '0x1002', '0x0166',
            vendor_name='Logitech Inc.',
            adapter_name='Unknown Webcam Pro 9000'
        )
        self._insert(
            '0x1222', '0x0166',
            vendor_name='Chicony Electronics Co.',
            adapter_name='Unknown Webcam Pro 9000'
        )

        # note, this is conveniently sorted by
        # vendor_hex followed by adapter_hex
        payload = [
            {
                'vendor_hex': '0x1002',
                'adapter_hex': '0x0166',
                'vendor_name': 'Logitech Inc.',
                'adapter_name': 'Unknown Webcam Pro 9000'
            },
            {
                'vendor_hex': '0x1222',
                'adapter_hex': '0x0166',
                'vendor_name': 'Chicony Electronics Co.',
                'adapter_name': 'Something else'
            },
            {
                'vendor_hex': '0x1333',
                'adapter_hex': '0x0177',
                'vendor_name': 'IBM',
                'adapter_name': ''
            },
        ]

        api = GraphicsDevices(config=self.config)
        res = api.post(data=json.dumps(payload))
        eq_(res, True)

        cursor = self.connection.cursor()
        cursor.execute("""
            select vendor_hex, adapter_hex, vendor_name, adapter_name
            from graphics_device
            order by vendor_hex, adapter_hex
        """)
        expect = []
        keys = 'vendor_hex', 'adapter_hex', 'vendor_name', 'adapter_name'
        for row in cursor.fetchall():
            expect.append(dict(zip(keys, row)))

        eq_(expect, payload)
コード例 #11
0
 def test_get_missing_arguments(self):
     """on .get() the adapter_hex and the vendor_hex is mandatory"""
     api = GraphicsDevices(config=self.config)
     assert_raises(
         MissingArgumentError,
         api.get
     )
     assert_raises(
         MissingArgumentError,
         api.get,
         adapter_hex='something'
     )
     assert_raises(
         MissingArgumentError,
         api.get,
         vendor_hex='something'
     )
     assert_raises(
         MissingArgumentError,
         api.get,
         vendor_hex='something',
         adapter_hex=''  # empty!
     )
     assert_raises(
         MissingArgumentError,
         api.get,
         vendor_hex='',  # empty!
         adapter_hex='something'
     )
コード例 #12
0
    def test_get(self):
        """returning rows by matching vendor_hex and adapter_hex"""
        api = GraphicsDevices(config=self.config)

        params = {
            'vendor_hex': '0x1002',
            'adapter_hex': '0x0166',
        }
        res = api.get(**params)
        res_expected = {
            'hits': [],
            'total': 0
        }
        eq_(res, res_expected)

        # insert something similar
        self._insert(
            '0x1002', '0x0166',
            vendor_name='Logitech Inc.',
            adapter_name='Unknown Webcam Pro 9000'
        )
        self._insert(
            '0x1002', '0xc064',
            vendor_name='Logitech Inc.',
            adapter_name='k251d DELL 6-Button mouse'
        )
        self._insert(
            '0x1222', '0x0166',
            vendor_name='Chicony Electronics Co.',
            adapter_name='Unknown Webcam Pro 9000'
        )

        # now we should get something
        res = api.get(**params)
        res_expected = {
            'hits': [{
                'vendor_hex': '0x1002',
                'adapter_hex': '0x0166',
                'vendor_name': 'Logitech Inc.',
                'adapter_name': 'Unknown Webcam Pro 9000'
            }],
            'total': 1
        }
        eq_(res, res_expected)
コード例 #13
0
    def test_get(self):
        """returning rows by matching vendor_hex and adapter_hex"""
        api = GraphicsDevices(config=self.config)

        params = {
            'vendor_hex': '0x1002',
            'adapter_hex': '0x0166',
        }
        res = api.get(**params)
        res_expected = {
            'hits': [],
            'total': 0
        }
        eq_(res, res_expected)

        # insert something similar
        self._insert(
            '0x1002', '0x0166',
            vendor_name='Logitech Inc.',
            adapter_name='Unknown Webcam Pro 9000'
        )
        self._insert(
            '0x1002', '0xc064',
            vendor_name='Logitech Inc.',
            adapter_name='k251d DELL 6-Button mouse'
        )
        self._insert(
            '0x1222', '0x0166',
            vendor_name='Chicony Electronics Co.',
            adapter_name='Unknown Webcam Pro 9000'
        )

        # now we should get something
        res = api.get(**params)
        res_expected = {
            'hits': [{
                'vendor_hex': '0x1002',
                'adapter_hex': '0x0166',
                'vendor_name': 'Logitech Inc.',
                'adapter_name': 'Unknown Webcam Pro 9000'
            }],
            'total': 1
        }
        eq_(res, res_expected)
コード例 #14
0
 def test_get_missing_arguments(self):
     """on .get() the adapter_hex and the vendor_hex is mandatory"""
     api = GraphicsDevices(config=self.config)
     with pytest.raises(MissingArgumentError):
         api.get()
     with pytest.raises(MissingArgumentError):
         api.get(adapter_hex='something')
     with pytest.raises(MissingArgumentError):
         api.get(vendor_hex='something')
     with pytest.raises(MissingArgumentError):
         # adapter_hex is empty!
         api.get(vendor_hex='something', adapter_hex='')
     with pytest.raises(MissingArgumentError):
         # vender_hex is empty!
         api.get(vendor_hex='', adapter_hex='something')
コード例 #15
0
 def test_get_missing_arguments(self):
     """on .get() the adapter_hex and the vendor_hex is mandatory"""
     api = GraphicsDevices(config=self.config)
     with pytest.raises(MissingArgumentError):
         api.get()
     with pytest.raises(MissingArgumentError):
         api.get(adapter_hex='something')
     with pytest.raises(MissingArgumentError):
         api.get(vendor_hex='something')
     with pytest.raises(MissingArgumentError):
         # adapter_hex is empty!
         api.get(vendor_hex='something', adapter_hex='')
     with pytest.raises(MissingArgumentError):
         # vender_hex is empty!
         api.get(vendor_hex='', adapter_hex='something')