Exemplo n.º 1
0
class CreateLocationTestCase(unittest.TestCase):
    def setUp(self) -> None:
        """清空数据库,注册用户。"""
        self.location_repository = DatabaseLocationRepository(
            connection=mysql_connection, )
        self.user_repository = DatabaseUserRepository(
            connection=mysql_connection, )
        self.location_repository.clear()
        self.user_repository.clear()
        register_user(self.location_repository, self.user_repository)

    def tearDown(self) -> None:
        self.location_repository.clear()
        self.user_repository.clear()

    def test_create_location(self):
        """测试创建一个地点。"""
        with main.app.test_client() as client:
            client.post('/user/login',
                        json={
                            'email': '*****@*****.**',
                            'password': '******',
                        })
            name = '工地'
            rv = client.post('/location', json={
                'name': name,
            })
            json_data = rv.get_json()
            assert json_data['result']['id']
            assert json_data['result']['name'] == name
Exemplo n.º 2
0
 def setUp(self) -> None:
     """清空数据库,注册用户。"""
     self.location_repository = DatabaseLocationRepository(
         connection=mysql_connection, )
     self.user_repository = DatabaseUserRepository(
         connection=mysql_connection, )
     self.location_repository.clear()
     self.user_repository.clear()
     register_user(self.location_repository, self.user_repository)
Exemplo n.º 3
0
 def location(self):
     return DatabaseLocationRepository(connection=self.mysql_connection)
Exemplo n.º 4
0
# -*- coding: utf8 -*-
# 测试创建任务接口
import pytest

from nest.repository.location import DatabaseLocationRepository
from nest.repository.task import DatabaseTaskRepository
from nest.repository.user import DatabaseUserRepository
from nest.web import main
from .user_helper import register_user
from tests.web.helper import mysql_connection

_task_id = None
location_repository = DatabaseLocationRepository(
    connection=mysql_connection,
)
task_repository = DatabaseTaskRepository(
    connection=mysql_connection,
)
user_repository = DatabaseUserRepository(
    connection=mysql_connection,
)


def clear_database():
    task_repository.clear()
    user_repository.clear()


# 写法来自这里:https://docs.pytest.org/en/stable/xunit_setup.html
def setup_module():
    clear_database()