예제 #1
0
def test_formatDate_Error(dateStr):
    """ Test DateUtil.formatDate() bad dates """
    # Call init fixture
    initEnv()

    with pytest.raises(ValueError):
        DateUtil.formatDate(dateStr)
예제 #2
0
def test_formatDate_OK(dateStr):
    """ Test DateUtil.formatDate() with correct dates no modification must appear """
    # Call init fixture
    initEnv()

    dateFormated = DateUtil.formatDate(dateStr)
    assert dateStr == dateFormated
예제 #3
0
def test_formatDate_convert_OK(dateStr, formatStr):
    """ Test DateUtil.formatDate() date reformatting """
    # Call init fixture
    initEnv()

    dateFormated = DateUtil.formatDate(dateStr)
    assert dateStr != dateFormated
    assert datetime.datetime.strptime(dateStr, formatStr) == \
            datetime.datetime.strptime(dateFormated, '%Y/%m/%d')
예제 #4
0
    def validate(self):
        """ Check Data entered by user
            if OK return True
        """
        isOK = False
        try:
            if self.nameVar.get() == "":
                raise ValueError(_("Please give a portion name"))
            if self.dateVar.get() == "":
                raise ValueError(_("Please give a date"))
            DateUtil.formatDate(self.dateVar.get())
            if self.patientCodeCombobox.get() == "":
                raise ValueError(_("Please give a patient code"))
            if self.portionTypeVar.get() == "":
                raise ValueError(_("Please give a portion type"))
            if self.periodCombobox.get() == "":
                raise ValueError(_("Please give a period"))

            # Ask if portion exists
            code, portionExists = self.database.getPortionCode(
                self.nameVar.get(), self.dateVar.get(),
                self.patientCodeCombobox.get())

            if portionExists:
                isMofificationOk = messagebox.askyesno(_("Add or modify Portion in database"),
                        _("Do you really want to modify this existing portion in database ?") + \
                        "\n" + _("Portion code") + " : " + str(code) + \
                        "\n" + _("Portion name") + " : " + self.nameVar.get() + \
                        "\n" + _("Date") + " : "  + self.dateVar.get() + \
                        "\n" + _("Patient code") + " : "  + self.patientCodeCombobox.get(),
                        icon='warning')
                if not isMofificationOk:
                    raise ValueError(_("Please modify portion identificators"))

            isOK = True
        except ValueError as exc:
            self.bell()
            messagebox.showwarning(_("Bad input"),
                                   message=_("Error") + " : " + str(exc) +
                                   " !")
        return isOK
예제 #5
0
 def clicExistingPortion(self, dummy):
     """ Update portion input field with chosen listbox item """
     # Get selection
     selectedExistingPortion = list(self.portionListBox.curselection())
     if len(selectedExistingPortion) > 0:
         nameDate = self.portionListBox.get(
             selectedExistingPortion[0]).split(" / ")
         self.nameVar.set(nameDate[0])
         dateRead = nameDate[1]
         try:
             DateUtil.formatDate(dateRead)
         except ValueError as exc:
             self.bell()
             messagebox.showwarning(
                 _("Loading values"),
                 str(exc) + "\n" + _("Please correct the date displayed") +
                 " !")
         self.dateVar.set(dateRead)
         self.patientCodeCombobox.set(nameDate[2])
         self.portionTypeVar.set(nameDate[3])
         self.periodCombobox.set(nameDate[4])