add: tests
This commit is contained in:
		
							parent
							
								
									760cec9a20
								
							
						
					
					
						commit
						865caa627e
					
				
					 15 changed files with 558 additions and 386 deletions
				
			
		| 
						 | 
				
			
			@ -1,3 +1,5 @@
 | 
			
		|||
#include <arpa/inet.h>
 | 
			
		||||
 | 
			
		||||
#include <cJSON.h>
 | 
			
		||||
#include <macros.h>
 | 
			
		||||
#include <command.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -74,35 +76,66 @@ api_v1_controllers_STR_PUT(struct mg_connection *nc, struct http_message *hm, en
 | 
			
		|||
    {
 | 
			
		||||
        static const char content[] = "no valid json was supplied";
 | 
			
		||||
        endpoint_response_text(response, 400, content, STRLEN(content));
 | 
			
		||||
        controller_free(controller);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    cJSON *json_name = cJSON_GetObjectItemCaseSensitive(json, "name");
 | 
			
		||||
    if(json_name)
 | 
			
		||||
    {
 | 
			
		||||
        if(cJSON_IsString(json_name) && json_name->valuestring)
 | 
			
		||||
        {
 | 
			
		||||
            strncpy(controller->name, json_name->valuestring, MAX_NAME_LENGTH);
 | 
			
		||||
            controller->name[MAX_NAME_LENGTH] = '\0';
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            static const char content[] = "the given name is no valid string";
 | 
			
		||||
            endpoint_response_text(response, 400, content, STRLEN(content));
 | 
			
		||||
            cJSON_Delete(json);
 | 
			
		||||
            controller_free(controller);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    cJSON *json_ip = cJSON_GetObjectItemCaseSensitive(json, "ip");
 | 
			
		||||
    if(json_ip)
 | 
			
		||||
    {
 | 
			
		||||
        if(cJSON_IsString(json_ip) && json_ip->valuestring)
 | 
			
		||||
        {
 | 
			
		||||
            unsigned char buf[sizeof(struct in_addr)];
 | 
			
		||||
            if(inet_pton(AF_INET, json_ip->valuestring, buf))
 | 
			
		||||
            {
 | 
			
		||||
                strncpy(controller->ip, json_ip->valuestring, IP_LENGTH);
 | 
			
		||||
                controller->ip[IP_LENGTH] = '\0';
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                static const char content[] = "the given ip address is no valid IPv4 address";
 | 
			
		||||
                endpoint_response_text(response, 400, content, STRLEN(content));
 | 
			
		||||
                cJSON_Delete(json);
 | 
			
		||||
                controller_free(controller);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            static const char content[] = "the given ip address is no valid string";
 | 
			
		||||
            endpoint_response_text(response, 400, content, STRLEN(content));
 | 
			
		||||
            cJSON_Delete(json);
 | 
			
		||||
            controller_free(controller);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if(controller_save(controller))
 | 
			
		||||
    {
 | 
			
		||||
        LOG_ERROR("failed to save controller\n");
 | 
			
		||||
        free(controller);
 | 
			
		||||
        controller_free(controller);
 | 
			
		||||
        cJSON_Delete(json);
 | 
			
		||||
 | 
			
		||||
        static const char content[] = "failed to save controller to database";
 | 
			
		||||
        response->status_code = 500;
 | 
			
		||||
        response->content_type = "text/plain";
 | 
			
		||||
        response->content_length = STRLEN(content);;
 | 
			
		||||
        response->content = content;
 | 
			
		||||
        response->alloced_content = false;
 | 
			
		||||
        endpoint_response_text(response, 500, content, STRLEN(content));
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -111,26 +144,7 @@ api_v1_controllers_STR_PUT(struct mg_connection *nc, struct http_message *hm, en
 | 
			
		|||
 | 
			
		||||
    command_set_controller_name(controller);
 | 
			
		||||
 | 
			
		||||
    char *json_str = cJSON_Print(json);
 | 
			
		||||
    if (json_str == NULL)
 | 
			
		||||
    {
 | 
			
		||||
        LOG_ERROR("failed to print controller json\n");
 | 
			
		||||
 | 
			
		||||
        static const char content[] = "failed to print json for controller";
 | 
			
		||||
        response->status_code = 500;
 | 
			
		||||
        response->content_type = "text/plain";
 | 
			
		||||
        response->content_length = STRLEN(content);;
 | 
			
		||||
        response->content = content;
 | 
			
		||||
        response->alloced_content = false;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        response->status_code = 200;
 | 
			
		||||
        response->content_type = "application/json";
 | 
			
		||||
        response->content_length = strlen(json_str);
 | 
			
		||||
        response->content = json_str;
 | 
			
		||||
        response->alloced_content = true;
 | 
			
		||||
    }
 | 
			
		||||
    endpoint_response_json(response, 200, json);
 | 
			
		||||
    cJSON_Delete(json);
 | 
			
		||||
    controller_free(controller);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -149,11 +163,7 @@ api_v1_controllers_STR_DELETE(struct mg_connection *nc, struct http_message *hm,
 | 
			
		|||
        LOG_DEBUG("failed to unparse uid\n");
 | 
			
		||||
 | 
			
		||||
        static const char content[] = "given id was invalid";
 | 
			
		||||
        response->status_code = 400;
 | 
			
		||||
        response->content_type = "text/plain";
 | 
			
		||||
        response->content_length = STRLEN(content);;
 | 
			
		||||
        response->content = content;
 | 
			
		||||
        response->alloced_content = false;
 | 
			
		||||
        endpoint_response_text(response, 400, content, STRLEN(content));
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -164,11 +174,7 @@ api_v1_controllers_STR_DELETE(struct mg_connection *nc, struct http_message *hm,
 | 
			
		|||
        LOG_DEBUG("could not find a controller for uid '%s'\n", args[0].value.v_str);
 | 
			
		||||
 | 
			
		||||
        static const char content[] = "no controller for id found";
 | 
			
		||||
        response->status_code = 404;
 | 
			
		||||
        response->content_type = "text/plain";
 | 
			
		||||
        response->content_length = STRLEN(content);;
 | 
			
		||||
        response->content = content;
 | 
			
		||||
        response->alloced_content = false;
 | 
			
		||||
        endpoint_response_text(response, 404, content, STRLEN(content));
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -177,19 +183,11 @@ api_v1_controllers_STR_DELETE(struct mg_connection *nc, struct http_message *hm,
 | 
			
		|||
        LOG_ERROR("failed to remove controller from database\n");
 | 
			
		||||
 | 
			
		||||
        static const char content[] = "failed to remove controller from database";
 | 
			
		||||
        response->status_code = 500;
 | 
			
		||||
        response->content_type = "text/plain";
 | 
			
		||||
        response->content_length = STRLEN(content);;
 | 
			
		||||
        response->content = content;
 | 
			
		||||
        response->alloced_content = false;
 | 
			
		||||
        endpoint_response_text(response, 500, content, STRLEN(content));
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        response->status_code = 200;
 | 
			
		||||
        response->content_type = "application/json";
 | 
			
		||||
        response->content_length = 0;
 | 
			
		||||
        response->content = "";
 | 
			
		||||
        response->alloced_content = false;
 | 
			
		||||
        endpoint_response_text(response, 200, "", 0);
 | 
			
		||||
    }
 | 
			
		||||
    controller_free(controller);
 | 
			
		||||
    return;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,8 +31,31 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
			
		|||
        endpoint_response_text(response, 400, content, STRLEN(content));
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    cJSON *json_period;
 | 
			
		||||
    cJSON *json_periods = cJSON_GetObjectItemCaseSensitive(json, "periods");
 | 
			
		||||
    if(!cJSON_IsArray(json_periods))
 | 
			
		||||
    {
 | 
			
		||||
        LOG_DEBUG("no periods for schedule provided\n");
 | 
			
		||||
        cJSON_Delete(json);
 | 
			
		||||
 | 
			
		||||
        static const char content[] = "no periods for schedule provided";
 | 
			
		||||
        endpoint_response_text(response, 400, content, STRLEN(content));
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    cJSON *json_tag;
 | 
			
		||||
    cJSON *json_tags = cJSON_GetObjectItemCaseSensitive(json, "tags");
 | 
			
		||||
    cJSON_ArrayForEach(json_tag, json_tags)
 | 
			
		||||
    {
 | 
			
		||||
        if(!cJSON_IsString(json_tag) || (json_tag->valuestring == NULL))
 | 
			
		||||
        {
 | 
			
		||||
            LOG_DEBUG("invalid tag in tags\n");
 | 
			
		||||
            cJSON_Delete(json);
 | 
			
		||||
 | 
			
		||||
            static const char content[] = "invalid tag in tags";
 | 
			
		||||
            endpoint_response_text(response, 400, content, STRLEN(content));
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    schedule_t *new_schedule = malloc(sizeof(schedule_t));
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -47,6 +70,7 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
			
		|||
 | 
			
		||||
    int periods_valid = 0;
 | 
			
		||||
 | 
			
		||||
    cJSON *json_period;
 | 
			
		||||
    cJSON_ArrayForEach(json_period, json_periods)
 | 
			
		||||
    {
 | 
			
		||||
        cJSON *json_period_start = cJSON_GetObjectItemCaseSensitive(json_period, "start");
 | 
			
		||||
| 
						 | 
				
			
			@ -106,15 +130,10 @@ api_v1_schedules_POST(struct mg_connection *nc, struct http_message *hm, endpoin
 | 
			
		|||
    schedule_save(new_schedule);
 | 
			
		||||
 | 
			
		||||
    junction_tag_remove_for_schedule(new_schedule->id);
 | 
			
		||||
    cJSON *json_tag;
 | 
			
		||||
    cJSON *json_tags = cJSON_GetObjectItemCaseSensitive(json, "tags");
 | 
			
		||||
 | 
			
		||||
    json_tags = cJSON_GetObjectItemCaseSensitive(json, "tags");
 | 
			
		||||
    cJSON_ArrayForEach(json_tag, json_tags)
 | 
			
		||||
    {
 | 
			
		||||
            if(!cJSON_IsString(json_tag) || (json_tag->valuestring == NULL))
 | 
			
		||||
            {
 | 
			
		||||
                LOG_DEBUG("invalid tag in tags\n");
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
        const char *tag = json_tag->valuestring;
 | 
			
		||||
        int tag_id = tag_get_id(tag);
 | 
			
		||||
        if(tag_id == 0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,7 +19,7 @@ handler_connection(struct mg_connection *nc, int ev, void *p)
 | 
			
		|||
    if (ev == MG_EV_HTTP_REQUEST)
 | 
			
		||||
    {
 | 
			
		||||
        struct http_message *hm = (struct http_message *) p;
 | 
			
		||||
        LOG_DEBUG("new http %.*s request for %.*s\n", hm->method.len, hm->method.p, hm->uri.len, hm->uri.p);
 | 
			
		||||
        LOG_TRACE("new http %.*s request for %.*s\n", hm->method.len, hm->method.p, hm->uri.len, hm->uri.p);
 | 
			
		||||
 | 
			
		||||
        endpoint_t *endpoint = router_find_endpoint(hm->uri.p, hm->uri.len, &hm->method);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,7 @@ rm -rf $working_dir
 | 
			
		|||
mkdir -p $working_dir
 | 
			
		||||
cd $working_dir
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
git clone --quiet ssh://git@git.serguzim.me:3022/emgauwa/controller.git controller || exit
 | 
			
		||||
pushd ./controller > /dev/null
 | 
			
		||||
git checkout $2
 | 
			
		||||
| 
						 | 
				
			
			@ -22,18 +23,27 @@ cd build
 | 
			
		|||
cmake -DWIRING_PI_DEBUG=on .. >/dev/null
 | 
			
		||||
cp $source_dir/controller.testing.ini ./controller.ini
 | 
			
		||||
make >/dev/null
 | 
			
		||||
 | 
			
		||||
./controller start >$working_dir/controller.log 2>&1 &
 | 
			
		||||
controller_id=$!
 | 
			
		||||
popd > /dev/null
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
cp $1 $working_dir/core
 | 
			
		||||
cp $source_dir/core.testing.ini $working_dir/core.ini
 | 
			
		||||
 | 
			
		||||
valgrind_emgauwa $working_dir/core start >$working_dir/core.log 2>&1 &
 | 
			
		||||
echo "=== invalids start (must exit) ===" >$working_dir/core.log
 | 
			
		||||
$working_dir/core >>$working_dir/core.log 2>&1
 | 
			
		||||
$working_dir/core INVALID_ACTION >>$working_dir/core.log 2>&1
 | 
			
		||||
 | 
			
		||||
echo "=== invalid start ===" >>$working_dir/core.log
 | 
			
		||||
valgrind_emgauwa $working_dir/core start >>$working_dir/core.log 2>&1 &
 | 
			
		||||
core_id=$!
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
sleep 2;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
export PYTHONPATH=$PYTHONPATH:$source_dir/tavern_utils
 | 
			
		||||
tavern-ci --disable-warnings $source_dir/tavern_tests
 | 
			
		||||
test_result=$?
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										116
									
								
								tests/tavern_tests/1.0.controllers_basic.tavern.yaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										116
									
								
								tests/tavern_tests/1.0.controllers_basic.tavern.yaml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,116 @@
 | 
			
		|||
test_name: Test basic controller functions
 | 
			
		||||
 | 
			
		||||
stages:
 | 
			
		||||
- name: "[controllers_basic] discover controllers"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/discover/"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_controller:multiple
 | 
			
		||||
    save:
 | 
			
		||||
      json:
 | 
			
		||||
        returned_name: "[0].name"
 | 
			
		||||
        returned_id: "[0].id"
 | 
			
		||||
        returned_ip: "[0].ip"
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] get controller, check name"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_controller:single
 | 
			
		||||
      function: validate_controller:check_id
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        id: "{returned_id}"
 | 
			
		||||
      function: validate_controller:check_name
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        name: "{returned_name}"
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] put controller, check name"
 | 
			
		||||
  request:
 | 
			
		||||
    method: PUT
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "renamed_controller"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_controller:single
 | 
			
		||||
      function: validate_controller:check_id
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        id: "{returned_id}"
 | 
			
		||||
      function: validate_controller:check_name
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        name: "{tavern.request_vars.json.name}"
 | 
			
		||||
    save:
 | 
			
		||||
      json:
 | 
			
		||||
        changed_name: "name"
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] put controller, check name and ip"
 | 
			
		||||
  request:
 | 
			
		||||
    method: PUT
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
    json:
 | 
			
		||||
      ip: "203.0.113.17"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_controller:single
 | 
			
		||||
      function: validate_controller:check_id
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        id: "{returned_id}"
 | 
			
		||||
      function: validate_controller:check_ip
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        ip: "{tavern.request_vars.json.ip}"
 | 
			
		||||
    save:
 | 
			
		||||
      json:
 | 
			
		||||
        changed_ip: "ip"
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] delete controller"
 | 
			
		||||
  request:
 | 
			
		||||
    method: DELETE
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] get controller, expect 404"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 404
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] discover controllers again"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/discover/"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_controller:multiple
 | 
			
		||||
      function: validate_controller:find
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        id: "{returned_id}"
 | 
			
		||||
        name: "{changed_name}"
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] get controller again, check name"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_controller:single
 | 
			
		||||
      function: validate_controller:check_id
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        id: "{returned_id}"
 | 
			
		||||
      function: validate_controller:check_name
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        name: "{changed_name}"
 | 
			
		||||
      function: validate_controller:check_ip
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        ip: "{returned_ip}"
 | 
			
		||||
| 
						 | 
				
			
			@ -1,10 +1,10 @@
 | 
			
		|||
test_name: Test basic controller relays functions
 | 
			
		||||
 | 
			
		||||
stages:
 | 
			
		||||
- name: "[controller_relays_basic] discover controllers"
 | 
			
		||||
- name: "[controller_relays_basic] get controllers"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/discover/"
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
							
								
								
									
										99
									
								
								tests/tavern_tests/1.2.controllers_bad.tavern.yaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								tests/tavern_tests/1.2.controllers_bad.tavern.yaml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,99 @@
 | 
			
		|||
test_name: Test bad controller functions
 | 
			
		||||
 | 
			
		||||
stages:
 | 
			
		||||
- name: "[controllers_bad] get controller with bad id"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/this_id_is_invalid"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_bad] put controller with bad id"
 | 
			
		||||
  request:
 | 
			
		||||
    method: PUT
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/this_id_is_invalid"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "unknown_controller"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_bad] delete controller with bad id"
 | 
			
		||||
  request:
 | 
			
		||||
    method: DELETE
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/this_id_is_invalid"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "unknown_controller"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_bad] get controller with unknown id"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/00000000-0000-0000-0000-000000000000"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 404
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_bad] put controller with unknown id"
 | 
			
		||||
  request:
 | 
			
		||||
    method: PUT
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/00000000-0000-0000-0000-000000000000"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "unknown_controller"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 404
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_bad] delete controller with unknown id"
 | 
			
		||||
  request:
 | 
			
		||||
    method: DELETE
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/00000000-0000-0000-0000-000000000000"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "unknown_controller"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 404
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_bad] get controllers to save valid id"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_controller:multiple
 | 
			
		||||
    save:
 | 
			
		||||
      json:
 | 
			
		||||
        returned_id: "[0].id"
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_bad] put controller with bad body (invalid name)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: PUT
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
    json:
 | 
			
		||||
      name: NULL
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_bad] put controller with bad body (invalid ip)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: PUT
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
    json:
 | 
			
		||||
      ip: 123
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_bad] put controller with bad body (invalid IPv4)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: PUT
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
    json:
 | 
			
		||||
      ip: "10.0.0.300"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_bad] put controller with bad body (no json)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: PUT
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
    data: "<b>not json</b><i>but html</i>"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
							
								
								
									
										87
									
								
								tests/tavern_tests/2.0.schedules_basic.tavern.yaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								tests/tavern_tests/2.0.schedules_basic.tavern.yaml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,87 @@
 | 
			
		|||
test_name: Test basic schedule requests
 | 
			
		||||
 | 
			
		||||
stages:
 | 
			
		||||
- name: "[schedules_basic] Make sure we get any response"
 | 
			
		||||
  request:
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    method: GET
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
        function: validate_schedule:multiple
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] post schedule with no periods, expect it to be echoed back"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "same as off"
 | 
			
		||||
      periods: []
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 201
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_schedule:single
 | 
			
		||||
      function: validate_schedule:check_name
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        name: "{tavern.request_vars.json.name}"
 | 
			
		||||
      function: validate_schedule:check_periods
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        periods: "{tavern.request_vars.json.periods}"
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] post schedule, expect it to be echoed back"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "hello"
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "00:10"
 | 
			
		||||
        end: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
      - start: "00:50"
 | 
			
		||||
        end: "01:00"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 201
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_schedule:single
 | 
			
		||||
      function: validate_schedule:check_name
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        name: "{tavern.request_vars.json.name}"
 | 
			
		||||
      function: validate_schedule:check_periods
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        periods: "{tavern.request_vars.json.periods}"
 | 
			
		||||
    save:
 | 
			
		||||
      json:
 | 
			
		||||
        returned_name: "name"
 | 
			
		||||
        returned_id: "id"
 | 
			
		||||
        returned_periods: "periods"
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] get schedule, check name and some periods"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_schedule:single
 | 
			
		||||
      function: validate_schedule:check_name
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        name: "{returned_name}"
 | 
			
		||||
      function: validate_schedule:check_periods
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        periods: "{returned_periods}"
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] delete schedule"
 | 
			
		||||
  request:
 | 
			
		||||
    method: DELETE
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] get deleted schedule, expect 404"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 404
 | 
			
		||||
							
								
								
									
										145
									
								
								tests/tavern_tests/2.2.schedules_bad.tavern.yaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										145
									
								
								tests/tavern_tests/2.2.schedules_bad.tavern.yaml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,145 @@
 | 
			
		|||
