Created
February 13, 2020 20:14
-
-
Save Porter97/d6eaec6b9a90758d163da0df8eac18f3 to your computer and use it in GitHub Desktop.
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
import unittest | |
import stream | |
from flask import current_app | |
from app import create_app, db | |
from app.models import User, Role, Collection, Content | |
class UserModelTestCase(unittest.TestCase): | |
def setUp(self): | |
self.app = create_app('testing') | |
self.app_context = self.app.app_context() | |
self.app_context.push() | |
db.create_all() | |
Role.insert_roles() | |
def tearDown(self): | |
db.session.remove() | |
db.drop_all() | |
self.app_context.pop() | |
def test_content(self): | |
client = stream.connect(current_app.config['STREAM_API_KEY'], current_app.config['STREAM_SECRET']) | |
# Add User | |
u = User(id=9999999999, username='john', email='john@example.com', password='test') | |
db.session.add(u) | |
db.session.commit() | |
confirm_token = u.generate_confirmation_token() | |
self.assertTrue(u.confirm(confirm_token)) | |
# Add Collection | |
c = Collection(name='Collection Test', description='Collection test description', author=u) | |
db.session.add(c) | |
db.session.commit() | |
self.assertTrue(c.add_to_stream()) | |
# Add Content | |
co = Content(title='Content test', description='Collection test description', url="http://test.com", collection=c) | |
db.session.add(co) | |
db.session.commit() | |
self.assertTrue(co.add_to_stream()) | |
# Edit and Delete Content | |
co.title = 'Content Test 2' | |
co.description = 'Content test description 2' | |
co.url = 'http://test2.com' | |
db.session.commit() | |
self.assertTrue(co.update_stream()) | |
self.assertTrue(co.delete_from_stream()) | |
db.session.delete(co) | |
# Edit and Delete Collection | |
c.name = 'Collection Test 2' | |
c.description = 'Collection test description 2' | |
db.session.commit() | |
self.assertTrue(c.update_stream()) | |
self.assertTrue(c.delete_from_stream()) | |
db.session.delete(c) | |
# Remove User from Stream | |
client.users.delete(u.id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment