コード例 #1
0
 def setUp(self):
     # First, create an instance of the Testbed class.
     self.testbed = testbed.Testbed()
     # Then activate the testbed, which prepares the service stubs for use.
     self.testbed.activate()
     # Next, declare which service stubs you want to use.
     self.testbed.init_datastore_v3_stub()
     self.testbed.init_memcache_stub()
     self.storage = BlogAppengineDataStore()
 def setUp(self):
     # First, create an instance of the Testbed class.
     self.testbed = testbed.Testbed()
     # Then activate the testbed, which prepares the service stubs for use.
     self.testbed.activate()
     # Next, declare which service stubs you want to use.
     self.testbed.init_datastore_v3_stub()
     self.testbed.init_memcache_stub()
     self.storage = BlogAppengineDataStore()
コード例 #3
0
class BlogDataStoreFactory():
    '''
    classdocs
    '''
    storage_implementations = {
        'memory': BlogMemoryDataStore(),
        'appengine': BlogAppengineDataStore()
    }

    def __init__(self, storage_impl='appengine'):
        '''
        Constructor
        '''
        self.storage = self.storage_implementations[storage_impl]

    def set_storage(self, blog_storage):
        self.storage = blog_storage

    def get_storage(self):
        return self.storage
コード例 #4
0
class Test(unittest.TestCase):
    def setUp(self):
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Next, declare which service stubs you want to use.
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.storage = BlogAppengineDataStore()

    def tearDown(self):
        self.testbed.deactivate()

    def testPut(self):
        data = BlogData(subject='Foo', content='Foo blog')
        data.put()
        pass

    def test_save(self):
        b3 = BlogData(subject='blog1', content='This is blog1')
        self.storage.save(b3)
        b3a = self.storage.fetch(1)
        self.assertEquals(
            b3.subject, b3a.subject, "Blog " + str(b3) +
            ' was not saved. This was saved instead: ' + str(b3a))
        self.assertEquals(
            b3.content, b3a.content, "Blog " + str(b3) +
            ' was not saved. This was saved instead: ' + str(b3a))
        pass

    def test_fetch(self):
        b = BlogData(subject='blog1', content='This is blog1')
        expected = b.subject
        self.storage.save(b)
        b1 = self.storage.fetch(1)
        self.assertEquals(expected, b1.subject,
                          "Blog with id " + str(expected) + ' was not found.')
        pass

    def test_fetchAll(self):
        b1 = BlogData(subject='blog1', content='This is blog1')
        self.storage.save(b1)
        b2 = BlogData(subject='blog2', content='This is blog2')
        self.storage.save(b2)
        expected = 2
        actual = list(self.storage.fetchAll())
        actual_count = len(actual)
        self.assertEquals(
            expected, actual_count, "Blog count of " + str(expected) +
            ' size was not found. Actual count: ' + str(actual_count))
        print repr(actual)
コード例 #5
0
class Test(unittest.TestCase):
    def setUp(self):
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Next, declare which service stubs you want to use.
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.storage = BlogAppengineDataStore()

    def tearDown(self):
        pass

    def test_BlogToJson(self):
        blog = BlogData(subject="Test1", content="Test1 blog content")
        self.storage.save(blog)
        blog_id = blog.key().id()
        stored_blog = self.storage.fetch(blog_id)
        actual = JsonUtils.blog_to_json(stored_blog)
        self.assertTrue(
            '"subject": "Test1"' in actual,
            "Blog subject not parsed correctly in blog data: " + repr(actual))
        self.assertTrue(
            '"content": "Test1 blog content"' in actual,
            "Blog content not parsed correctly in blog data: " + repr(actual))

    def test_BlogToJson_with_single_quote(self):
        blog = BlogData(subject="Test1", content="Test1 blog's content")
        self.storage.save(blog)
        blog_id = blog.key().id()
        stored_blog = self.storage.fetch(blog_id)
        actual = JsonUtils.blog_to_json(stored_blog)
        self.assertTrue(
            '"subject": "Test1"' in actual,
            "Blog subject not parsed correctly in blog data: " + repr(actual))
        self.assertTrue(
            '"content": "Test1 blog\'s content"' in actual,
            "Blog content not parsed correctly in blog data: " + repr(actual))

    def test_BlogToJson_with_double_quote(self):
        blog = BlogData(subject="Test1", content='Test1 blog"s content')
        self.storage.save(blog)
        blog_id = blog.key().id()
        stored_blog = self.storage.fetch(blog_id)
        actual = JsonUtils.blog_to_json(stored_blog)
        self.assertTrue(
            '"subject": "Test1"' in actual,
            "Blog subject not parsed correctly in blog data: " + repr(actual))
        self.assertTrue(
            '"content": "Test1 blog\\"s content"' in actual,
            "Blog content not parsed correctly in blog data: " + repr(actual))

    def test_BlogListToJson(self):
        blog1 = BlogData(subject="Test1", content='Test1 blog content')
        self.storage.save(blog1)
        blog2 = BlogData(subject="Test2", content='Test2 blog content')
        self.storage.save(blog2)
        blog_list = self.storage.fetchAll()
        actual = JsonUtils.blog_list_to_json(blog_list)
        print actual
        print str(len(actual))
        self.assertFalse(len(actual) == 0)