test_name: Test bad schedule requests
 | 
			
		||||
 | 
			
		||||
stages:
 | 
			
		||||
- name: "[schedules_bad] get schedule with bad id"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/this_id_is_invalid"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_bad] post schedule with bad body (no json)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    data: "<b>not json</b><i>but html</i>"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_bad] post schedule with bad body (no name)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "00:10"
 | 
			
		||||
        end: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
      - start: "00:50"
 | 
			
		||||
        end: "01:00"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_bad] post schedule with bad body (name as number)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: 42
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "00:10"
 | 
			
		||||
        end: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
      - start: "00:50"
 | 
			
		||||
        end: "01:00"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_bad] post schedule with bad period (no start)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "i am invalid"
 | 
			
		||||
      periods:
 | 
			
		||||
      - end: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_bad] post schedule with bad period (no end)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "i am invalid"
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_bad] post schedule with bad period (invalid start)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "i am invalid"
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "hello"
 | 
			
		||||
        end: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_bad] post schedule with bad period (invalid end)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "i am invalid"
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "12:10"
 | 
			
		||||
        end: 1215
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_bad] post schedule with bad period (invalid end 2)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "i am invalid"
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "12:10"
 | 
			
		||||
        end: "25:90"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_bad] post schedule with bad periods (invalid list)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "i am nvalid"
 | 
			
		||||
      periods: "not a list"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_bad] post schedule with bad tags (one invalid)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "hello"
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "00:10"
 | 
			
		||||
        end: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
      - start: "00:50"
 | 
			
		||||
        end: "01:00"
 | 
			
		||||
      tags:
 | 
			
		||||
      - "valid_tag"
 | 
			
		||||
      - 123
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
| 
						 | 
				
			
			@ -45,10 +45,10 @@ stages:
 | 
			
		|||
        name: "{returned_name}"
 | 
			
		||||
        periods: "{returned_periods}"
 | 
			
		||||
 | 
			
		||||
