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)
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=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)
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)
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=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
def test_post_fail(self): payload = [ { 'rubbish': 'Crap' }, ] api = GraphicsDevices(config=self.config) res = api.post(data=payload) eq_(res, False)
def test_post_fail(self): payload = [ { 'rubbish': 'Crap' }, ] api = GraphicsDevices(config=self.config) res = api.post(data=json.dumps(payload)) eq_(res, False)
def test_post_fail(self): payload = [ { 'rubbish': 'Crap' }, ] api = GraphicsDevices(config=self.config) res = api.post(data=json.dumps(payload)) self.assertEqual(res, False)
def test_post_fail(self): payload = [ { 'rubbish': 'Crap' }, ] api = GraphicsDevices(config=self.config) res = api.post(data=payload) assert res is False
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)
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)