Skip to content

Commit

Permalink
User storyjen hyväksymisehdot kirjattu Robot Framework tiedostoihin. …
Browse files Browse the repository at this point in the history
…Yleistä refaktorointia ja siistimistä
  • Loading branch information
n0spoon committed Dec 14, 2022
1 parent 67a42ac commit 49aa24b
Show file tree
Hide file tree
Showing 17 changed files with 407 additions and 60 deletions.
5 changes: 3 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension-pkg-whitelist=
fail-on=

# Specify a score threshold under which the program will exit with error.
fail-under=9.0
fail-under=10

# Interpret the stdin as a python script, whose filename needs to be passed as
# the module_or_package argument.
Expand Down Expand Up @@ -277,7 +277,7 @@ ignored-parents=
max-args=7

# Maximum number of attributes for a class (see R0902).
max-attributes=7
max-attributes=8

# Maximum number of boolean expressions in an if statement (see R0916).
max-bool-expr=5
Expand Down Expand Up @@ -418,6 +418,7 @@ disable=raw-checker-failed,
use-symbolic-message-instead,
missing-docstring,
unspecified-encoding,
line-too-long

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
20 changes: 12 additions & 8 deletions src/ReferenceLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ def run_application_with_inputs(self):
app.run()

def print_references(self):
self._reference_handler.print_references(self._file_handler.read_book_refs_from_file())

self._reference_handler.print_references(
self._file_handler.read_book_refs_from_file())

def print_reversed_references(self):
self._reference_handler.print_references(self._reference_handler.reverse_the_reference_list())

self._reference_handler.print_references(
self._reference_handler.reverse_the_reference_list())

def print_references_in_alphabetical_order(self):
self._reference_handler.print_references(self._reference_handler.sort_refs_to_alphabetical_order_by_author_surname())

self._reference_handler.print_references(
self._reference_handler.sort_refs_to_alphabetical_order_by_author_surname())

def print_references_in_reversed_alphabetical_order(self):
self._reference_handler.print_references(self._reference_handler.sort_refs_to_reverse_alphabetical_order_by_author_surname())
self._reference_handler.print_references(
self._reference_handler.sort_refs_to_reverse_alphabetical_order_by_author_surname())

def user_input(self, value):
self.stub_io.input_value(value)
Expand All @@ -43,7 +47,7 @@ def output_should_contain(self, value):
raise AssertionError(
f'Output \"{value}\" is not in {str(outputs)}'
)

def first_reference_should_be(self, value):
first_reference = self.stub_io.get_output_with_index(-2)
if not value == str(first_reference):
Expand Down
3 changes: 1 addition & 2 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ def run(self):
if self.referenceValidator.is_input_empty(key):
self.io.write("\nSyöte ei saa olla tyhjä\n")
continue
if self.referenceValidator.does_this_key_already_exist(str(key),
self.fileHandler.get_references()) == True:
if self.referenceValidator.does_this_key_already_exist(str(key), self.fileHandler.get_references()) == True:
self.io.write("\nTällä avaimella löytyy jo viite\n")
continue
author_first_name = self.io.read("Kirjailija etunimi: ")
Expand Down
2 changes: 1 addition & 1 deletion src/console_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ def read(self, prompt):
return input(prompt)

def get_log(self):
return self.written
return self.written
13 changes: 5 additions & 8 deletions src/file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class FileHandler:
# FileHandler takes the paths to the storage files as parameters
def __init__(self, books_file_path):
self.references = []
self.books_file_path = books_file_path
Expand Down Expand Up @@ -38,9 +37,9 @@ def write_book_refs_to_file(self, references):
self.references = references
with open(self.books_file_path, "w") as books_file:
for reference in self.references:
str_to_write = str(reference.key+";"+reference.author_first_name+";"+
reference.author_last_name+";"+reference.title+";"+
str(reference.year)+";"+reference.publisher+"\n")
str_to_write = str(reference.key+";"+reference.author_first_name+";" +
reference.author_last_name+";"+reference.title+";" +
str(reference.year)+";"+reference.publisher+"\n")
if len(reference.get_tags()) > 0:
for tag in reference.get_tags():
str_to_write = str_to_write.strip()+";"+tag
Expand All @@ -51,8 +50,8 @@ def write_book_refs_to_file(self, references):
def write_ref_object_into_bibtext_file(self, ref_object, file_to_write):
ref_object_fields = list(ref_object.__dict__.keys())

str_to_write = str("@"+ref_object.type+"{"+ref_object.key+",\n"+
" author = {"+ref_object.author_first_name+", "+ref_object.author_last_name+"},\n")
str_to_write = str("@"+ref_object.type+"{"+ref_object.key+",\n" +
" author = {"+ref_object.author_first_name+", "+ref_object.author_last_name+"},\n")
for key in ref_object_fields[4:-1]:
str_to_write = str_to_write + \
(" "+key+" = {"+str(ref_object.__dict__[key])+"},\n")
Expand All @@ -70,7 +69,6 @@ def write_bibtext_file(self, path_to_bibtext_file):
return 1

