コード例 #1
0
    def test_save__try_to_update_with_none_values(self):
        #
        #   In database fields with new values which are equal to None
        #   should not be overwritten because of the fact, that client tends to
        #   send back to server only a small part of object's data, such as ID.

        # Arrange
        movie_orm = MovieORM.objects.create(title=self.title,
                                            year=self.year,
                                            director=self.director,
                                            poster_url=self.poster_url,
                                            video_url=self.video_url)

        existed_movie = MovieRepo().get(movie_orm.id)

        expected_movie_data = {
            'title': self.title,
            'year': self.year,
            'director': self.director,
            'poster_url': self.poster_url,
            'video_url': self.video_url
        }

        # Act
        movie_repo = MovieRepo()

        existed_movie.title = None
        existed_movie.year = None
        existed_movie.director = None
        existed_movie.poster_url = None

        actual_movie = movie_repo.save(existed_movie)

        actual_movie_data = {
            'title': actual_movie.title,
            'year': actual_movie.year,
            'director': actual_movie.director,
            'poster_url': actual_movie.poster_url,
            'video_url': actual_movie.video_url
        }

        # Assert
        self.assertDictEqual(expected_movie_data, actual_movie_data)

        # Chech immutabilty direct in orm object
        actual_movie_orm = MovieORM.objects.get(pk=movie_orm.id)
        actual_movie_orm_data = {
            'title': actual_movie_orm.title,
            'year': actual_movie_orm.year,
            'director': actual_movie_orm.director,
            'poster_url': actual_movie_orm.poster_url,
            'video_url': actual_movie_orm.video_url
        }

        self.assertDictEqual(expected_movie_data, actual_movie_orm_data)
コード例 #2
0
    def test_save__update(self):
        # Arrange
        movie_orm = MovieORM.objects.create(title=self.title,
                                            year=self.year,
                                            director=self.director,
                                            poster_url=self.poster_url,
                                            video_url=self.video_url)

        existed_movie = MovieRepo().get(movie_orm.id)

        title_new_value = 'The Departed'
        year_new_value = 2006
        director_new_value = 'Martin Scorsese'

        expected_movie_data = {
            'title': title_new_value,
            'year': year_new_value,
            'director': director_new_value,
            'poster_url': self.poster_url,
            'video_url': self.video_url
        }

        # Act
        existed_movie.title = title_new_value
        existed_movie.year = year_new_value
        existed_movie.director = director_new_value

        movie_repo = MovieRepo()
        actual_movie = movie_repo.save(existed_movie)
        actual_movie_data = {
            'title': actual_movie.title,
            'year': actual_movie.year,
            'director': actual_movie.director,
            'poster_url': actual_movie.poster_url,
            'video_url': actual_movie.video_url
        }

        self.assertDictEqual(expected_movie_data, actual_movie_data)