def setUp(self):
     from google.appengine.ext import db
     
     class CategoryData(DataSet):
         class red:
             color = 'red'
 
     class ProductData(DataSet):
         class red_truck:
             category = CategoryData.red
             sale_tag = "Big, Shiny Red Truck"
     self.ProductData = ProductData
     
     class Category(db.Model):
         color = db.StringProperty()
     self.Category = Category
     
     class Product(db.Model):
         category = db.ReferenceProperty(Category)
         sale_tag = db.StringProperty()
     self.Product = Product
                     
     self.fixture = GoogleDatastoreFixture(env={
         'CategoryData': self.Category,
         'ProductData': self.Product,
     })
 def setUp(self):
     from google.appengine.ext import db
     
     class Author(db.Model):
         name = db.StringProperty()
     self.Author = Author
     
     class Book(db.Model):
         title = db.StringProperty()
         authors = db.ListProperty(db.Key)
     self.Book = Book
     
     class AuthorData(DataSet):
         class frank_herbert:
             name = "Frank Herbert"
         class brian_herbert:
             name = "Brian Herbert"
             
     class BookData(DataSet):
          class two_worlds:
              title = "Man of Two Worlds"
              authors = [AuthorData.frank_herbert, AuthorData.brian_herbert]
     self.BookData = BookData
           
     self.fixture = GoogleDatastoreFixture(env={
         'BookData': self.Book,
         'AuthorData': self.Author
     })
 def setUp(self):
     from google.appengine.ext import db
     
     class Category(db.Model):
         name = db.StringProperty()        
     self.Category = Category
                     
     self.fixture = GoogleDatastoreFixture(env={'CategoryData': self.Category})
def main():
    p = optparse.OptionParser(usage="%prog [options]")
    default = "/tmp/dev_appserver.datastore"
    p.add_option(
        "--datastore_path",
        default=default,
        help=(
            "Path to datastore file.  This must match the value used for "
            "the same option when running dev_appserver.py if you want to view the data.  "
            "Default: %s" % default
        ),
    )
    default = "/tmp/dev_appserver.datastore.history"
    p.add_option(
        "--history_path",
        default=default,
        help=(
            "Path to datastore history file.  This doesn't need to match the one you use for "
            "dev_appserver.py.  Default: %s" % default
        ),
    )
    default = "/usr/local/google_appengine"
    p.add_option("--google_path", default=default, help=("Path to google module directory.  Default: %s" % default))
    (options, args) = p.parse_args()

    if not os.path.exists(options.google_path):
        p.error("Could not find google module path at %s.  You'll need to specify the path" % options.google_path)

    groot = options.google_path
    sys.path.append(groot)
    sys.path.append(os.path.join(groot, "lib/antlr3"))
    sys.path.append(os.path.join(groot, "lib/fancy_urllib"))
    sys.path.append(os.path.join(groot, "lib/webob-1.2.3"))
    sys.path.append(os.path.join(groot, "lib/yaml/lib"))
    sys.path.append("..")
    sys.path.append("../lib")

    from google.appengine.tools import dev_appserver
    import models
    from fixtures import language_holywood

    config, explicit_matcher, from_cache = dev_appserver.LoadAppConfig("..", {})
    dev_appserver.SetupStubs(
        config.application,
        clear_datastore=False,  # just removes the files when True
        datastore_path=options.datastore_path,
        history_path=options.history_path,
        blobstore_path="",
        login_url=None,
    )

    datafixture = GoogleDatastoreFixture(env=models, style=NamedDataStyle())

    data = datafixture.data(language_holywood.WeeksData, language_holywood.CourseData)
    data.setup()
    print "Data loaded into datastore %s" % (options.datastore_path or "[default]")
