Beispiel #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')
Beispiel #2
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))
Beispiel #3
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))
Beispiel #4
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'])
Beispiel #5
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)
Beispiel #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.assertEqual(
             Image.query.get(1).group.name,
             'testGroup1',
         )
Beispiel #7
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)
Beispiel #8
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,
         )
Beispiel #9
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))
Beispiel #10
0
 def setUp(self):
     with test_app.app_context():
         db.create_all()
         group = Group(name=f'testGroup', )
         img1 = Image(
             data=b'abcdefggggggg',
             img_type='jpeg',
             tags=['aTag'],
         )
         img2 = Image(
             data=b'abcdefggggggg',
             img_type='jpeg',
             tags=['bTag'],
         )
         group.images = [img1, img2]
         db.session.add(group)
         img3 = Image(
             data=b'abcdefggggggg',
             img_type='jpeg',
             tags=['cTag'],
         )
         db.session.add(img3)
         db.session.commit()
Beispiel #11
0
 def setUp(self):
     with test_app.app_context():
         db.create_all()
Beispiel #12
0
 def setUp(self):
     with test_app.app_context():
         db.create_all()
         fake_images(20)