Ejemplo n.º 1
0
    def test_with_group(self):
        # setup
        with test_app.app_context():
            group = Group(name=f'testGroup', )
            db.session.add(group)
            db.session.commit()

        # test
        client = test_app.test_client()
        resp = client.post(self.url,
                           data={
                               'image': (BytesIO(b'added image data'),
                                         'test_image.jpeg'),
                               'metadata':
                               json.dumps({
                                   'img_type': 'jpeg',
                                   'tags': ['aTag', 'bTag'],
                                   'group': 'testGroup',
                               })
                           })
        self.assertEqual(resp.status_code, 200)
        json_data = resp.get_json()
        self.assertIn('msg', json_data)
        # 验证已插入数据库
        with test_app.app_context():
            image = Image.query.get(1)
            self.assertTrue(image)
            self.assertEqual(image.group.name, 'testGroup')
Ejemplo n.º 2
0
 def test_search_group(self):
     client = test_app.test_client()
     resp = client.get(self.url, query_string={'group': 'testGroup'})
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('data', json_data)
     self.assertEqual(len(json_data['data']), 2)
Ejemplo n.º 3
0
 def test_move_to_not_exists_group(self):
     client = test_app.test_client()
     body = self.data.copy()
     body['group'] = 'notExistsGroup'
     resp = client.post(self.url, json=body)
     self.assertEqual(resp.status_code, 404)
     json_data = resp.get_json()
     self.assertIn('error', json_data)
Ejemplo n.º 4
0
 def test_default(self):
     client = test_app.test_client()
     resp = client.get(
         self.url,
         query_string={'image_id': 1}
     )
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('data', json_data)
Ejemplo n.º 5
0
 def test_normal(self):
     client = test_app.test_client()
     resp = client.get(self.url, query_string={'id': 1})
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('msg', json_data)
     # 验证数据库中已删除
     with test_app.app_context():
         self.assertFalse(Image.query.get(1))
Ejemplo n.º 6
0
 def test_normal(self):
     client = test_app.test_client()
     body = self.data.copy()
     resp = client.post(self.url, json=body)
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('msg', json_data)
     # 验证已插入数据库
     with test_app.app_context():
         self.assertTrue(Group.query.get(1))
Ejemplo n.º 7
0
 def test_pagination(self):
     client = test_app.test_client()
     resp = client.get(self.url, query_string={
         'page': 2,
         'per_page': 10,
     })
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('data', json_data)
     self.assertIn('pagination', json_data)
     self.assertEqual(len(json_data['data']), 10)
Ejemplo n.º 8
0
 def test_normal(self):
     client = test_app.test_client()
     body = self.data.copy()
     resp = client.post(self.url, json=body)
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('msg', json_data)
     # 验证数据库中确实已经更新
     with test_app.app_context():
         record = Group.query.get(1)
         self.assertEqual(record.name, self.data['new_name'])
Ejemplo n.º 9
0
 def test_normal(self):
     client = test_app.test_client()
     resp = client.post(self.url, json={'name': 'testGroup1'})
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('msg', json_data)
     # 验证数据库中已删除
     with test_app.app_context():
         self.assertFalse(Group.query.filter_by(name='testGroup1').first())
         # 验证 cascade delete:
         self.assertFalse(Image.query.get(1))
         self.assertFalse(Image.query.get(2))
Ejemplo n.º 10
0
 def test_default(self):
     client = test_app.test_client()
     body = self.data.copy()
     resp = client.post(self.url, json=body)
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('msg', json_data)
     # 验证已插入数据库
     with test_app.app_context():
         image = Image.query.get(1)
         self.assertIn('addedTag1', image.tags)
         self.assertIn('addedTag2', image.tags)
Ejemplo n.º 11
0
 def test_normal(self):
     client = test_app.test_client()
     body = self.data.copy()
     resp = client.post(self.url, json=body)
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('msg', json_data)
     with test_app.app_context():
         self.assertEqual(
             Image.query.get(1).group.name,
             'testGroup1',
         )
Ejemplo n.º 12
0
 def test_normal(self):
     client = test_app.test_client()
     body = self.data.copy()
     resp = client.post(
         self.url,
         json=body
     )
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('msg', json_data)
     # 验证数据库中已删除
     with test_app.app_context():
         image = Image.query.get(1)
         self.assertNotIn('aTag', image.tags)
Ejemplo n.º 13
0
 def test_move_to_all(self):
     client = test_app.test_client()
     resp = client.post(self.url, json={
         'id': 2,
         'group': None,
     })
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('msg', json_data)
     with test_app.app_context():
         self.assertIs(
             Image.query.get(2).group_id,
             None,
         )
Ejemplo n.º 14
0
 def test_with_tags(self):
     client = test_app.test_client()
     resp = client.post(self.url,
                        data={
                            'image': (BytesIO(b'added image data'),
                                      'test_image.jpeg'),
                            'metadata':
                            json.dumps({
                                'img_type': 'jpeg',
                                'tags': ['aTag', 'bTag'],
                            })
                        })
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('msg', json_data)
     # 验证已插入数据库
     with test_app.app_context():
         self.assertTrue(Image.query.get(1))
Ejemplo n.º 15
0
 def test_delete_not_exists_group(self):
     client = test_app.test_client()
     resp = client.post(self.url, json={'name': 'not_exists_group'})
     self.assertEqual(resp.status_code, 404)
     json_data = resp.get_json()
     self.assertIn('error', json_data)
Ejemplo n.º 16
0
 def test_delete_not_exists_image(self):
     client = test_app.test_client()
     resp = client.get(self.url, query_string={'id': 10000})
     self.assertEqual(resp.status_code, 404)
     json_data = resp.get_json()
     self.assertIn('error', json_data)
Ejemplo n.º 17
0
 def test_normal(self):
     client = test_app.test_client()
     resp = client.get(self.url)
     self.assertEqual(resp.status_code, 200)
     json_data = resp.get_json()
     self.assertIn('data', json_data)
Ejemplo n.º 18
0
 def test_default(self):
     client = test_app.test_client()
     resp = client.get(self.url, )
     json_data = resp.get_json()
     self.assertTrue(json_data['success'])
Ejemplo n.º 19
0
 def test_show_one_images_data(self):
     client = test_app.test_client()
     resp = client.get(self.url, query_string={'id': 1})
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(resp.mimetype, 'image/jpeg')
     self.assertEqual(resp.headers.get('Content-Type'), 'image/jpeg')