-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from thegeorgeous/tests
Tests
- Loading branch information
Showing
7 changed files
with
75 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,11 @@ dist/ | |
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# Emacs files | ||
.org | ||
tags | ||
|
||
# Vagrant files | ||
Vagrantfile | ||
.vagrant/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
services: | ||
- cassandra | ||
|
||
language: python | ||
|
||
python: | ||
- 2.7 | ||
|
||
env: | ||
- CASSANDRA_DRIVER_VERSION=2.6.0 | ||
- CASSANDRA_DRIVER_VERSION=2.7.2 | ||
|
||
install: | ||
- pip install -q cassandra-driver==$CASSANDRA_DRIVER_VERSION | ||
- pip install -q flask | ||
- python setup.py -q install | ||
|
||
script: py.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import unittest | ||
import uuid | ||
from flask import Flask | ||
from flask.ext.cqlalchemy import CQLAlchemy | ||
from cassandra.cqlengine.management import drop_keyspace, create_keyspace_simple | ||
from cassandra.cqlengine import models | ||
|
||
def make_user_model(db): | ||
class User(db.Model): | ||
uuid = db.columns.UUID(primary_key=True, default=uuid.uuid4) | ||
username = db.columns.Text(index=True, required=False) | ||
|
||
return User | ||
|
||
class BasicTestCase(unittest.TestCase): | ||
|
||
def setUp(self): | ||
app = Flask(__name__) | ||
app.config['CASSANDRA_HOSTS'] = ['127.0.0.1'] | ||
app.config['CASSANDRA_KEYSPACE'] = "test1" | ||
app.config['CASSANDRA_SETUP_KWARGS'] = {'protocol_version': 3} | ||
db = CQLAlchemy(app) | ||
self.User = make_user_model(db) | ||
create_keyspace_simple("test1", 1) | ||
|
||
self.app = app | ||
self.db = db | ||
|
||
def tearDown(self): | ||
drop_keyspace("cqlengine") | ||
|
||
|
||
def test_sync_db(self): | ||
self.db.sync_db() | ||
user = self.User.create(username="JohnDoe") | ||
self.assertTrue(isinstance(user, self.User)) | ||
self.assertEqual(user.username, "JohnDoe") | ||
|
||
def test_set_keyspace(self): | ||
create_keyspace_simple("test2", 1) | ||
self.db.set_keyspace('test2') | ||
self.assertEqual(models.DEFAULT_KEYSPACE, "test2") | ||
self.assertEqual(self.db._keyspace_, "test2") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |