Ejemplo n.º 1
0
def main():
    """
    Imports data from 'dog_details.json',

    Raises an error if DogSerializer does not exist
    inside pugorugh/serializers.py
    """
    try:
        from pugorugh.serializers import DogSerializer
    except ImportError:
        raise ImportError("DogSerializer not implemented in serializers.py")

    # Full path to dog_details.json leveraging
    # Pythons ability to find file path of this script from earlier.
    json_file = path.join(PROJECT_DIR, 'pugorugh', 'static',
                          'dog_details.json')

    # pass full file path to open()
    with open(json_file, 'r') as file:
        data = json.load(file)
        serializer = DogSerializer(data=data, many=True)
        if serializer.is_valid():
            serializer.save()
        else:
            print(serializer.errors)
Ejemplo n.º 2
0
def load_data():
    filepath = path.join(PROJ_DIR, 'pugorugh', 'static', 'dog_details.json')

    with open(filepath, 'r') as file:
        data = json.load(file)

        serializer = DogSerializer(data=data, many=True)
        if serializer.is_valid():
            serializer.save()
        else:
            print(serializer.errors)
Ejemplo n.º 3
0
def load_data():
    filepath = path.join(DATA_PATH, DATA_FILE)
    
    with open(filepath, 'r', encoding='utf-8') as file:
        data = json.load(file)

        serializer = DogSerializer(data=data, many=True)
        if serializer.is_valid():
            serializer.save()
        else:
            print(serializer.errors)

    print('load_data done.')
Ejemplo n.º 4
0
def load_data():
    filepath = path.join(PROJ_DIR, 'pugorugh', 'static', 'dog_details.json')

    pdb.set_trace()

    with open(filepath, 'r', encoding='utf-8') as file:
        data = json.load(file)

        serializer = DogSerializer(data=data, many=True)
        if serializer.is_valid():
            serializer.save()
        else:
            print(serializer.errors)

    print('load_data done.')
def main():
    try:
        from pugorugh.serializers import DogSerializer
    except ImportError:
        raise ImportError("DogSerializer not implemented in serializers.py")

    json_file = path.join(PROJECT_DIR,
                          'pugorugh',
                          'static',
                          'dog_details.json')

    with open(json_file, 'r') as file:
        data = json.load(file)
        serializer = DogSerializer(data=data, many=True)
        if serializer.is_valid():
            serializer.save()
        else:
            print(serializer.errors)
Ejemplo n.º 6
0
def load_data():
    try:
        from pugorugh.serializers import DogSerializer
    except ImportError:
        raise ImportError(
            'serializers.py must contain a properly '
            'implemented DogSerializer class for this import to work.')

    filepath = path.join('backend', 'pugorugh', 'static', 'dog_details.json')

    with open(filepath, 'r', encoding='utf-8') as file:
        data = json.load(file)

        serializer = DogSerializer(data=data, many=True)
        if serializer.is_valid():
            serializer.save()
        else:
            print(serializer.errors)

    print('load_data done.')
# I have left the origninal data_import.py script in the project in case
# the data_import script does not work for someone, but this script
# does.


import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
django.setup()

from pugorugh.serializers import DogSerializer
import json

with open('pugorugh/static/dog_details.json', 'r') as file:
    data = json.load(file)

    serializer = DogSerializer(data=data, many=True)
    if serializer.is_valid():
        serializer.save()
    else:
print(serializer.errors)
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
django.setup()

from pugorugh.serializers import DogSerializer
import json

with open('pugorugh/static/dog_details.json', 'r') as file:
    data = json.load(file)

    serializer = DogSerializer(data=data, many=True)
    if serializer.is_valid():
        serializer.save()
    else:
        print(serializer.errors)
Ejemplo n.º 9
0
 def test_get_correct_value(self):
     serializer = DogSerializer(data=self.dog_1_data)
     self.assertTrue(serializer.is_valid())
     self.assertEqual(serializer.data['name'], self.dog_1_data['name'])