- name: "[tags] discover controllers"
 | 
			
		||||
- name: "[tags] get controllers"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/discover/"
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
| 
						 | 
				
			
			@ -1,105 +0,0 @@
 | 
			
		|||
test_name: Test basic controller functions
 | 
			
		||||
 | 
			
		||||
stages:
 | 
			
		||||
- name: "[controllers_basic] discover controllers"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/discover/"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    json:
 | 
			
		||||
    - id: !anystr
 | 
			
		||||
      name: !anystr
 | 
			
		||||
      relay_count: !anyint
 | 
			
		||||
      relays: !anystr
 | 
			
		||||
      active: !anybool
 | 
			
		||||
      port: !anyint
 | 
			
		||||
      ip: !anystr
 | 
			
		||||
      relays: !anylist
 | 
			
		||||
    save:
 | 
			
		||||
      json:
 | 
			
		||||
        returned_name: "[0].name"
 | 
			
		||||
        returned_id: "[0].id"
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] get controller, check name"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    json:
 | 
			
		||||
      name: "{returned_name}"
 | 
			
		||||
      id: "{returned_id}"
 | 
			
		||||
      relay_count: !anyint
 | 
			
		||||
      relays: !anystr
 | 
			
		||||
      active: !anybool
 | 
			
		||||
      port: !anyint
 | 
			
		||||
      ip: !anystr
 | 
			
		||||
      relays: !anylist
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] get controller, check name"
 | 
			
		||||
  request:
 | 
			
		||||
    method: PUT
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "renamed_controller"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    json:
 | 
			
		||||
      name: "{tavern.request_vars.json.name}"
 | 
			
		||||
      id: "{returned_id}"
 | 
			
		||||
      relay_count: !anyint
 | 
			
		||||
      relays: !anystr
 | 
			
		||||
      active: true
 | 
			
		||||
      port: !anyint
 | 
			
		||||
      ip: !anystr
 | 
			
		||||
      relays: !anylist
 | 
			
		||||
    save:
 | 
			
		||||
      json:
 | 
			
		||||
        changed_name: "name"
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] delete controller"
 | 
			
		||||
  request:
 | 
			
		||||
    method: DELETE
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] get controller, expect 404"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 404
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] discover controllers again"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/discover/"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    json:
 | 
			
		||||
    - id: "{returned_id}"
 | 
			
		||||
      name: "{changed_name}"
 | 
			
		||||
      relay_count: !anyint
 | 
			
		||||
      relays: !anystr
 | 
			
		||||
      active: true
 | 
			
		||||
      port: !anyint
 | 
			
		||||
      ip: !anystr
 | 
			
		||||
      relays: !anylist
 | 
			
		||||
 | 
			
		||||
