'Tests that update with if_exists work as expected
@since 3.1
@jira_ticket PYTHON-432
@expected_result updates to be applied when primary key exists, otherwise LWT exception to be thrown
@test_category object_mapper'

@unittest.skipUnless((PROTOCOL_VERSION >= 2), 'only    runs    against    the    cql3    protocol    v2.0')
def test_update_if_exists(self):

    id = uuid4()
    m = TestIfExistsModel.create(id=id, count=8, text='123456789')
    m.text = 'changed'
    m.if_exists().update()
    m = TestIfExistsModel.get(id=id)
    self.assertEqual(m.text, 'changed')
    m.text = 'changed_again'
    m.if_exists().save()
    m = TestIfExistsModel.get(id=id)
    self.assertEqual(m.text, 'changed_again')
    m = TestIfExistsModel(id=uuid4(), count=44)
    with self.assertRaises(LWTException) as assertion:
        m.if_exists().update()
    self.assertEqual(assertion.exception.existing, {'[applied]': False})
    with self.assertRaises(LWTException) as assertion:
        TestIfExistsModel.objects(id=uuid4()).if_exists().update(count=8)
    self.assertEqual(assertion.exception.existing, {'[applied]': False})