def remove_reference_from_file(self, ref_key):
# this method removes the wanted reference from the list and then rewrites the csv file without it
ref_list = self.read_book_refs_from_file()
rem_success = False
for ref in ref_list:
Expand All @@ -83,6 +81,5 @@ def remove_reference_from_file(self, ref_key):
return rem_success

def clear_for_rewrite(self):
# opening a csv file like this removes the content of the file
with open(self.books_file_path, "w+") as books_file:
books_file.close()
7 changes: 5 additions & 2 deletions src/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
from validate_reference import ValidateReference
from app import App


def main():
path_to_this_files_location = os.path.dirname(os.path.realpath(__file__))
books_file_path = str(path_to_this_files_location+"/storage/book_references.csv")
books_file_path = str(path_to_this_files_location +
"/storage/book_references.csv")
console_io = ConsoleIO()
filehandler = FileHandler(books_file_path)
referencehandler = ReferenceHandler(console_io, filehandler)
referencevalidator = ValidateReference()
app = App(console_io, filehandler, referencehandler, referencevalidator)
app.run()


if __name__ == "__main__":
main()
main()
14 changes: 5 additions & 9 deletions src/refclasses/bookref.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,19 @@ def get_year(self):

def get_publisher(self):
return self.publisher

def get_tags(self):
return self.tags

def __str__(self):
if len(self.tags) == 0:
return (f"\033[0;33mkey\033[0m: \033[1;31m{self.key}\033[0m, \033[0;33mauthor\033[0m: \033[1;32m{self.author_first_name}\033[0m, \033[1;32m{self.author_last_name}\033[0m, \033[0;33mtitle\033[0m: \033[1;34m{self.title}\033[0m, \033[0;33myear\033[0m: \033[1;35m{str(self.year)}\033[0m, \033[0;33mpublisher\033[0m: \033[1;36m{self.publisher}\033[0m")
else:
tags = self.tags_as_str()
return (f"\033[0;33mkey\033[0m: \033[1;31m{self.key}\033[0m, \033[0;33mauthor\033[0m: \033[1;32m{self.author_first_name}\033[0m, \033[1;32m{self.author_last_name}\033[0m, \033[0;33mtitle\033[0m: \033[1;34m{self.title}\033[0m, \033[0;33myear\033[0m: \033[1;35m{str(self.year)}\033[0m, \033[0;33mpublisher\033[0m: \033[1;36m{self.publisher}\033[0m, \033[0;33mtagit\033[0m: \033[1;37m{tags}\033[0m ")
return f"\033[0;33mkey\033[0m: \033[1;31m{self.key}\033[0m, \033[0;33mauthor\033[0m: \033[1;32m{self.author_first_name}\033[0m, \033[1;32m{self.author_last_name}\033[0m, \033[0;33mtitle\033[0m: \033[1;34m{self.title}\033[0m, \033[0;33myear\033[0m: \033[1;35m{str(self.year)}\033[0m, \033[0;33mpublisher\033[0m: \033[1;36m{self.publisher}\033[0m"
tags = self.tags_as_str()
return f"\033[0;33mkey\033[0m: \033[1;31m{self.key}\033[0m, \033[0;33mauthor\033[0m: \033[1;32m{self.author_first_name}\033[0m, \033[1;32m{self.author_last_name}\033[0m, \033[0;33mtitle\033[0m: \033[1;34m{self.title}\033[0m, \033[0;33myear\033[0m: \033[1;35m{str(self.year)}\033[0m, \033[0;33mpublisher\033[0m: \033[1;36m{self.publisher}\033[0m, \033[0;33mtagit\033[0m: \033[1;37m{tags}\033[0m"

def tags_as_str(self):
return_string = ""
for tag in self.tags:
return_string = return_string + str(tag) + ", "
return_string = return_string + str(tag) + ", "
return_string = return_string[:-2]
return return_string

def __lt__(self, other):
return self.author < other.author
18 changes: 6 additions & 12 deletions src/reference_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,28 @@ def get_references(self):
def set_references(self, references):
self.references = references

# For every different ref object we need
# different method because of the different
#fields in references
def generate_book_reference_object(self, inputs):
self.references = self.filehandler.read_book_refs_from_file()
# Generate ref
# After that send the ref to filehandler for storing
# (In this model all references are
# written to the file when new one is added)
book_object = Bookref(str(inputs[0]), inputs[1],
inputs[2], inputs[3],
int(inputs[4]), inputs[5])
inputs[2], inputs[3],
int(inputs[4]), inputs[5])
self.references.append(book_object)
self.filehandler.write_book_refs_to_file(self.references)


