コード例 #1
0
 def test_create_entry4(self):
     try:
         create_entry(self.r_els4, self.r_indices4)
     except DataValueError:
         pass
     else:
         self.fail("Did not see DataValueError")
コード例 #2
0
def start_screen():
    """Runs the start screen and provides the user with the
    options to create a new entry, search for entries or quit
    """
    clear_screen()
    print("WorkLog | Track Your Time")
    print('''
    [A] Create New Entry
    [B] Search Entries
    [C] Quit Program
    ''')

    while True:
        user_input = input("What Would You Like To Do? ")

        if user_input.upper() == "A":
            create_entry()
            start_screen()
        elif user_input.upper() == "B":
            search_entry()
            start_screen()
        elif user_input.upper() == "C":
            print("Thanks! See You Next Time!")
            sys.exit()
        else:
            print("Please Enter A, B or C!")
            pass
コード例 #3
0
    def do_POST(self):
        # Set response code to 'Created'
        self._set_headers(201)
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)

        # Convert JSON string to Python dictionary
        post_body = json.loads(post_body)

        # Parse the URL
        (resource, id) = self.parse_url(self.path)

        # Initialize new animal
        new_item = None

        # Add a new item to the list. Don't worry about
        # the orange squiggle, you'll define the create_item
        # function next

        if resource == "entries":
            new_item = create_entry(post_body)

        if resource == "moods":
            new_item = create_mood(post_body)

        # Encode the new animal and send in response
        self.wfile.write(f"{new_item}".encode())
コード例 #4
0
 def test_create_entry5(self):
     er = {
         "color": "yellow",
         "firstname": "James",
         "lastname": "Murphy",
         "phonenumber": "018-154-6474",
         "zipcode": "83880"
     }
     self.assertEquals(create_entry(self.r_els5, self.r_indices5), er)
コード例 #5
0
 def test_create_entry3(self):
     er = {
             "color": "yellow",
             "firstname": "Booker T.",
             "lastname": "Washington",
             "phonenumber": "373-781-7380",
             "zipcode": "87360"
     }
     self.assertEquals(create_entry(self.r_els3, self.r_indices3), er)
コード例 #6
0
    def do_POST(self):
        self._set_headers(201)
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)

        # Convert JSON string to Python dictionary
        post_body = json.loads(post_body)

        # Parse the URL
        (resource, id) = self.parse_url(self.path)

        if resource == "entries":
            new_entry = create_entry(post_body)
            # Encode the new animal and send in response
            self.wfile.write(f"{new_entry}".encode())
コード例 #7
0
    def do_POST(self):
        self._set_headers(201)
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)

        post_body = json.loads(post_body)

        (resource, value) = self.parse_url(self.path)

        response = {}

        if resource == "entries":
            response = create_entry(post_body)

        return self.wfile.write(response.encode())
コード例 #8
0
    def do_POST(self):
        self._set_headers(201)
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)

        post_body = json.loads(post_body)

        (resource, id) = self.parse_url(self.path)

        new_entry = None

        if resource == "entries":
            new_entry = create_entry(post_body)
        # PUT HASHTAG LOGIC HERE

        self.wfile.write(f"{new_entry}".encode())
コード例 #9
0
    def do_POST(self):
        self._set_headers(201)
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)

        # Convert JSON string to a Python dictionary
        post_body = json.loads(post_body)

        # Parse the URL
        (resource, id) = self.parse_url(self.path)

        new_item = None

        if resource == "entries":
            new_item = create_entry(post_body)
        if resource == "tags":
            new_item = create_tag(post_body)
        if resource == "entryTags":
            new_item = create_entry_tag(post_body)

        self.wfile.write(f"{new_item}".encode())
コード例 #10
0
    def do_POST(self):
        self._set_headers(201)
        # You should be able to explain the purpose of a 201 status code.
        content_len = int(self.headers.get('content-length', 0))
        post_body = self.rfile.read(content_len)

        # Convert JSON string to a Python dictionary
        post_body = json.loads(post_body)

        # Parse the URL
        (resource, id) = self.parse_url(self.path)

        # Initialize new entry
        new_entry = None

        # Add a new entry to the list. Don't worry about
        # the orange squiggle, you'll define the create_entry
        # function next.
        if resource == "entries":
            new_entry = create_entry(post_body)
            # Encode the new entry and send in response
            self.wfile.write(f"{new_entry}".encode())