예제 #5
0
def main():
    p = optparse.OptionParser(usage="%prog [options]")
    default = "/tmp/dev_appserver.datastore"
    p.add_option(
        "--datastore_path",
        default=default,
        help=
        ("Path to datastore file.  This must match the value used for "
         "the same option when running dev_appserver.py if you want to view the data.  "
         "Default: %s" % default))
    default = "/tmp/dev_appserver.datastore.history"
    p.add_option(
        "--history_path",
        default=default,
        help=
        ("Path to datastore history file.  This doesn't need to match the one you use for "
         "dev_appserver.py.  Default: %s" % default))
    default = "/usr/local/google_appengine"
    p.add_option("--google_path",
                 default=default,
                 help=("Path to google module directory.  Default: %s" %
                       default))
    (options, args) = p.parse_args()

    if not os.path.exists(options.google_path):
        p.error(
            "Could not find google module path at %s.  You'll need to specify the path"
            % options.google_path)

    groot = options.google_path
    sys.path.append(groot)
    sys.path.append(os.path.join(groot, "lib/django"))
    sys.path.append(os.path.join(groot, "lib/webob"))
    sys.path.append(os.path.join(groot, "lib/yaml/lib"))

    from google.appengine.tools import dev_appserver
    from gblog import models
    from tests import datasets

    config, explicit_matcher = dev_appserver.LoadAppConfig(
        os.path.dirname(__file__), {})
    dev_appserver.SetupStubs(
        config.application,
        clear_datastore=False,  # just removes the files when True
        datastore_path=options.datastore_path,
        history_path=options.history_path,
        login_url=None)

    datafixture = GoogleDatastoreFixture(env=models, style=NamedDataStyle())

    data = datafixture.data(datasets.CommentData, datasets.EntryData)
    data.setup()
    print "Data loaded into datastore %s" % (options.datastore_path
                                             or "[default]")
class TestListOfRelationships(unittest.TestCase):
    def setUp(self):
        from google.appengine.ext import db

        class Author(db.Model):
            name = db.StringProperty()

        self.Author = Author

        class Book(db.Model):
            title = db.StringProperty()
            authors = db.ListProperty(db.Key)

        self.Book = Book

        class AuthorData(DataSet):
            class frank_herbert:
                name = "Frank Herbert"

            class brian_herbert:
                name = "Brian Herbert"

        class BookData(DataSet):
            class two_worlds:
                title = "Man of Two Worlds"
                authors = [AuthorData.frank_herbert, AuthorData.brian_herbert]

        self.BookData = BookData

        self.fixture = GoogleDatastoreFixture(env={
            'BookData': self.Book,
            'AuthorData': self.Author
        })

    def tearDown(self):
        clear_datastore()

    @attr(functional=1)
    def test_setup_then_teardown(self):

        eq_(list(self.Author.all()), [])
        eq_(list(self.Book.all()), [])

        data = self.fixture.data(self.BookData)
        data.setup()

        books = self.Book.all()

        eq_(books[0].title, "Man of Two Worlds")
        authors = [self.Author.get(k) for k in books[0].authors]
        print_(authors)
        eq_(len(authors), 2)
        authors.sort(key=lambda a: a.name)
        eq_(authors[0].name, "Brian Herbert")
        eq_(authors[1].name, "Frank Herbert")

        data.teardown()

        eq_(list(self.Author.all()), [])
        eq_(list(self.Book.all()), [])
class TestListOfRelationships(unittest.TestCase):
            
    def setUp(self):
        from google.appengine.ext import db
        
        class Author(db.Model):
            name = db.StringProperty()
        self.Author = Author
        
        class Book(db.Model):
            title = db.StringProperty()
            authors = db.ListProperty(db.Key)
        self.Book = Book
        
        class AuthorData(DataSet):
            class frank_herbert:
                name = "Frank Herbert"
            class brian_herbert:
                name = "Brian Herbert"
                
        class BookData(DataSet):
             class two_worlds:
                 title = "Man of Two Worlds"
                 authors = [AuthorData.frank_herbert, AuthorData.brian_herbert]
        self.BookData = BookData
              
        self.fixture = GoogleDatastoreFixture(env={
            'BookData': self.Book,
            'AuthorData': self.Author
        })
    
    def tearDown(self):
        clear_datastore()
    
    @attr(functional=1)
    def test_setup_then_teardown(self):
        
        eq_(list(self.Author.all()), [])
        eq_(list(self.Book.all()), [])
        
        data = self.fixture.data(self.BookData)
        data.setup()
        
        books = self.Book.all()
        
        eq_(books[0].title, "Man of Two Worlds")
        authors = [self.Author.get(k) for k in books[0].authors]
        print authors
        eq_(len(authors), 2)
        authors.sort(key=lambda a:a.name )
        eq_(authors[0].name, "Brian Herbert")
        eq_(authors[1].name, "Frank Herbert")
        
        data.teardown()
        
        eq_(list(self.Author.all()), [])
        eq_(list(self.Book.all()), [])