- name: "[controllers_basic] get controller again, check name"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/controllers/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    json:
 | 
			
		||||
      id: "{returned_id}"
 | 
			
		||||
      name: "{changed_name}"
 | 
			
		||||
      relay_count: !anyint
 | 
			
		||||
      relays: !anystr
 | 
			
		||||
      active: true
 | 
			
		||||
      port: !anyint
 | 
			
		||||
      ip: !anystr
 | 
			
		||||
      relays: !anylist
 | 
			
		||||
| 
						 | 
				
			
			@ -1,201 +0,0 @@
 | 
			
		|||
test_name: Test basic schedule requests
 | 
			
		||||
 | 
			
		||||
stages:
 | 
			
		||||
- name: "[schedules_basic] Make sure we get any response"
 | 
			
		||||
  request:
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    method: GET
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
        function: validate_schedule:multiple
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] post schedule with no periods, expect it to be echoed back"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "same as off"
 | 
			
		||||
      periods: []
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 201
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_schedule:single
 | 
			
		||||
      function: validate_schedule:check_name
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        name: "{tavern.request_vars.json.name}"
 | 
			
		||||
      function: validate_schedule:check_periods
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        periods: "{tavern.request_vars.json.periods}"
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] post schedule, expect it to be echoed back"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "hello"
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "00:10"
 | 
			
		||||
        end: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
      - start: "00:50"
 | 
			
		||||
        end: "01:00"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 201
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_schedule:single
 | 
			
		||||
      function: validate_schedule:check_name
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        name: "{tavern.request_vars.json.name}"
 | 
			
		||||
      function: validate_schedule:check_periods
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        periods: "{tavern.request_vars.json.periods}"
 | 
			
		||||
    save:
 | 
			
		||||
      json:
 | 
			
		||||
        returned_name: "name"
 | 
			
		||||
        returned_id: "id"
 | 
			
		||||
        returned_periods: "periods"
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] get schedule, check name and some periods"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
    verify_response_with:
 | 
			
		||||
      function: validate_schedule:single
 | 
			
		||||
      function: validate_schedule:check_name
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        name: "{returned_name}"
 | 
			
		||||
      function: validate_schedule:check_periods
 | 
			
		||||
      extra_kwargs:
 | 
			
		||||
        periods: "{returned_periods}"
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] delete schedule"
 | 
			
		||||
  request:
 | 
			
		||||
    method: DELETE
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 200
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] get deleted schedule, expect 404"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/{returned_id}"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 404
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] get schedule with bad id"
 | 
			
		||||
  request:
 | 
			
		||||
    method: GET
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/this_id_is_invalid"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] post schedule with bad body (no json)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    data: "<b>not json</b><i>but html</i>"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] post schedule with bad body (no name)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "00:10"
 | 
			
		||||
        end: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
      - start: "00:50"
 | 
			
		||||
        end: "01:00"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] post schedule with bad body (name as number)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: 42
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "00:10"
 | 
			
		||||
        end: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
      - start: "00:50"
 | 
			
		||||
        end: "01:00"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] post schedule with bad period (no start)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "i am invalid"
 | 
			
		||||
      periods:
 | 
			
		||||
      - end: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] post schedule with bad period (no end)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "i am invalid"
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] post schedule with bad period (invalid start)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "i am invalid"
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "hello"
 | 
			
		||||
        end: "00:20"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] post schedule with bad period (invalid end)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "i am invalid"
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "12:10"
 | 
			
		||||
        end: 1215
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
 | 
			
		||||
