コード例 #1
0
 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)
コード例 #2
0
 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)
コード例 #3
0
ファイル: __init__.py プロジェクト: patallen/markdraft.com
    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)
        ]
コード例 #4
0
ファイル: test_views.py プロジェクト: patallen/markdraft.com
 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)
コード例 #5
0
    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)]
コード例 #6
0
ファイル: documents.py プロジェクト: patallen/markdraft.com
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
コード例 #7
0
ファイル: test_views.py プロジェクト: patallen/markdraft.com
 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)
コード例 #8
0
ファイル: test_views.py プロジェクト: patallen/markdraft.com
 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))
コード例 #9
0
 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"})
コード例 #10
0
ファイル: test_models.py プロジェクト: patallen/markdraft.com
 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"})
コード例 #11
0
ファイル: test_views.py プロジェクト: patallen/markdraft.com
 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)
コード例 #12
0
ファイル: test_views.py プロジェクト: patallen/markdraft.com
 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)
コード例 #13
0
 def setUp(self):
     super(FiltersTestCase, self).setUp()
     documents = [
         {
             "title": "Title 1",
             "body": "blank"
         },
         {
             "title": "Title 2",
             "body": "blank"
         },
         {
             "title": "Title 3",
             "body": "blank"
         },
     ]
     for doc in documents:
         d = Document(title=doc.get('title'), body=doc.get('body'))
         self.db.session.add(d)
     self.db.session.commit()
コード例 #14
0
ファイル: test_models.py プロジェクト: patallen/markdraft.com
 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))
コード例 #15
0
ファイル: test_views.py プロジェクト: patallen/markdraft.com
 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)
コード例 #16
0
 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))
コード例 #17
0
ファイル: test_views.py プロジェクト: patallen/markdraft.com
 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))
コード例 #18
0
ファイル: test_views.py プロジェクト: patallen/markdraft.com
 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)