class TestRelationships(unittest.TestCase):
    def setUp(self):
        from google.appengine.ext import db

        class CategoryData(DataSet):
            class red:
                color = 'red'

        class ProductData(DataSet):
            class red_truck:
                category = CategoryData.red
                sale_tag = "Big, Shiny Red Truck"

        self.ProductData = ProductData

        class Category(db.Model):
            color = db.StringProperty()

        self.Category = Category

        class Product(db.Model):
            category = db.ReferenceProperty(Category)
            sale_tag = db.StringProperty()

        self.Product = Product

        self.fixture = GoogleDatastoreFixture(env={
            'CategoryData': self.Category,
            'ProductData': self.Product,
        })

    def tearDown(self):
        clear_datastore()

    @attr(functional=1)
    def test_setup_then_teardown(self):

        eq_(list(self.Category.all()), [])
        eq_(list(self.Product.all()), [])

        data = self.fixture.data(self.ProductData)
        data.setup()

        products = self.Product.all()

        eq_(products[0].sale_tag, "Big, Shiny Red Truck")
        eq_(products[0].category.color, "red")

        data.teardown()

        eq_(list(self.Category.all()), [])
        eq_(list(self.Product.all()), [])
예제 #9
0
    def setUp(self):
        """Set up required for the view tests.
    """

        self.view = TestView()
        self.stubout_helper = StuboutHelper()
        self.stubout_helper.stuboutBase()
        self.stubout_helper.stuboutElement(task.View, 'select',
                                           ['request', 'view', 'redirect'])

        # map all the models
        models_dict = {
            'User': models.user.User,
            'Site': models.site.Site,
            'Sponsor': models.sponsor.Sponsor,
            'Host': models.host.Host,
            'GCITimeline': gci_models.timeline.GCITimeline,
            'GCIProgram': gci_models.program.GCIProgram,
            'GCIOrganization': gci_models.organization.GCIOrganization,
            'GCIOrgAdmin': gci_models.org_admin.GCIOrgAdmin,
            'GCIMentor': gci_models.mentor.GCIMentor,
            'GCIStudent': gci_models.student.GCIStudent,
            'GCITask': gci_models.task.GCITask,
        }

        # create a fixture for Appengine datastore using the previous map
        datafixture = GoogleDatastoreFixture(env=models_dict,
                                             style=NamedDataStyle())

        # seed the data in the datastore
        self.data = datafixture.data(
            datasets.UserData, datasets.SiteData, datasets.SponsorData,
            datasets.HostData, datasets.GCITimelineData,
            datasets.GCIProgramData, datasets.GCIOrganizationData,
            datasets.GCIOrgAdminData, datasets.GCIMentorData,
            datasets.GCIMentorData, datasets.GCITaskData)

        self.data.setup()
예제 #10
0
  def setUp(self):
    """Set up required for the view tests.
    """

    self.view = TestView()
    self.stubout_helper = StuboutHelper()
    self.stubout_helper.stuboutBase()
    self.stubout_helper.stuboutElement(task.View, 'select',
                                       ['request', 'view', 'redirect'])

    # map all the models
    models_dict = {
        'User': models.user.User,
        'Site': models.site.Site,
        'Sponsor': models.sponsor.Sponsor,
        'Host': models.host.Host,
        'GCITimeline': gci_models.timeline.GCITimeline,
        'GCIProgram': gci_models.program.GCIProgram,
        'GCIOrganization': gci_models.organization.GCIOrganization,
        'GCIOrgAdmin': gci_models.org_admin.GCIOrgAdmin,
        'GCIMentor': gci_models.mentor.GCIMentor,
        'GCIStudent': gci_models.student.GCIStudent,
        'GCITask': gci_models.task.GCITask,
        }

    # create a fixture for Appengine datastore using the previous map
    datafixture = GoogleDatastoreFixture(env=models_dict,
                                         style=NamedDataStyle())

    # seed the data in the datastore
    self.data = datafixture.data(
        datasets.UserData, datasets.SiteData, datasets.SponsorData,
        datasets.HostData, datasets.GCITimelineData, datasets.GCIProgramData,
        datasets.GCIOrganizationData, datasets.GCIOrgAdminData,
        datasets.GCIMentorData, datasets.GCIMentorData,
        datasets.GCITaskData)

    self.data.setup()
