예제 #1
0
    def test_should_create_model_with_simple_info(self):
        json_fixture = os.path.join(settings.BASE_DIR, "cinemas/fixtures/movie_228049.json")

        with open(json_fixture, "r") as f:
            self.json = json.load(f)

        serializer = MovieSerializer(data=self.json)
        serializer.is_valid()
        serializer.save()

        self.check_movie_from_json()
예제 #2
0
 def test_movie_serializer_should_be_valid(self):
     """
     Movie serializer should be valid
     :return:
     """
     serializer = MovieSerializer(data=self.json)
     self.assertTrue(serializer.is_valid())
예제 #3
0
def save_or_update_movie(json):
    try:
        movie = Movie.objects.get(code=json['code'])
        serializer = MovieSerializer(movie, data=json)
    except Movie.DoesNotExist:
        serializer = MovieSerializer(data=json)

    if serializer.is_valid():
        movie = serializer.save()
    else:
        print('Oups, serializer is not valid')
        print(serializer.errors)

    return movie
예제 #4
0
    def test_should_create_model_with_correct_values(self):
        serializer = MovieSerializer(data=self.json)
        serializer.is_valid()
        serializer.save()

        self.check_movie_from_json()