示例#1
0
 def test_get_entry_by_key_multiple_values(self):
     key = "foo"
     value = ["bar", "baz"]
     create_entry(key, value)
     entry = get_entry(key)
     self.assertEqual(key, entry.key)
     self.assertListEqual(sorted(value), sorted(entry.value))
示例#2
0
 def test_get_entry_by_key(self):
     key = "foo"
     value = ["bar"]
     create_entry(key, value)
     entry = get_entry(key)
     self.assertEqual(key, entry.key)
     self.assertListEqual(value, list(entry.value))
示例#3
0
    def test_delete_entry(self):
        key = "foo"
        value = ["bar"]
        create_entry(key, value)
        event = gen_event(key, value)

        res = delete(event, None)
        self.assertEquals(204, res['statusCode'])
示例#4
0
    def test_list_entries(self):
        value = ["bar", "baz"]
        create_entry("foo", value)
        create_entry("foo2", value)
        res = list_entries(None, None)

        self.assertEquals(200, res['statusCode'])
        data = json.loads(res["body"])
        self.assertEqual(2, len(data['entries']))
示例#5
0
 def test_list_all_entries(self):
     value = ["bar", "baz"]
     create_entry("foo", value)
     create_entry("foo2", value)
     entries = list(list_all_entries())
     self.assertEqual(2, len(entries))
     for entry in entries:
         if entry.key in ["foo", "foo2"]:
             self.assertListEqual(sorted(entry.value), sorted(value))
示例#6
0
    def test_update(self):
        value = ["bar", "baz"]
        value2 = ["foo", "meh"]
        create_entry("foo", value)
        event = gen_event("foo", value2)
        res = update(event, None)

        self.assertEqual(200, res['statusCode'])
        data = json.loads(res["body"])
        self.assertEqual(sorted(value2), sorted(data["value"]))
示例#7
0
    def test_get_entry(self):
        key = "foo"
        value = ["bar"]
        create_entry(key, value)
        event = gen_event(key, value)

        res = get(event, None)
        self.assertEquals(200, res['statusCode'])
        data = json.loads(res["body"])
        self.assertEquals(data, {"key": key, "value": value})
示例#8
0
    def test_update_entry_nonlist_value(self):
        value = ["bar", "baz"]
        value2 = "hello"
        create_entry("foo", value)

        with self.assertRaises(ValidationError) as exc:
            update_entry("foo", value2)
        self.assertEqual(exc.exception.field, "value")
        self.assertEqual(exc.exception.message,
                         "'value' must be a list of strings")
示例#9
0
    def test_get_entry_multiple_values(self):
        key = "foo"
        value = ["bar", "baz"]
        create_entry(key, value)
        event = gen_event(key, None)

        res = get(event, None)
        self.assertEquals(200, res['statusCode'])
        data = json.loads(res["body"])
        data['value'] = sorted(data['value'])
        self.assertDictEqual(data, {"key": key, "value": sorted(value)})
示例#10
0
    def test_update_no_value(self):
        key = "foo"
        create_entry(key, ["bar"])
        event = {
            "pathParameters": {
                "key": key
            },
            "body": json.dumps({"key": key})
        }
        res = update(event, None)

        self.assertEquals(422, res['statusCode'])
        data = json.loads(res["body"])
        self.assertEqual(
            data["error_message"],
            "value: Invalid Request.  Missing 'value' field in json request.")
示例#11
0
 def test_create_entry_nonstring_key(self):
     key = 1
     value = ["bar"]
     with self.assertRaises(ValidationError) as exc:
         entry = create_entry(key, value)
     self.assertEqual(exc.exception.field, "key")
     self.assertEqual(exc.exception.message, "'key' must be a string.")
示例#12
0
 def test_create_entry_nonlist_value(self):
     key = "foo"
     value = [1]
     with self.assertRaises(ValidationError) as exc:
         entry = create_entry(key, value)
     self.assertEqual(exc.exception.field, "value")
     self.assertEqual(exc.exception.message,
                      "'value' must be a list of strings")
示例#13
0
def create(event, context):
    try:
        data = json.loads(event["body"])
        validate_fields_present(data, require_key=True, require_value=True)
    except HTTPError as exc:
        return exc.as_response()

    entry = kvstore.create_entry(data["key"], data["value"])
    return {"statusCode": 201,
            "body": json.dumps(_serialize_entry(entry))}
示例#14
0
    def test_update_entry(self):
        value1 = ['foo', 'bar']
        value2 = ['bar', 'baz']
        entry = create_entry("foo", value1)
        self.assertListEqual(sorted(value1), sorted(entry.value))

        updated_entry = update_entry('foo', value2)
        self.assertListEqual(sorted(value2), sorted(updated_entry.value))

        entry.refresh()
        self.assertListEqual(sorted(value2), sorted(entry.value))
示例#15
0
 def test_create_entry(self):
     key = "foo"
     value = ["bar"]
     entry = create_entry(key, value)
     self.assertEqual(key, entry.key)
     self.assertListEqual(value, entry.value)
示例#16
0
 def test_delete_entry(self):
     value = ["bar", "baz"]
     create_entry("foo", value)
     delete_entry("foo")
     with self.assertRaises(DoesNotExist):
         get_entry("foo")