Ejemplo n.º 1
0
 def test_can_dump_and_load_timer(self):
     user = TestObjects().get_test_user()
     timer = TimerEntity(notes="Just a test timer", user=user, tags=["Unit Tests"], seconds = 22, running = True)
     timer.save()
     tf = TimerFormatter()
     timer_entity_as_dict = tf.model_to_dict(timer)
     timer.delete()
     timer2 = tf.dict_to_model(TimerEntity, timer_entity_as_dict)
     # This won't pass, there are subtle, trivial differences in datetimes once dates have been serialized
     #assert(timer.lastRestart == timer2.lastRestart)
     #assert(timer.dateEntered == timer2.dateEntered)
     assert(timer.tags == timer2.tags)
     assert(timer.running == timer2.running)
     assert(timer.seconds == timer2.seconds)
     assert(timer.notes == timer2.notes)
     assert(timer.user == timer2.user)
     assert(timer.to_json() == timer2.to_json())
Ejemplo n.º 2
0
 def test_can_dump_and_load_timer(self):
     user = TestObjects().get_test_user()
     timer = TimerEntity(notes="Just a test timer",
                         user=user,
                         tags=["Unit Tests"],
                         seconds=22,
                         running=True)
     timer.save()
     tf = TimerFormatter()
     timer_entity_as_dict = tf.model_to_dict(timer)
     timer.delete()
     timer2 = tf.dict_to_model(TimerEntity, timer_entity_as_dict)
     # This won't pass, there are subtle, trivial differences in datetimes once dates have been serialized
     #assert(timer.lastRestart == timer2.lastRestart)
     #assert(timer.dateEntered == timer2.dateEntered)
     assert (timer.tags == timer2.tags)
     assert (timer.running == timer2.running)
     assert (timer.seconds == timer2.seconds)
     assert (timer.notes == timer2.notes)
     assert (timer.user == timer2.user)
     assert (timer.to_json() == timer2.to_json())
Ejemplo n.º 3
0
    def test_timer_resource_all(self):
        token = test_credentials.get_auth_token()
        user = TestObjects().get_test_user()
        timer = TimerEntity(notes="Just a test timer", user=user, tags=["Unit Tests"], seconds = 22, running = True)
        timer_dict = TimerFormatter().model_to_dict(timer)

        # Not authorized w/o token
        response = requests.post(v1_api + "/timer", headers={'content-type' : 'application/json'}, data=timer.to_json())
        assert(response.status_code == http.client.UNAUTHORIZED)

        # With token, should get "CREATED"
        response = requests.post(v1_api + "/timer", headers={'content-type' : 'application/json'}, auth=token, data=timer.to_json())
        assert(response.status_code == http.client.CREATED)

        # Object location
        url = response.headers["Location"]

        # Not authorized without the token (401)
        response = requests.get(url)
        assert(response.status_code == http.client.UNAUTHORIZED)

        # Re-send the request with the token, this time get OK (200)
        response = requests.get(url, auth=token)
        assert(response.status_code == http.client.OK)
        timer_dict2 = loads(response.text)
        assert(timer_dict2["seconds"] == 22)

        # Update the seconds and PUT the request
        timer_dict2["seconds"] = 99
        response = requests.put(url, headers={'content-type' : 'application/json'}, auth=token, data=dumps(timer_dict2))
        assert(response.status_code == http.client.OK)
        response = requests.get(url, auth=token)
        assert(response.status_code == http.client.OK)
        timer_dict3 = loads(response.text)
        assert(timer_dict3["seconds"] == 99)

        # Currently our GET all means "Everything for the current user.  This will change, and we'll need a new test
        get_many_url = v1_api + "/timer"
        # Not authorized without the token (401)
        response = requests.get(get_many_url)
        assert(response.status_code == http.client.UNAUTHORIZED)

        # Re-send the request with the token, this time get OK (200)
        response = requests.get(get_many_url, auth=token)
        assert(response.status_code == http.client.OK)
        print(response.text)

        # Delete the resource
        response = requests.delete(url, auth=token)
        assert(response.status_code == http.client.NO_CONTENT)
Ejemplo n.º 4
0
    def test_timer_resource_all(self):
        token = test_credentials.get_auth_token()
        user = TestObjects().get_test_user()
        timer = TimerEntity(notes="Just a test timer",
                            user=user,
                            tags=["Unit Tests"],
                            seconds=22,
                            running=True)
        timer_dict = TimerFormatter().model_to_dict(timer)

        # Not authorized w/o token
        response = requests.post(v1_api + "/timer",
                                 headers={'content-type': 'application/json'},
                                 data=timer.to_json())
        assert (response.status_code == http.client.UNAUTHORIZED)

        # With token, should get "CREATED"
        response = requests.post(v1_api + "/timer",
                                 headers={'content-type': 'application/json'},
                                 auth=token,
                                 data=timer.to_json())
        assert (response.status_code == http.client.CREATED)

        # Object location
        url = response.headers["Location"]

        # Not authorized without the token (401)
        response = requests.get(url)
        assert (response.status_code == http.client.UNAUTHORIZED)

        # Re-send the request with the token, this time get OK (200)
        response = requests.get(url, auth=token)
        assert (response.status_code == http.client.OK)
        timer_dict2 = loads(response.text)
        assert (timer_dict2["seconds"] == 22)

        # Update the seconds and PUT the request
        timer_dict2["seconds"] = 99
        response = requests.put(url,
                                headers={'content-type': 'application/json'},
                                auth=token,
                                data=dumps(timer_dict2))
        assert (response.status_code == http.client.OK)
        response = requests.get(url, auth=token)
        assert (response.status_code == http.client.OK)
        timer_dict3 = loads(response.text)
        assert (timer_dict3["seconds"] == 99)

        # Currently our GET all means "Everything for the current user.  This will change, and we'll need a new test
        get_many_url = v1_api + "/timer"
        # Not authorized without the token (401)
        response = requests.get(get_many_url)
        assert (response.status_code == http.client.UNAUTHORIZED)

        # Re-send the request with the token, this time get OK (200)
        response = requests.get(get_many_url, auth=token)
        assert (response.status_code == http.client.OK)
        print(response.text)

        # Delete the resource
        response = requests.delete(url, auth=token)
        assert (response.status_code == http.client.NO_CONTENT)