示例#1
0
def test_wrong_start_end_date():
    start_date = datetime(2021, 9, 9)
    end_date = datetime(2021, 8, 8)
    with pytest.raises(ValidationError):
        Event(1, Name('nome'), Description('descr'), Author(0),
              Date(start_date), Date(end_date), Location('casa mia'),
              Category(1), Priority(1))
示例#2
0
def test_index_todolist():
    toDoList = ToDoList()
    end_date = datetime(2021, 9, 9)
    start_date = datetime(2021, 8, 8)
    event = Event(1, Name('nome'), Description('descr'), Author(0),
                  Date(start_date), Date(end_date), Location('casa mia'),
                  Category(1), Priority(1))
    toDoList.add_event(event)
    assert toDoList.event(0) == event
示例#3
0
def test_event_str():
    end_date = datetime(2021, 9, 9)
    start_date = datetime(2021, 8, 8)
    event = Event(1, Name('nome'), Description('descr'), Author(0),
                  Date(start_date), Date(end_date), Location('casa mia'),
                  Category(1), Priority(1))
    print(event)

    assert str(
        event
    ) == 'name\t description\t start_date\t end_date\t location\t category\t priority\n' + str(
        event.name) + '\t' + str(event.description) + '\t' + str(
            event.start_date) + '\t' + str(event.end_date) + '\t' + str(
                event.location) + '\t' + str(event.category) + '\t' + str(
                    event.priority) + '\n'
示例#4
0
def test_sort_priority():
    toDoList = ToDoList()
    end_date = datetime(2021, 9, 9)
    start_date = datetime(2021, 8, 8)
    event = Event(1, Name('nome'), Description('descr'), Author(0),
                  Date(start_date), Date(end_date), Location('casa mia'),
                  Category(1), Priority(2))
    toDoList.add_event(event)
    start_date2 = datetime(2021, 7, 7)
    event2 = Event(2, Name('nome'), Description('descr'), Author(0),
                   Date(start_date2), Date(end_date), Location('casa mia'),
                   Category(1), Priority(1))
    toDoList.add_event(event2)
    toDoList.sort_by_priority()
    assert toDoList.event(0) == event
示例#5
0
    def fetch_events(self):
        res = requests.get(url=f'{api_server}/events',
                           headers={'Authorization': f'Token {self.__key}'})
        if res.status_code != 200:
            return None

        json = res.json()
        for item in json:
            id = int(item['id'])
            name = Name(item['name'])
            description = Description(item['description'])
            author = Author(item['author'])
            start_date = Date(
                datetime.strptime(item['start_date'], '%Y-%m-%dT%H:%M:%SZ'))
            end_date = Date(
                datetime.strptime(item['end_date'], '%Y-%m-%dT%H:%M:%SZ'))
            location = Location(item['location'])
            category = Category(item['category'])
            priority = Priority(item['priority'])
            self.__toDoList.add_event(
                Event(id, name, description, author, start_date, end_date,
                      location, category, priority))

        return res.json()
示例#6
0
def test_wrong_date():
    date = datetime(2010, 9, 9)
    with pytest.raises(ValidationError):
        Date(date)