def print_references(self, references_to_print):
for reference in references_to_print:
self.io_object.write(str(reference))

def sort_refs_to_alphabetical_order_by_author_surname(self):
self.references = self.filehandler.read_book_refs_from_file()
sorted_references = sorted(self.references,key=lambda ref: ref.author_last_name)
sorted_references = sorted(
self.references, key=lambda ref: ref.author_last_name)
return sorted_references

def sort_refs_to_reverse_alphabetical_order_by_author_surname(self):
self.references = self.filehandler.read_book_refs_from_file()
sorted_references = sorted(self.references,key=lambda ref: ref.author_last_name, reverse=True)
sorted_references = sorted(
self.references, key=lambda ref: ref.author_last_name, reverse=True)
return sorted_references

def reverse_the_reference_list(self):
Expand Down
13 changes: 6 additions & 7 deletions src/stub_io.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
class StubIO:
def __init__(self, inputs=None):
self.inputs = inputs or []
self.outputs = []

self.outputs = []

def input_value(self,value):
def input_value(self, value):
self.inputs.append(value)

def write(self, value):
self.outputs.append(value)

def read(self, prompt):
if len(self.inputs) > 0:
return self.inputs.pop(0)
Expand All @@ -18,9 +17,9 @@ def read(self, prompt):

def get_inputs(self):
return self.inputs

def get_outputs(self):
return self.outputs

def get_output_with_index(self, index):
return self.outputs[index]
return self.outputs[index]
2 changes: 1 addition & 1 deletion src/tests/bookref_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def test_bookref_tags_are_in_print_if_they_exist(self):
self.bookref.tags = self.tags
printti = str(self.bookref)
#self.assertEqual(printti,"key: Testiavain, author: Testinimi, title: Testititle, year: 1999, publisher: Testikustantaja")
self.assertEqual(printti, "\033[0;33mkey\033[0m: \033[1;31mTestiavain\033[0m, \033[0;33mauthor\033[0m: \033[1;32mTestikirjailija_etunimi\033[0m, \033[1;32mTestikirjailija_sukunimi\033[0m, \033[0;33mtitle\033[0m: \033[1;34mTestititle\033[0m, \033[0;33myear\033[0m: \033[1;35m1999\033[0m, \033[0;33mpublisher\033[0m: \033[1;36mTestikustantaja\033[0m, \033[0;33mtagit\033[0m: \033[1;37mFiktio, Fakta\033[0m ")
self.assertEqual(printti, "\033[0;33mkey\033[0m: \033[1;31mTestiavain\033[0m, \033[0;33mauthor\033[0m: \033[1;32mTestikirjailija_etunimi\033[0m, \033[1;32mTestikirjailija_sukunimi\033[0m, \033[0;33mtitle\033[0m: \033[1;34mTestititle\033[0m, \033[0;33myear\033[0m: \033[1;35m1999\033[0m, \033[0;33mpublisher\033[0m: \033[1;36mTestikustantaja\033[0m, \033[0;33mtagit\033[0m: \033[1;37mFiktio, Fakta\033[0m")
54 changes: 54 additions & 0 deletions src/tests/fifth_user_story_acceptance_criteria.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
*** Settings ***
Resource resource.robot

*** Test Cases ***
User Can Not Create BibTeX File From Empty Storage
User Input 3

Run Application With Inputs
Output Should Contain Ei viitteitä \n

User Can Give Command To Create BibTeX File From References In Storage
User Input 1
User Input @{KEY}
User Input @{AUTHOR_FIRST_NAME}
User Input @{AUTHOR_LAST_NAME}
User Input @{BOOK}
User Input @{YEAR}
User Input @{PUBLISHER}
User Input \
User Input 3
User Input \

Run Application With Inputs
Output Should Contain references.bib tiedosto luotu sijaintiin ${EXECDIR}\n

Program Can Create BibTeX File
User Input 1
User Input @{KEY_2}
User Input @{AUTHOR_FIRST_NAME_2}
User Input @{AUTHOR_LAST_NAME_2}
User Input @{BOOK_2}
User Input @{YEAR_2}
User Input @{PUBLISHER_2}
User Input \
User Input 3
User Input \

Run Application With Inputs
Output Should Contain references.bib tiedosto luotu sijaintiin ${EXECDIR}\n

Program Outputs Absolute Path Where BibTeX File Was Created Into Terminal
User Input 1
User Input @{KEY_3}
User Input @{AUTHOR_FIRST_NAME_3}
User Input @{AUTHOR_LAST_NAME_3}
User Input @{BOOK_3}
User Input @{YEAR_3}
User Input @{PUBLISHER_3}
User Input \
User Input 3
User Input \

Run Application With Inputs
Output Should Contain references.bib tiedosto luotu sijaintiin ${EXECDIR}\n
Loading

0 comments on commit 49aa24b

Please sign in to comment.