def create_test_user1_note1_tag1_tag1(self): user_data = { "username": '******', 'password': '******' } user = UserModel(**user_data) user.save() res = self.client.get("/users") data = json.loads(res.data) self.assertEqual(res.status_code, 200) self.assertEqual(data[0]["username"], user_data["username"]) note_data1 = { "note": 'test note 1' } note = NoteModel(author_id=user.id, **note_data1) note.save() tags_data = [ { "name": 'test1 tag' }, { "name": 'test2 tag' } ] for tag_data in tags_data: tag = TagModel(author_id=user.id, **tag_data) tag.save() return user, note, user_data, tags_data
def create_test_note1_and_note2_by_user1(self): user_data = { "username": '******', 'password': '******' } user = UserModel(**user_data) user.save() res = self.client.get("/users") data = json.loads(res.data) self.assertEqual(res.status_code, 200) self.assertEqual(data[0]["username"], user_data["username"]) notes_data = [ { "note": 'test note 1' }, { "note": 'test note 2' }, ] ids = [] for note_data in notes_data: note = NoteModel(author_id=user.id, **note_data) note.save() ids.append(note.id) return user, user_data
def create_test_note1_by_user1(create_test_user1): note_data1 = {"note": 'test note 1'} note1 = NoteModel(author_id=create_test_user1[0].id, **note_data1) note1.save() return note1, create_test_user1
def create_test_note2_by_user2(create_test_user2): note_data2 = {"note": 'test note 2'} note2 = NoteModel(author_id=create_test_user2[0].id, **note_data2) note2.save() return note2, create_test_user2
def test_get_note_by_id(self): user_data = {"username": '******', "password": '******'} user = UserModel(**user_data) user.save() notes_data = [ { "text": 'Text note 1', }, { "text": 'Text note 2', }, ] ids = [] for note_data in notes_data: note = NoteModel(author_id=user.id, **note_data) note.save() ids.append(note.id) headers = { 'Authorization': 'Basic ' + b64encode(f"{user_data['username']}:{user_data['password']}". encode('ascii')).decode('utf-8') } res = self.client.get('/notes', headers=headers) self.assertEqual(res.status_code, 200) data = json.loads(res.data) self.assertEqual(len(data), 2)
def post(self, **kwargs): """ Создает заметку пользователя. Требуется аутентификация. :param kwargs: параметры для создания заметки :return: заметку """ author = g.user note = NoteModel(author_id=author.id, **kwargs) note.save() return note, 201
def create_test_user2_note2_tag3_tag4(create_test_user2): note_data2 = {"note": 'test note 2'} note2 = NoteModel(author_id=create_test_user2[0].id, **note_data2) note2.save() tags_data = [{"name": 'test tag 3'}, {"name": 'test tag 4'}] tags_lst = [] for tag_data in tags_data: tag = TagModel(author_id=create_test_user2[0].id, **tag_data) tag.save() tags_lst.append(tag) return note2, tags_lst, create_test_user2
def create_test_user1_note1_tag1_tag2(create_test_user1): note_data1 = {"note": 'test note 1'} note1 = NoteModel(author_id=create_test_user1[0].id, **note_data1) note1.save() tags_data = [{"name": 'test tag 1'}, {"name": 'test tag 2'}] tags_lst = [] for tag_data in tags_data: tag = TagModel(author_id=create_test_user1[0].id, **tag_data) tag.save() tags_lst.append(tag) return note1, tags_lst, create_test_user1
def create_test_note1_and_note2_by_user1(create_test_user1): notes_data = [ { "note": 'test note 1' }, { "note": 'test note 2' }, ] notes_lst = [] for note_data in notes_data: note = NoteModel(author_id=create_test_user1[0].id, **note_data) note.save() notes_lst.append(note) return notes_lst
def create_test_user1_note1_by_user1(self): user_data1 = { "username": '******', 'password': '******' } user1 = UserModel(**user_data1) user1.save() res = self.client.get("/users") data = json.loads(res.data) self.assertEqual(res.status_code, 200) self.assertEqual(data[0]["username"], user_data1["username"]) note_data1 = { "note": 'test note 1' } note1 = NoteModel(author_id=user1.id, **note_data1) note1.save() return note1, user1, user_data1
def create_test_user2_note2_by_user2(self): user_data2 = { "username": '******', 'password': '******' } user2 = UserModel(**user_data2) user2.save() res = self.client.get("/users") data = json.loads(res.data) self.assertEqual(res.status_code, 200) self.assertEqual(data[1]["username"], user_data2["username"]) note_data = { "note": 'test note 2' } note = NoteModel(author_id=user2.id, **note_data) note.save() return note, user2, user_data2
def post(self, **kwargs): author = g.user print("author.username = ", author.username) note = NoteModel(author_id=author.id, **kwargs) note.save() return note, 201
def post(self, **kwargs): author = g.user note = NoteModel(author_id=author.id, **kwargs) note.save() return note, 201