Ejemplo n.º 1
0
    def test_parse_command_set(self):
        """
        Behaviour of the set command is represented below.

        |   command               |  Expected              |
        +-------------------------+------------------------+
        | SET k1 "some test data" | k1 -> "some test data" |
        | SET k2 "some test data" | k2 -> "some test data" |
        | SET k2 more test data   | k2 -> "more test data" |
        | SET k3 "me " TTL=20     | k3 -> "me "            |
        | SET k4                  | Exception - wrong args |
        | SET                     | Exception - wrong args |
        """
        status = ncache.parse_command('SET k1 "some test data"')
        self.assertEqual(status, 'SUCCESS')
        data = ncache._get_or_timeout('k1')
        self.assertEqual(data, 'some test data')

        status = ncache.parse_command('SET k2 "some test data"')
        self.assertEqual(status, 'SUCCESS')
        data = ncache._get_or_timeout('k2')
        self.assertEqual(data, 'some test data')

        status = ncache.parse_command('SET k2 more test data')
        self.assertEqual(status, 'SUCCESS')
        data = ncache._get_or_timeout('k2')
        self.assertEqual(data, 'more test data')

        status = ncache.parse_command('SET k3 "me " TTL=20')
        self.assertEqual(status, 'SUCCESS')
        data = ncache._get_or_timeout('k3')
        self.assertEqual(data, 'me ')

        with self.assertRaises(ValueError):
            ncache.parse_command('SET k4')
        with self.assertRaises(ValueError):
            ncache.parse_command('SET')
Ejemplo n.º 2
0
    def test_parse_command_get(self):
        """
        Behaviour of the set command is represented below.

        |   command               |  Expected              |
        +-------------------------+------------------------+
        | SET k3 "me "            | k3 -> "me "            |
        | GET thing               | NOT FOUND              |
        | GET k3                  | "me "                  |
        | GET                     | Exception - wrong args |
        | GET my head             | Exception - wrong args |
        """
        status = ncache.parse_command('SET k3 "me "')
        self.assertEqual(status, 'SUCCESS')
        data = ncache.parse_command('GET thing')
        self.assertEqual(data, 'NOT FOUND')
        data = ncache.parse_command('GET k3')
        self.assertEqual(data, 'me ')

        with self.assertRaises(ValueError):
            ncache.parse_command('GET')
        with self.assertRaises(ValueError):
            ncache.parse_command('GET my head')