def test_filter_by_access(self): user = User.create( dict(username='******', password='******', email='*****@*****.**')) Document.create(dict(title="title", body="d", user=user)) available = filter_by_access( user, Document.query.all(), ) self.assertEqual(len(available), 1)
def test_filter_by_access(self): user = User.create(dict( username='******', password='******', email='*****@*****.**' )) Document.create(dict(title="title", body="d", user=user)) available = filter_by_access( user, Document.query.all(), ) self.assertEqual(len(available), 1)
def setUp(self): super(BaseTestCase, self).setUp() self.app = create_app(config.Testing) self.app_context = self.app.app_context() self.client = self.app.test_client() self.app_context.push() self.db = db self.db.drop_all() self.db.create_all() self.user = dict( username="******", password="******", first_name="Test", last_name="User", _admin=True ) self.document = dict( title="This is a Test Title", body="Body Body Body, likeasomebody" ) self.tag = {"title": "TAGGY"} self.default_user = User.create(self.user) self.default_document = Document.create(self.document) self.default_document.user = self.default_user self.tag = Tag.create(self.tag) self.tag.user = self.default_user self.default_document.tags.append(self.tag) self.db.session.commit() self.redis_store = RedisStore(store=FakeStrictRedis, name='test') token = jwt.create_token_for_user(self.default_user) self.headers = [ ('Content-Type', 'application/json'), ('Authorization', 'Bearer %s' % token) ]
def test_edit_document_no_access(self): doc = Document.create(dict(title="daslkf", body="kdsjf")) req = json.dumps({"title": "this is a new title"}) res = self.client.put('/documents/%s' % doc.id, data=req, headers=self.headers) self.assertStatus(res, 401)
def setUp(self): super(BaseTestCase, self).setUp() self.app = create_app(config.Testing) self.app_context = self.app.app_context() self.client = self.app.test_client() self.app_context.push() self.db = db self.db.drop_all() self.db.create_all() self.user = dict(username="******", password="******", first_name="Test", last_name="User", _admin=True) self.document = dict(title="This is a Test Title", body="Body Body Body, likeasomebody") self.tag = {"title": "TAGGY"} self.default_user = User.create(self.user) self.default_document = Document.create(self.document) self.default_document.user = self.default_user self.tag = Tag.create(self.tag) self.tag.user = self.default_user self.default_document.tags.append(self.tag) self.db.session.commit() self.redis_store = RedisStore(store=FakeStrictRedis, name='test') token = jwt.create_token_for_user(self.default_user) self.headers = [('Content-Type', 'application/json'), ('Authorization', 'Bearer %s' % token)]
def create_document(): user = api.helpers.get_user() data = document_schema.load(request.get_json()).data data['user'] = user doc = Document.create(data) xhr = MakeResponse(201, document_schema.dump(doc).data) return xhr.response
def test_edit_document_no_access(self): doc = Document.create(dict(title="daslkf", body="kdsjf")) req = json.dumps({"title": "this is a new title"}) res = self.client.put( '/documents/%s' % doc.id, data=req, headers=self.headers ) self.assertStatus(res, 401)
def test_delete_document_no_access(self): doc = Document.create(dict(title="daslkf", body="kdsjf")) res = self.client.delete( '/documents/%s' % doc.id, headers=self.headers ) self.assertStatus(res, 401) self.assertIsNotNone(Document.query.get(doc.id))
def setUp(self): super(DocumentModelTestCase, self).setUp() self.user2 = User.create({ "username": "******", "email": "*****@*****.**", "password": "******", }) Share.create_or_update(self.user2, self.default_document, read=True) self.random_doc = Document.create({"title": "random document"})
def test_get_docs_for_tag(self): tag = Tag.query.get(1) doc = Document.create(dict(title="Random DOCKY")) doc.tags.append(tag) res = self.client.get('/tags/1/documents', headers=self.headers) self.assertStatus200(res) data = json.loads(res.data) self.assertIsNotNone(data.get('results')) self.assertEqual(len(data.get('results')), 1)
def test_owns_document(self): doc = Document.query.first() self.assertTrue(self.default_user.owns_document(doc)) new_doc = Document.create({"title": "random document"}) self.assertFalse(self.default_user.owns_document(new_doc))
def test_get_document_no_access(self): doc = Document.create(dict(title="random", body="text")) res = self.client.get('/documents/%s' % doc.id, headers=self.headers) self.assertStatus(res, 401)
def test_delete_document_no_access(self): doc = Document.create(dict(title="daslkf", body="kdsjf")) res = self.client.delete('/documents/%s' % doc.id, headers=self.headers) self.assertStatus(res, 401) self.assertIsNotNone(Document.query.get(doc.id))