def test_get_success(self, simple_profile): # arrange expected_profile = UserDBRepo.decode_orm_user_profile(simple_profile) test_username = expected_profile.username # act (result_profile, error) = UserDBRepo.get(test_username) # assert assert result_profile.id == expected_profile.id
def test_session_success(self, simple_profile, simple_profile_user): # arrange expected_profile = UserDBRepo.decode_orm_user_profile(simple_profile) test_user = simple_profile_user # act (result_session, error) = UserDBRepo.create_session(test_user) # assert assert error is None assert result_session.id == expected_profile.id
def decode_orm_comment(orm_comment): orm_author = orm_comment.author return Comment(id=orm_comment.id, text=orm_comment.text, author=UserDBRepo.decode_orm_user_profile(orm_author), film=orm_comment.film.id, created=orm_comment.created_at)
def test_session_fail(self, simple_profile_user): # arrange test_user = simple_profile_user # act (result_session, error) = UserDBRepo.create_session(test_user) # assert assert error == "notExist"
def test_get_fail_not_normal(self): # arrange test_username = 1000 # act (result_profile, error) = UserDBRepo.get(test_username) # assert assert error == "NotExist"
def test_get_fail_not_found(self): # arrange test_username = "******" # act (result_profile, error) = UserDBRepo.get(test_username) # assert assert error == "NotExist"
def test_create_user(self): # arrange userdata = userToDict(UserMother.one().build()) usecase = UserUsecases(UserDBRepo()) # act (user, error) = usecase.create_user(userdata) # assert assert error is None assert userdata['username'] == user.username assert userdata['email'] == user.email
def test_get_one_success_london(self, mocker): # arrange usecase = UserUsecases(UserDBRepo()) test_id = 1 expected_user = UserMother.one().build() mocker.patch('modules.DBRepo.UserDBRepo.UserDBRepo.get', return_value=(expected_user, None)) # act (result_users, error) = usecase.get_user(test_id) # assert assert result_users.username == expected_user.username
def test_create_user_no_password(self): # arrange userdata = { 'username': '******', 'email': '*****@*****.**', } usecase = UserUsecases(UserDBRepo()) with pytest.raises(KeyError) as r: # act (user, error) = usecase.create_user(userdata) # assert assert r
def test_create_user_mock(self, mocker): # arrange userdata = userToDict(UserMother.one().build()) usecase = UserUsecases(UserDBRepo()) mocker.patch('modules.DBRepo.UserDBRepo.UserDBRepo.create', return_value=(UserMother.one().build(), None)) # act (user, error) = usecase.create_user(userdata) # assert assert error is None assert userdata['username'] == user.username assert userdata['email'] == user.email
def test_create_user_duple_email(self): # arrange builder = UserMother.one() userdata_1 = userToDict(builder.build()) builder.name = "user122212" userdata_2 = userToDict(builder.build()) usecase = UserUsecases(UserDBRepo()) # act (user_1, error_1) = usecase.create_user(userdata_1) (user_2, error_2) = usecase.create_user(userdata_2) # assert assert error_2 == "invalid_email"
def test_create_user_duple_username(self): # arrange builder = UserMother.one() userdata_1 = userToDict(builder.build()) builder.email = "*****@*****.**" userdata_2 = userToDict(builder.build()) usecase = UserUsecases(UserDBRepo()) # act (user_1, error_1) = usecase.create_user(userdata_1) (user_2, error_2) = usecase.create_user(userdata_2) # assert assert error_2 == "invalid_username"
def get_user_usecase() -> UserUsecases: return UserUsecases(UserDBRepo())
def test_all(self, x, films_3, simple_profile, client): # arrange test_films = [ FilmDBRepo.decode_orm_film(films_3[i]) for i in range(len(films_3)) ] test_films_genre_1 = test_films[0].genres[0] test_film_with_genre = test_films[0] test_profile = UserDBRepo.decode_orm_user_profile(simple_profile) test_user = userToDict(test_profile) comment_builder = CommentMother.one() test_comment = comment_builder.build() like_builder = LikeMother.one() test_like = like_builder.build() # act resp = client.post("/api/v1/sessions/", test_user) # print(resp.json()) # assert assert resp.json()['username'] == test_user['username'] session = resp.json()['token'] # act resp = client.get("/api/v1/films/", HTTP_AUTHORIZATION='Bearer ' + session) # print(resp.json()) resp = resp.json() # assert for i in range(len(test_films)): assert test_films[i].id in [ resp[i]['id'] for i in range(len(resp)) ] # act resp = client.get("/api/v1/films/?genre=" + str(test_films_genre_1.id)) print(resp.json()) result_films = resp.json() # assert for i in range(len(result_films)): film_genres_ids = [ result_films[i]['genres'][j]['id'] for j in range(len(result_films[i]['genres'])) ] assert test_films_genre_1.id in film_genres_ids # act resp = client.get("/api/v1/films/" + str(result_films[0]['id']) + '/') # assert assert test_film_with_genre.id == resp.json()['id'] # act resp = client.get("/api/v1/films/" + str(result_films[0]['id']) + '/comments/') # assert assert [] == resp.json() # act resp = client.post("/api/v1/films/" + str(result_films[0]['id']) + '/comments/', commentToDict(test_comment), HTTP_AUTHORIZATION='Bearer ' + session) # assert assert resp.json()['text'] == test_comment.text # act resp = client.post("/api/v1/films/" + str(result_films[0]['id']) + '/likes/', likeToDict(test_like), HTTP_AUTHORIZATION='Bearer ' + session) # assert assert resp.json()['value'] == test_like.value
def user(simple_profile): test_profile = UserDBRepo.decode_orm_user_profile(simple_profile) test_user = userToDict(test_profile) return test_user