예제 #11
0
class TestRelationships(unittest.TestCase):
            
    def setUp(self):
        from google.appengine.ext import db
        
        class CategoryData(DataSet):
            class red:
                color = 'red'
    
        class ProductData(DataSet):
            class red_truck:
                category = CategoryData.red
                sale_tag = "Big, Shiny Red Truck"
        self.ProductData = ProductData
        
        class Category(db.Model):
            color = db.StringProperty()
        self.Category = Category
        
        class Product(db.Model):
            category = db.ReferenceProperty(Category)
            sale_tag = db.StringProperty()
        self.Product = Product
                        
        self.fixture = GoogleDatastoreFixture(env={
            'CategoryData': self.Category,
            'ProductData': self.Product,
        })
    
    def tearDown(self):
        clear_datastore()
    
    @attr(functional=1)
    def test_setup_then_teardown(self):
        
        eq_(list(self.Category.all()), [])
        eq_(list(self.Product.all()), [])
        
        data = self.fixture.data(self.ProductData)
        data.setup()
        
        products = self.Product.all()
        
        eq_(products[0].sale_tag, "Big, Shiny Red Truck")
        eq_(products[0].category.color, "red")
        
        data.teardown()
        
        eq_(list(self.Category.all()), [])
        eq_(list(self.Product.all()), [])
class TestSetupTeardown(unittest.TestCase):
    class CategoryData(DataSet):
        class cars:
            name = 'cars'

        class free_stuff:
            name = 'get free stuff'

    def setUp(self):
        from google.appengine.ext import db

        class Category(db.Model):
            name = db.StringProperty()

        self.Category = Category

        self.fixture = GoogleDatastoreFixture(
            env={'CategoryData': self.Category})

    def tearDown(self):
        clear_datastore()

    @attr(functional=1)
    def test_setup_then_teardown(self):

        eq_(list(self.Category.all()), [])

        data = self.fixture.data(self.CategoryData)
        data.setup()

        cats = self.Category.all().order('name')

        eq_(cats[0].name, 'cars')
        eq_(cats[1].name, 'get free stuff')

        data.teardown()

        eq_(list(self.Category.all()), [])
예제 #13
0
class TestSetupTeardown(unittest.TestCase):
    
    class CategoryData(DataSet):
        class cars:
            name = 'cars'
        class free_stuff:
            name = 'get free stuff'
            
    def setUp(self):
        from google.appengine.ext import db
        
        class Category(db.Model):
            name = db.StringProperty()        
        self.Category = Category
                        
        self.fixture = GoogleDatastoreFixture(env={'CategoryData': self.Category})
    
    def tearDown(self):
        clear_datastore()
    
    @attr(functional=1)
    def test_setup_then_teardown(self):
        
        eq_(list(self.Category.all()), [])
        
        data = self.fixture.data(self.CategoryData)
        data.setup()
        
        cats = self.Category.all().order('name')
        
        eq_(cats[0].name, 'cars')
        eq_(cats[1].name, 'get free stuff')
        
        data.teardown()
        
        eq_(list(self.Category.all()), [])
예제 #14
0
import unittest
from fixture import GoogleDatastoreFixture, DataSet
from fixture.style import NamedDataStyle
from gblog import application, models
from webtest import TestApp
from datasets import CommentData, EntryData

datafixture = GoogleDatastoreFixture(env=models, style=NamedDataStyle())

class TestListEntries(unittest.TestCase):
    def setUp(self):
        self.app = TestApp(application)
        self.data = datafixture.data(CommentData, EntryData)
        self.data.setup()
    
    def tearDown(self):
        self.data.teardown()
    
    def test_entries(self):
        response = self.app.get("/")
        print response
        
        assert EntryData.great_monday.title in response
        assert EntryData.great_monday.body in response
        
        assert CommentData.monday_liked_it.comment in response
        assert CommentData.monday_sucked.comment in response