Example #1
0
class LayerServiceTest(unittest.TestCase):
    """Unit tests for LayerService class."""

    def setUp(self):
        """Sets up the test environment."""

        # The LayerService to use for testing:
        self.service = LayerService()

        # It's an error to register the same service twice:
        if apiproxy_stub_map.apiproxy.GetStub('datastore_v3') is not None:
            return;

        # Let's us run unit tests without running the dev server:
        os.environ['TZ'] = 'UTC'
        time.tzset()
        os.environ['SERVER_SOFTWARE'] = 'Development via nose'
        os.environ['SERVER_NAME'] = 'Foo'
        os.environ['SERVER_PORT'] = '8080'
        os.environ['APPLICATION_ID'] = APP_ID
        os.environ['USER_EMAIL'] = '*****@*****.**'
        os.environ['CURRENT_VERSION_ID'] = 'testing-version'
        ds_stub = DatastoreFileStub(APP_ID, None, None)
        apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', ds_stub)

    def test_is_valid_id(self):
        self.assertEqual(False, self.service.is_id_valid(None))
        self.assertEqual(False, self.service.is_id_valid(''))
        self.assertEqual(False, self.service.is_id_valid(' '))
        self.assertEqual(False, self.service.is_id_valid('foo'))

        # Valid id
        key_name = 'testlayer'
        key = db.Key.from_path('Species', key_name)
        species = Species(key=key)
        id = str(db.put(species))
        self.assertEqual(True, self.service.is_id_valid(id))

        # Invalid id
        key_name = 'testlayerINVALID'
        key = db.Key.from_path('Species', key_name)
        id = str(key)
        self.assertEqual(False, self.service.is_id_valid(id))

        # Invalid id
        key_name = 'testlayer'
        key = db.Key.from_path('SpeciesIndex', key_name)
        species = SpeciesIndex(key=key)
        id = str(db.put(species))
        self.assertEqual(False, self.service.is_id_valid(id))
Example #2
0
    def setUp(self):
        """Sets up the test environment."""

        # The LayerService to use for testing:
        self.service = LayerService()

        # It's an error to register the same service twice:
        if apiproxy_stub_map.apiproxy.GetStub('datastore_v3') is not None:
            return;

        # Let's us run unit tests without running the dev server:
        os.environ['TZ'] = 'UTC'
        time.tzset()
        os.environ['SERVER_SOFTWARE'] = 'Development via nose'
        os.environ['SERVER_NAME'] = 'Foo'
        os.environ['SERVER_PORT'] = '8080'
        os.environ['APPLICATION_ID'] = APP_ID
        os.environ['USER_EMAIL'] = '*****@*****.**'
        os.environ['CURRENT_VERSION_ID'] = 'testing-version'
        ds_stub = DatastoreFileStub(APP_ID, None, None)
        apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', ds_stub)