def test_wrong_cookie_format(self): with open(self.tf.name, 'w') as f: f.write('[1, 2, 3]\n') c = Cookie(self.tf.name) with self.assertRaises(ValueError): c.open() c.close()
def test_wrong_cookie_format(self): with open(self.tf.name, 'w') as f: f.write('[1, 2, 3]\n') c = Cookie(self.tf.name) with self.assertRaises(ValueError): c.open() c.close()
def test_corrupted_cookie_should_raise(self): with open(self.tf.name, 'w') as f: f.write('{{{') c = Cookie(self.tf.name) with self.assertRaises(ValueError): c.open() c.close()
def test_corrupted_cookie_should_raise(self): with open(self.tf.name, 'w') as f: f.write('{{{') c = Cookie(self.tf.name) with self.assertRaises(ValueError): c.open() c.close()
def test_oblivious_cookie(self): c = Cookie('') # the following method calls are not expected to perfom any function c.open() c['key'] = 1 c.commit() c.close() self.assertEqual(c['key'], 1)
def test_close_removes_file_if_no_value_set(self): try: os.unlink("cookietest") except OSError: pass c = Cookie("cookietest") c.close() self.failIf(os.path.exists("cookietest"), u"file 'cookietest' does exist but shouldn't")
def test_oblivious_cookie(self): c = Cookie('') # the following method calls are not expected to perfom any function c.open() c['key'] = 1 c.commit() c.close() self.assertEqual(c['key'], 1)
def test_cookie_format_exception_truncates_file(self): with codecs.open(self.tf.name, 'w', 'utf-8') as f: f.write('{slö@@ä') c = Cookie(self.tf.name) try: c.open() except ValueError: pass finally: c.close() self.assertEqual(0, os.stat(self.tf.name).st_size)
def test_cookie_format_exception_truncates_file(self): with codecs.open(self.tf.name, 'w', 'utf-8') as f: f.write('{slö@@ä') c = Cookie(self.tf.name) try: c.open() except ValueError: pass finally: c.close() self.assertEqual(0, os.stat(self.tf.name).st_size)
def test_multiple_commit(self): c = Cookie(self.tf.name) c.open() c['key'] = 1 c.commit() with open(self.tf.name) as f: self.assertIn('"key": 1', f.read()) c['key'] = 2 c.commit() with open(self.tf.name) as f: self.assertIn('"key": 2', f.read()) c.close()
def test_multiple_commit(self): c = Cookie(self.tf.name) c.open() c['key'] = 1 c.commit() with open(self.tf.name) as f: self.assertIn('"key": 1', f.read()) c['key'] = 2 c.commit() with open(self.tf.name) as f: self.assertIn('"key": 2', f.read()) c.close()
def test_double_close_raises_no_exception(self): c = Cookie(self.tf.name) c.open() c.close() c.close() self.assertTrue(True)
def test_double_close_raises_no_exception(self): c = Cookie(self.tf.name) c.open() c.close() c.close() self.assertTrue(True)