Giter Club home page Giter Club logo

ohri-test's Introduction

Specification

You will need to write a Python function to validate data.

Arguments

  1. Data from an SQL table that needs to be validated represented as a Python dictionary. The keys in the dictionary are the column names and the values are the column values.

  2. The rules to validate the data provided as a Python dictionary. The keys to the dictionary are the columns expected in the data and values are strings that provide the type that the data should have for that column. For example,

{
    "email": "string",
    "phone": "number"
}

The above rule dictionary states that the data should have at most two keys called email and phone and their values should be a string and number respectively.

For now, assume that the types allowed are either string or number.

Function Return

The function should return a list of strings which has all the validation errors found in the data. Examples are shown below.

# The validation rules we will use for this example
contact_rules = {
    "email": "string",
    "phone": "number",
    "address": "string"
}

# This should return a list with 3 strings telling the user that they are
# missing the columns, email, phone and address
data_one = {}

# This should return a list with 1 error, telling the user that the phone
# column should be a number
data_two = {
    "email":"[email protected]",
    "phone": "12345",
    "address": "123 Test Way"
}

# This should return a list with 1 error, telling the user that the 
# postalCode column should not be there
data_three = {
    "email":"[email protected]",
    "phone": 12345,
    "address": "123 Test Way",
    "postalCode": "K6D789
}

You can format the validation messages as you wish making sure that they give enough information to the user to correct the error.

Validation Requirements

The function should perform the following validations:

  1. Make sure that the correct columns are present in the data.
  2. Make sure no extra columns are present in it
  3. Make sure the column value matches the type specified in the validation rule

ohri-test's People

Contributors

zargot avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.