- name: "[schedules_basic] post schedule with bad period (invalid end 2)"
 | 
			
		||||
  request:
 | 
			
		||||
    method: POST
 | 
			
		||||
    url: "http://localhost:5000/api/v1/schedules/"
 | 
			
		||||
    json:
 | 
			
		||||
      name: "i am invalid"
 | 
			
		||||
      periods:
 | 
			
		||||
      - start: "12:10"
 | 
			
		||||
        end: "25:90"
 | 
			
		||||
      - start: "00:30"
 | 
			
		||||
        end: "00:40"
 | 
			
		||||
  response:
 | 
			
		||||
    status_code: 400
 | 
			
		||||
| 
						 | 
				
			
			@ -27,14 +27,18 @@ def check_id(response, id):
 | 
			
		|||
def check_name(response, name):
 | 
			
		||||
    assert response.json().get("name") == name, "controller name check failed"
 | 
			
		||||
 | 
			
		||||
def check_ip(response, ip):
 | 
			
		||||
    assert response.json().get("ip") == ip, "controller ip check failed"
 | 
			
		||||
 | 
			
		||||
def find(response, id=None, name=None):
 | 
			
		||||
    print(response.json())
 | 
			
		||||
    for controller in response.json():
 | 
			
		||||
        if id != None and id != schedule.get("id"):
 | 
			
		||||
            print(schedule.get("id"))
 | 
			
		||||
        if id != None and id != controller.get("id"):
 | 
			
		||||
            print(controller.get("id"))
 | 
			
		||||
            continue
 | 
			
		||||
 | 
			
		||||
        if name != None and name != schedule.get("name"):
 | 
			
		||||
            print(schedule.get("name"))
 | 
			
		||||
        if name != None and name != controller.get("name"):
 | 
			
		||||
            print(controller.get("name"))
 | 
			
		||||
            continue
 | 
			
		||||
        return
 | 
			
		||||
    assert False, "controller not found in list"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue