Exemplo n.º 1
0
def test_get_entity_from_url_safe_key(testbed):
    sandy_key = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    result = snippets.get_entity_from_url_safe_key(
        snippets.get_url_safe_key(sandy_key))
    assert isinstance(result, snippets.Account)
    assert result.username == 'Sandy'
def test_get_entity_from_url_safe_key(testbed):
    sandy_key = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    result = snippets.get_entity_from_url_safe_key(
        snippets.get_url_safe_key(sandy_key))
    assert isinstance(result, snippets.Account)
    assert result.username == 'Sandy'
Exemplo n.º 3
0
def test_update_entity_from_key(testbed):
    sandy = snippets.create_entity_using_keyword_arguments()
    sandy_key = snippets.save_entity(sandy)
    urlsafe = snippets.get_url_safe_key(sandy_key)
    key, ident, kind_string = (
        snippets.get_key_and_numeric_id_from_url_safe_key(urlsafe))
    snippets.update_entity_from_key(key)
    assert key.get().email == '*****@*****.**'
Exemplo n.º 4
0
def test_get_key_and_numeric_id_from_url_safe_key(testbed):
    sandy_key = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    urlsafe = snippets.get_url_safe_key(sandy_key)
    key, ident, kind_string = (
        snippets.get_key_and_numeric_id_from_url_safe_key(urlsafe))
    assert isinstance(key, ndb.Key)
    assert isinstance(kind_string, str)
def test_update_entity_from_key(testbed):
    sandy = snippets.create_entity_using_keyword_arguments()
    sandy_key = snippets.save_entity(sandy)
    urlsafe = snippets.get_url_safe_key(sandy_key)
    key, ident, kind_string = (
        snippets.get_key_and_numeric_id_from_url_safe_key(urlsafe))
    snippets.update_entity_from_key(key)
    assert key.get().email == '*****@*****.**'
Exemplo n.º 6
0
def test_get_entity_from_url_safe_key(testbed):
    sandy_key = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    result = snippets.get_entity_from_url_safe_key(
        snippets.get_url_safe_key(sandy_key))
    if not isinstance(result, snippets.Account):
        raise AssertionError
    if result.username != 'Sandy':
        raise AssertionError
def test_get_key_and_numeric_id_from_url_safe_key(testbed):
    sandy_key = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    urlsafe = snippets.get_url_safe_key(sandy_key)
    key, ident, kind_string = (
        snippets.get_key_and_numeric_id_from_url_safe_key(urlsafe))
    assert isinstance(key, ndb.Key)
    assert isinstance(ident, long)
    assert isinstance(kind_string, str)
Exemplo n.º 8
0
    def get(self):
        result = snippets.save_entity(
            snippets.create_entity_using_keyword_arguments())

        logger.debug("putResult {}".format(result))

        result = snippets.get_entity(result)
        logger.debug("Get Result {}".format(result))

        self.response.out.write('<html><body>')
        guestbook_name = self.request.get('guestbook_name')
        ancestor_key = ndb.Key("Book", guestbook_name or "*notitle*")
        greetings = Greeting.query_book(ancestor_key).fetch(20)
        # [END query]

        greeting_blockquotes = []
        for greeting in greetings:
            greeting_blockquotes.append('<blockquote>%s</blockquote>' %
                                        cgi.escape(greeting.content))

        self.response.out.write(
            textwrap.dedent("""\
            <html>
              <body>
                {blockquotes}
                <form action="/sign?{sign}" method="post">
                  <div>
                    <textarea name="content" rows="3" cols="60">
                    </textarea>
                  </div>
                  <div>
                    <input type="submit" value="Sign Guestbook">
                  </div>
                </form>
                <hr>
                <form>
                  Guestbook name:
                    <input value="{guestbook_name}" name="guestbook_name">
                    <input type="submit" value="switch">
                </form>
              </body>
            </html>""").format(blockquotes='\n'.join(greeting_blockquotes),
                               sign=urllib.urlencode(
                                   {'guestbook_name': guestbook_name}),
                               guestbook_name=cgi.escape(guestbook_name)))
def test_create_entity_using_keyword_arguments(testbed):
    result = snippets.create_entity_using_keyword_arguments()
    assert isinstance(result, snippets.Account)
Exemplo n.º 10
0
def test_get_key_kind_and_id(testbed):
    sandy_key = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    kind_string, ident = snippets.get_key_kind_and_id(sandy_key)
    if kind_string != 'Account':
        raise AssertionError
Exemplo n.º 11
0
def test_demonstrate_entity_attribute_type_checking(testbed):
    with pytest.raises(datastore_errors.BadValueError):
        snippets.demonstrate_entity_attribute_type_checking(
            snippets.create_entity_using_keyword_arguments())
def test_get_url_safe_key(testbed):
    sandy_key = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    result = snippets.get_url_safe_key(sandy_key)
    assert isinstance(result, str)
def test_get_key_kind_and_id(testbed):
    sandy_key = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    kind_string, ident = snippets.get_key_kind_and_id(sandy_key)
    assert kind_string == 'Account'
    assert isinstance(ident, long)
def test_save_entity(testbed):
    result = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    assert isinstance(result, snippets.ndb.Key)
def test_demonstrate_entity_attribute_type_checking(testbed):
    with pytest.raises(datastore_errors.BadValueError):
        snippets.demonstrate_entity_attribute_type_checking(
            snippets.create_entity_using_keyword_arguments())
Exemplo n.º 16
0
def test_delete_entity(testbed):
    sandy = snippets.create_entity_using_keyword_arguments()
    snippets.save_entity(sandy)
    snippets.delete_entity(sandy)
    if sandy.key.get() is not None:
        raise AssertionError
Exemplo n.º 17
0
def test_create_entity_using_keyword_arguments(testbed):
    result = snippets.create_entity_using_keyword_arguments()
    if not isinstance(result, snippets.Account):
        raise AssertionError
Exemplo n.º 18
0
def test_delete_entity(testbed):
    sandy = snippets.create_entity_using_keyword_arguments()
    snippets.save_entity(sandy)
    snippets.delete_entity(sandy)
    assert sandy.key.get() is None
Exemplo n.º 19
0
def test_save_entity(testbed):
    result = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    if not isinstance(result, snippets.ndb.Key):
        raise AssertionError
Exemplo n.º 20
0
def test_create_entity_using_keyword_arguments(testbed):
    result = snippets.create_entity_using_keyword_arguments()
    assert isinstance(result, snippets.Account)
Exemplo n.º 21
0
def test_get_url_safe_key(testbed):
    sandy_key = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    result = snippets.get_url_safe_key(sandy_key)
    if not isinstance(result, str):
        raise AssertionError
Exemplo n.º 22
0
def test_get_entity(testbed):
    sandy_key = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    result = snippets.get_entity(sandy_key)
    assert isinstance(result, snippets.Account)
Exemplo n.º 23
0
def test_get_key_kind_and_id(testbed):
    sandy_key = snippets.save_entity(
        snippets.create_entity_using_keyword_arguments())
    kind_string, ident = snippets.get_key_kind_and_id(sandy_key)
    assert kind_string == 'Account'
def test_delete_entity(testbed):
    sandy = snippets.create_entity_using_keyword_arguments()
    snippets.save_entity(sandy)
    snippets.delete_entity(sandy)
    assert sandy.key.get() is None