moltin / python-sdk

Moltin python SDK
MIT License
6 stars 9 forks source link

fixed bug in request.get and added new Entry endpoint object #8

Open neywen opened 8 years ago

neywen commented 8 years ago

fixed bug in request.get: payload parameter name should be 'params', not 'data', for a get request

added new Entry endpoint object, with methods to easily manage the Flows entries

outrunthewolf commented 8 years ago

You'll have to excuse my python skills. Are there any tests to update along with this?

neywen commented 8 years ago

I'm not a Python expert either :) I just saw that it was not working correctly, and I saw in the python requests documentation that the parameter has a different name in the case of the "get" request.

I know I should have added more unitary tests, yeah. not doing so is baaaad. Actually, I have a bunch of unitary tests for those changes, but in my Python app : in order to test the new Entry endpoint, I had to create a custom Flow "tests" in my dashboard. So, as long as we don't add a "Flow" endpoint in the SDK, it's going to be difficult to test the Entry endpoint automatically.

Here are the unitary tests I use in my app, I'll let you decide what's the best move for the next step :

from my_moltin_front_end import moltin_instance, authenticate
from moltin.moltin import Moltin
from moltin import exception as MoltinExceptions

  [...]

   def test_moltin_flows(self):
        authenticate.authenticate()

        try:
            # list flow
            flow = moltin_instance.Entry(flow_slug="tests")
            list = flow.list()
            assert len(list) == 0

            # create entry
            entry = flow.create_entry({'key':'my_key', 'value':'my_value'})
            assert entry is not None
            entry_id = entry.get("id")
            assert entry_id is not None

            # list flow
            list = flow.list()
            assert len(list) == 1

            # get entry
            entry = flow.get_entry(entry_id)
            assert entry is not None
            entry_id_tmp = entry.get("id")
            assert entry_id_tmp is not None
            assert entry_id_tmp == entry_id

            # create another entry
            entry = flow.create_entry({'key':'my_key_2', 'value':'my_value_2'})
            entry_id_2 = entry.get("id")
            assert entry is not None

            # list flow
            list = flow.list()
            assert len(list) == 2

            # get entry
            entry = flow.get_entry(entry_id)
            assert entry is not None
            entry_id_tmp = entry.get("id")
            assert entry_id_tmp is not None
            assert entry_id_tmp == entry_id

            # find entry
            list = flow.find_by({'key': 'my_key'})
            assert list is not None
            assert len(list) == 1
            entry = list[0]
            entry_id = entry.get("id")
            assert entry_id is not None
            assert entry_id == entry_id_tmp

            # delete entry
            flow.delete_entry(entry_id)

            # list flow
            list = flow.list()
            assert len(list) == 1

            # delte entry
            flow.delete_entry(entry_id_2)

            # list flow
            list = flow.list()
            assert len(list) == 0

            done = True

        except MoltinExceptions.RequestError as e:
            print("MoltinExceptions.RequestError "+str(e))
            done = False
        except Exception as e:
            print("Exception "+str(e))
            done = False

        assert done == True

l.