Exemple #1
0
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
Exemple #2
0
    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
Exemple #3
0
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
Exemple #4
0
    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
Exemple #5
0
    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)
Exemple #6
0
 def post(self, **kwargs):
     """
     Создает заметку пользователя.
     Требуется аутентификация.
     :param kwargs: параметры для создания заметки
     :return: заметку
     """
     author = g.user
     note = NoteModel(author_id=author.id, **kwargs)
     note.save()
     return note, 201
Exemple #7
0
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
Exemple #8
0
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
Exemple #9
0
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
Exemple #10
0
 def get(self):
     """
     Возвращает все публичные заметки пользователя
     :return: заметки
     """
     notes = NoteModel.get_all_public_notes()
     if not notes:
         abort(404, error=f"Public notes not found")
     return notes, 200
Exemple #11
0
 def get(self, **kwargs):
     notes_lst = []
     for tag_name in kwargs["tags"]:
         #pdb.set_trace()
         notes = NoteModel.get_notes_filtered_by_tags(tag_name)
         if not notes:
             abort(404, error=f"Note with tag_name={tag_name} not found")
         for note in notes:
             if note not in notes_lst:
                 notes_lst.append(note)
     return notes_lst, 200
Exemple #12
0
    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
Exemple #13
0
 def get(self):
     """
     Возвращает все заметки пользователя.
     Фильтры поиска не применяются.
     Требуется аутентификация.
     :return: все заметки
     """
     author = g.user
     notes = NoteModel.get_all_notes(author, archive="all")
     if not notes:
         abort(404, error=f"You have no notes yet")
     return notes, 200
Exemple #14
0
 def get(self):
     """
     Возвращает все архивные заметки пользователя.
     Используется фильтр - "архивные".
     Требуется аутентификация.
     :return:
     """
     author = g.user
     notes = NoteModel.get_all_notes(author, archive="archive")
     if not notes:
         abort(404, error=f"You have no notes yet")
     return notes, 200
Exemple #15
0
    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
Exemple #16
0
 def get(self, **kwargs):
     """
     Возвращает заметки, фильтруя по привязанным тегам.
     :param kwargs: теги в формате списка
     :return: заметки
     """
     notes_lst = []
     for tag_name in kwargs["tags"]:
         #pdb.set_trace()
         notes = NoteModel.get_notes_filtered_by_tags(tag_name)
         if not notes:
             abort(404, error=f"Note with tag_name={tag_name} not found")
         for note in notes:
             if note not in notes_lst:
                 notes_lst.append(note)
     return notes_lst, 200
Exemple #17
0
 def get(self):
     author = g.user
     notes = NoteModel.get_all_notes(author, archive="no_archive")
     if not notes:
         abort(404, error=f"You have no notes yet")
     return notes, 200
Exemple #18
0
 def post(self, **kwargs):
     author = g.user
     print("author.username = ", author.username)
     note = NoteModel(author_id=author.id, **kwargs)
     note.save()
     return note, 201
Exemple #19
0
 def get(self):
     notes = NoteModel.get_all_public_notes()
     if not notes:
         abort(404, error=f"Public notes not found")
     return notes, 200
Exemple #20
0
 def post(self, **kwargs):
     author = g.user
     note = NoteModel(author_id=author.id, **kwargs)
     note.save()
     return note, 201