def test_eval_ok(self):
     user = TestObjects().get_test_user()
     t1 = TimerEntity(id=ObjectId(b"Timer1Timer2"), notes="I want a shrubbery", user=user)
     # print(t1.__repr__())
     t2 = eval(t1.__repr__())
     # Note this part works partly because compare is brain-dead, compares id only and only works for non-null id
     # But that may be what we need for MongoEngine purposes, so don't override
     assert(t1 == t2)
     # A better check
     assert(t1.__repr__() == t2.__repr__())
 def test_eval_ok(self):
     user = TestObjects().get_test_user()
     t1 = TimerEntity(id=ObjectId(b"Timer1Timer2"),
                      notes="I want a shrubbery",
                      user=user)
     # print(t1.__repr__())
     t2 = eval(t1.__repr__())
     # Note this part works partly because compare is brain-dead, compares id only and only works for non-null id
     # But that may be what we need for MongoEngine purposes, so don't override
     assert (t1 == t2)
     # A better check
     assert (t1.__repr__() == t2.__repr__())
 def test_save_timer(self):
     dao = TimerDAO()
     t1 = TimerEntity(notes="My Test LegacyTimer Running!",
                      user=TestObjects().get_test_user(),
                      running=True)
     dao.put(t1)
     assert (t1.id is not None)
 def test_can_save_and_load_timer(self):
     user = TestObjects().get_test_user()
     t = TimerEntity(id=TestObjects().get_any_id(),
                     notes="Saved from unit test",
                     user=user)
     t.save()
     t2 = TimerEntity.objects(id=t.id).first()
     assert (t.__repr__() == t2.__repr__())
     t.delete()
 def test_user_not_updated_on_save(self):
     user = TestObjects().get_test_user()
     t1 = TimerEntity(id=ObjectId(b"Timer1Timer3"),
                      notes="I want a shrubbery",
                      user=user)
     t1.save()
     t1.user.password = "******"
     t1.save()
     # TODO ETC...
     t1.delete()
 def test_can_save_and_load_timer(self):
     user = TestObjects().get_test_user()
     t = TimerEntity(id=TestObjects().get_any_id(), notes="Saved from unit test", user=user )
     t.save()
     t2 = TimerEntity.objects(id = t.id).first()
     assert(t.__repr__() == t2.__repr__())
     t.delete()
Ejemplo n.º 7
0
 def test_can_convert_timer_to_dict(self):
     user = TestObjects().get_test_user()
     timer = TimerEntity(notes="Just a test timer",
                         user=user,
                         tags=["Unit Tests"])
     tf = TimerFormatter()
     timer_entity_as_dict = tf.model_to_dict(timer)
     assert (timer_entity_as_dict is not None)
     assert (timer_entity_as_dict["notes"] == timer.notes)
 def test_user_not_updated_on_save(self):
     user = TestObjects().get_test_user()
     t1 = TimerEntity(id=ObjectId(b"Timer1Timer3"), notes="I want a shrubbery", user=user)
     t1.save()
     t1.user.password = "******"
     t1.save()
     # TODO ETC...
     t1.delete()
Ejemplo n.º 9
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.º 10
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.º 11
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.º 12
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)