class Test(unittest.TestCase):

    def setUp(self):
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Next, declare which service stubs you want to use.
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.storage = BlogAppengineDataStore()
        
    
    def tearDown(self):
        self.testbed.deactivate()

    def testPut(self):
        data = BlogData(subject='Foo',content='Foo blog')
        data.put()
        pass

    def test_save(self):
        b3 = BlogData(subject='blog1',content='This is blog1')
        self.storage.save(b3)
        b3a = self.storage.fetch(1)
        self.assertEquals(b3.subject, b3a.subject, "Blog " + str(b3) + ' was not saved. This was saved instead: ' + str(b3a))
        self.assertEquals(b3.content, b3a.content, "Blog " + str(b3) + ' was not saved. This was saved instead: ' + str(b3a))
        pass

    def test_fetch(self):
        b = BlogData(subject='blog1',content='This is blog1')
        expected = b.subject 
        self.storage.save(b)
        b1 = self.storage.fetch(1)
        self.assertEquals(expected, b1.subject, "Blog with id " + str(expected) + ' was not found.')
        pass

    def test_fetchAll(self):
        b1 = BlogData(subject='blog1',content='This is blog1')
        self.storage.save(b1)
        b2 = BlogData(subject='blog2',content='This is blog2')
        self.storage.save(b2)
        expected = 2
        actual = list(self.storage.fetchAll())
        actual_count = len(actual)
        self.assertEquals(expected, actual_count, "Blog count of " + str(expected) + ' size was not found. Actual count: ' + str(actual_count))
        print repr(actual)
コード例 #7
0
class Test(unittest.TestCase):


    def setUp(self):
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Next, declare which service stubs you want to use.
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.storage = BlogAppengineDataStore()


    def tearDown(self):
        pass


    def test_BlogToJson(self):
        blog = BlogData(subject="Test1", content="Test1 blog content")
        self.storage.save(blog)
        blog_id = blog.key().id()
        stored_blog = self.storage.fetch(blog_id)
        actual = JsonUtils.blog_to_json(stored_blog);
        self.assertTrue('"subject": "Test1"' in actual,"Blog subject not parsed correctly in blog data: " + repr(actual))
        self.assertTrue('"content": "Test1 blog content"' in actual,"Blog content not parsed correctly in blog data: " + repr(actual))
        
    def test_BlogToJson_with_single_quote(self):
        blog = BlogData(subject="Test1", content="Test1 blog's content")
        self.storage.save(blog)
        blog_id = blog.key().id()
        stored_blog = self.storage.fetch(blog_id)
        actual = JsonUtils.blog_to_json(stored_blog);
        self.assertTrue('"subject": "Test1"' in actual,"Blog subject not parsed correctly in blog data: " + repr(actual))
        self.assertTrue('"content": "Test1 blog\'s content"' in actual,"Blog content not parsed correctly in blog data: " + repr(actual))

    def test_BlogToJson_with_double_quote(self):
        blog = BlogData(subject="Test1", content='Test1 blog"s content')
        self.storage.save(blog)
        blog_id = blog.key().id()
        stored_blog = self.storage.fetch(blog_id)
        actual = JsonUtils.blog_to_json(stored_blog);
        self.assertTrue('"subject": "Test1"' in actual,"Blog subject not parsed correctly in blog data: " + repr(actual))
        self.assertTrue('"content": "Test1 blog\\"s content"' in actual,"Blog content not parsed correctly in blog data: " + repr(actual))

    def test_BlogListToJson(self):
        blog1 = BlogData(subject="Test1", content='Test1 blog content')
        self.storage.save(blog1)
        blog2 = BlogData(subject="Test2", content='Test2 blog content')
        self.storage.save(blog2)
        blog_list = self.storage.fetchAll()
        actual = JsonUtils.blog_list_to_json(blog_list);
        print actual
        print str(len(actual))
        self.assertFalse(len(actual) == 0)