コード例 #1
0
 def setUp(self):
     super().setUp()
     user = models.User(username=faker.name(),
                        fullname=faker.name(),
                        password=faker.text(16),
                        is_active=True)
     models.session.add(user)
     models.session.commit()
     self.user = user
     access_token = auth.generate_access_token(user.username)
     self.data = {
         'title': faker.text(20),
     }
     self.headers = {'Authorization': f'Bearer {access_token}'}
コード例 #2
0
 def test_update_task_owned_by_other_user(self):
     url = self.url().format(self.task.id)
     with patch('app.services.update_task') as mock_update_task:
         mock_update_task.return_value = None
         _, http_code = self.call_api(url,
                                      json={'title': faker.text(20)},
                                      headers=self.headers)
     assert http_code == 404
コード例 #3
0
 def test_update_task_not_found(self):
     url = self.url().format(faker.random_int(100, 1000))
     with patch('app.services.update_task') as mock_update_task:
         mock_update_task.return_value = None
         _, http_code = self.call_api(url,
                                      json={'title': faker.text(20)},
                                      headers=self.headers)
     assert http_code == 404
コード例 #4
0
    def wrapper(ordered=True, header=None):
        date_fmt = '%d/%m/%Y'

        patient_data, header_str = patient_report_header(ordered=ordered,
                                                         header=header)

        free_text = faker.text()

        final_text = f'{header_str}\n\n{free_text}'
        return patient_data, free_text, final_text
コード例 #5
0
def test_encode_and_decode_token(db):
    user = models.User(fullname=faker.name(),
                       username=faker.name(),
                       password=faker.text(16))
    user.is_active = True
    db.add(user)
    db.commit()
    access_token = auth.generate_access_token(user.username)

    data_decoded = auth.decode_token(access_token)
    assert data_decoded['sub'] == user.username
コード例 #6
0
 def setUp(self):
     super().setUp()
     user = models.User(username=faker.name(),
                        fullname=faker.name(),
                        password=faker.text(16),
                        is_active=True)
     models.session.add(user)
     models.session.flush()
     tasks = list()
     for _ in range(3):
         task = models.Task(title=faker.name(),
                            created_by=user.username,
                            description=faker.text())
         models.session.add(task)
         tasks.append(task)
     models.session.commit()
     self.user = user
     self.tasks = tasks
     access_token = auth.generate_access_token(user.username)
     self.data = {
         'title': faker.text(20),
     }
     self.headers = {'Authorization': f'Bearer {access_token}'}
コード例 #7
0
 def test_update_task(self):
     url = self.url().format(self.task.id)
     data = {
         'title': faker.name(),
         'description': faker.text(),
         'status': faker.random_element(('new', 'done', 'failure', 'doing'))
     }
     before_updated_at = self.task.updated_at
     _, http_code = self.call_api(url, json=data, headers=self.headers)
     assert http_code == 204
     assert self.task.updated_at != before_updated_at
     assert self.task.title == data['title']
     assert self.task.description == data['description']
     assert self.task.status == data['status']
コード例 #8
0
 def setUp(self):
     super().setUp()
     raw_pass = faker.text(16)
     user = models.User(
         username=faker.name(),
         fullname=faker.name(),
         password=raw_pass,
         is_active=False
     )
     models.session.add(user)
     models.session.commit()
     self.user = user
     self.data = {
         'username': user.username,
         'password': raw_pass
     }
コード例 #9
0
 def test_login_with_username_is_wrong(self):
     self.data['username'] = self.data['username'] + faker.text(5)
     _, http_code = self.call_api(json=self.data)
     assert http_code == 400
     assert not self.user.is_active