Add unittests
This commit is contained in:
parent
e6f38a5476
commit
b65dc7c392
31
tests/scripts_get_answered_question_unittest.py
Normal file
31
tests/scripts_get_answered_question_unittest.py
Normal file
@ -0,0 +1,31 @@
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
from scripts.get_answered_questions import get_answered_questions, get_question_list
|
||||
|
||||
|
||||
def open_test_case_file(n: int) -> List[bytes]:
|
||||
tests_path = Path(__file__).parent.joinpath()
|
||||
|
||||
with open(f'{tests_path}/testcases/testcase{n}.md', 'rb') as f:
|
||||
file_list = [line.rstrip() for line in f.readlines()]
|
||||
return file_list
|
||||
|
||||
|
||||
class QuestionCount(unittest.TestCase):
|
||||
|
||||
def test_case_1(self):
|
||||
raw_list = open_test_case_file(1)
|
||||
question_list = get_question_list(raw_list)
|
||||
answers = get_answered_questions(question_list)
|
||||
|
||||
self.assertEqual(len(question_list), 11)
|
||||
self.assertEqual(answers, 3)
|
||||
|
||||
def test_case_2(self):
|
||||
raw_list = open_test_case_file(2)
|
||||
question_list = get_question_list(raw_list)
|
||||
answers = get_answered_questions(question_list)
|
||||
|
||||
self.assertEqual(len(question_list), 16)
|
||||
self.assertEqual(answers, 11)
|
@ -36,7 +36,7 @@ def count_details(file_list):
|
||||
if b'</details>' in line:
|
||||
details_final_count += 1
|
||||
|
||||
return details_count, details_final_count
|
||||
return details_count == details_final_count
|
||||
|
||||
|
||||
def check_details_tag(file_list):
|
||||
|
@ -3,37 +3,42 @@ WIP
|
||||
|
||||
Yes, we do write tests for our tests.
|
||||
"""
|
||||
import unittest
|
||||
# import pathlib
|
||||
|
||||
# from tests import *
|
||||
# from scripts import get_answered_questions
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
from unittest import TestCase
|
||||
from tests import syntax_checker
|
||||
|
||||
|
||||
def open_test_case_file(n: int):
|
||||
pass
|
||||
# p = pathlib.Path(
|
||||
# rf'D:\PycharmProjects\devops-interview-questions\scripts\tests\' + '
|
||||
# testcase{n}.md')
|
||||
def open_test_case_file(n: int) -> List[bytes]:
|
||||
tests_path = Path(__file__).parent.joinpath()
|
||||
|
||||
# with open(p, 'rb') as f:
|
||||
# file_list = [line.rstrip() for line in f.readlines()]
|
||||
# return file_list
|
||||
with open(f'{tests_path}/testcases/testcase{n}.md', 'rb') as f:
|
||||
file_list = [line.rstrip() for line in f.readlines()]
|
||||
return file_list
|
||||
|
||||
|
||||
class QuestionCount(unittest.TestCase):
|
||||
solutions = (
|
||||
test_case_1 = open_test_case_file(1)
|
||||
test_case_2 = open_test_case_file(2)
|
||||
test_case_3 = open_test_case_file(3)
|
||||
|
||||
)
|
||||
|
||||
def test_count_case_1(self):
|
||||
pass
|
||||
# raw_list = open_test_case_file(1)
|
||||
# question_list = get_question_list(raw_list)
|
||||
# answers = get_answered_questions.n_answers(question_list)
|
||||
class TestSyntax(TestCase):
|
||||
|
||||
# self.assertEqual(len(question_list), 21)
|
||||
# self.assertEqual(answers, 2)
|
||||
def test_details_count_case1(self):
|
||||
self.assertTrue(syntax_checker.count_details(test_case_1))
|
||||
|
||||
def test_count_case_2(self):
|
||||
pass
|
||||
def test_details_count_case2(self):
|
||||
self.assertTrue(syntax_checker.count_details(test_case_2))
|
||||
|
||||
def test_details_errors_1(self):
|
||||
syntax_checker.check_details_tag(test_case_1)
|
||||
self.assertFalse(syntax_checker.errors)
|
||||
|
||||
def test_details_errors_2(self):
|
||||
syntax_checker.check_details_tag(test_case_2)
|
||||
self.assertFalse(syntax_checker.errors)
|
||||
#
|
||||
# def test_details_error_exist_1(self):
|
||||
# syntax_checker.check_details_tag(test_case_3)
|
||||
# print(syntax_checker.errors)
|
||||
# self.assertEqual(len(syntax_checker.errors), 3)
|
||||
|
67
tests/testcases/testcase1.md
Normal file
67
tests/testcases/testcase1.md
Normal file
@ -0,0 +1,67 @@
|
||||
<details>
|
||||
<summary>What is Docker? What are you using it for?</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>How containers are different from VMs?</summary><br><b>
|
||||
|
||||
The primary difference between containers and VMs is that containers allow you to virtualize
|
||||
multiple workloads on the operating system while in the case of VMs the hardware is being virtualized to
|
||||
run multiple machines each with its own OS.
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>In which scenarios would you use containers and in which you would prefer to use VMs?</summary><br><b>
|
||||
|
||||
You should choose VMs when:
|
||||
* you need run an application which requires all the resources and functionalities of an OS
|
||||
* you need full isolation and security
|
||||
|
||||
You should choose containers when:
|
||||
* you need a lightweight solution
|
||||
* Running multiple versions or instances of a single application
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>Explain Docker architecture</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>Describe in detail what happens when you run `docker run hello-world`?</summary><br><b>
|
||||
|
||||
Docker CLI passes your request to Docker daemon.
|
||||
Docker daemon downloads the image from Docker Hub
|
||||
Docker daemon creates a new container by using the image it downloaded
|
||||
Docker daemon redirects output from container to Docker CLI which redirects it to the standard output
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>How do you run a container?</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>What `docker commit` does?. When will you use it?</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>How would you transfer data from one container into another?</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>What happens to data of the container when a container exists?</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>Explain what each of the following commands do:
|
||||
|
||||
* docker run
|
||||
* docker rm
|
||||
* docker ps
|
||||
* docker pull
|
||||
* docker build
|
||||
* docker commit</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>How do you remove old, non running, containers?</summary><br><b>
|
||||
</b></details>
|
179
tests/testcases/testcase2.md
Normal file
179
tests/testcases/testcase2.md
Normal file
@ -0,0 +1,179 @@
|
||||
<details>
|
||||
<summary>Explain the following code:
|
||||
|
||||
<code>:(){ :|:& };:</code>
|
||||
|
||||
</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>Can you give an example to some Bash best practices?</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>What is the ternary operator? How do you use it in bash?</summary><br><b>
|
||||
|
||||
A short way of using if/else. An example:
|
||||
|
||||
[[ $a = 1 ]] && b="yes, equal" || b="nope"
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>What does the following code do and when would you use it?
|
||||
|
||||
<code>diff <(ls /tmp) <(ls /var/tmp)</code>
|
||||
|
||||
</summary><br>
|
||||
It is called 'process substitution'. It provides a way to pass the output of a command to another command when using a pipe <code>|</code> is not possible. It can be used when a command does not support <code>STDIN</code> or you need the output of multiple commands.
|
||||
https://superuser.com/a/1060002/167769
|
||||
</details>
|
||||
|
||||
|
||||
## SQL
|
||||
|
||||
<a name="sql-beginner"></a>
|
||||
#### :baby: Beginner
|
||||
|
||||
<details>
|
||||
<summary>What does SQL stand for?</summary><br><b>
|
||||
|
||||
Structured Query Language
|
||||
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>How is SQL Different from NoSQL</summary><br><b>
|
||||
|
||||
The main difference is that SQL databases are structured (data is stored in the form of
|
||||
tables with rows and columns - like an excel spreadsheet table) while NoSQL is
|
||||
unstructured, and the data storage can vary depending on how the NoSQL DB is set up, such
|
||||
as key-value pair, document-oriented, etc.
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>What does it mean when a database is ACID compliant?</summary><br>
|
||||
|
||||
ACID stands for Atomicity, Consistency, Isolation, Durability. In order to be ACID compliant, the database much meet each of the four criteria
|
||||
|
||||
**Atomicity** - When a change occurs to the database, it should either succeed or fail as a whole.
|
||||
|
||||
For example, if you were to update a table, the update should completely execute. If it only partially executes, the
|
||||
update is considered failed as a whole, and will not go through - the DB will revert back to it's original
|
||||
state before the update occurred. It should also be mentioned that Atomicity ensures that each
|
||||
transaction is completed as it's own stand alone "unit" - if any part fails, the whole statement fails.
|
||||
|
||||
**Consistency** - any change made to the database should bring it from one valid state into the next.
|
||||
|
||||
For example, if you make a change to the DB, it shouldn't corrupt it. Consistency is upheld by checks and constraints that
|
||||
are pre-defined in the DB. For example, if you tried to change a value from a string to an int when the column
|
||||
should be of datatype string, a consistent DB would not allow this transaction to go through, and the action would
|
||||
not be executed
|
||||
|
||||
**Isolation** - this ensures that a database will never be seen "mid-update" - as multiple transactions are running at
|
||||
the same time, it should still leave the DB in the same state as if the transactions were being run sequentially.
|
||||
|
||||
For example, let's say that 20 other people were making changes to the database at the same time. At the
|
||||
time you executed your query, 15 of the 20 changes had gone through, but 5 were still in progress. You should
|
||||
only see the 15 changes that had completed - you wouldn't see the database mid-update as the change goes through.
|
||||
|
||||
**Durability** - Once a change is committed, it will remain committed regardless of what happens
|
||||
(power failure, system crash, etc.). This means that all completed transactions
|
||||
must be recorded in non-volatile memory.
|
||||
|
||||
Note that SQL is by nature ACID compliant. Certain NoSQL DB's can be ACID compliant depending on
|
||||
how they operate, but as a general rule of thumb, NoSQL DB's are not considered ACID compliant
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>When is it best to use SQL? NoSQL?</summary><br><b>
|
||||
|
||||
SQL - Best used when data integrity is crucial. SQL is typically implemented with many
|
||||
businesses and areas within the finance field due to it's ACID compliance.
|
||||
|
||||
NoSQL - Great if you need to scale things quickly. NoSQL was designed with web applications
|
||||
in mind, so it works great if you need to quickly spread the same information around to
|
||||
multiple servers
|
||||
|
||||
Additionally, since NoSQL does not adhere to the strict table with columns and rows structure
|
||||
that Relational Databases require, you can store different data types together.
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>What is a Cartesian Product?</summary><br>
|
||||
|
||||
A Cartesian product is when all rows from the first table are joined to all rows in the second
|
||||
table. This can be done implicitly by not defining a key to join, or explicitly by
|
||||
calling a CROSS JOIN on two tables, such as below:
|
||||
|
||||
Select * from customers **CROSS JOIN** orders;
|
||||
|
||||
Note that a Cartesian product can also be a bad thing - when performing a join
|
||||
on two tables in which both do not have unique keys, this could cause the returned information
|
||||
to be incorrect.
|
||||
</details>
|
||||
|
||||
##### SQL Specific Questions
|
||||
|
||||
For these questions, we will be using the Customers and Orders tables shown below:
|
||||
|
||||
**Customers**
|
||||
|
||||
Customer_ID | Customer_Name | Items_in_cart | Cash_spent_to_Date
|
||||
------------ | ------------- | ------------- | -------------
|
||||
100204 | John Smith | 0 | 20.00
|
||||
100205 | Jane Smith | 3 | 40.00
|
||||
100206 | Bobby Frank | 1 | 100.20
|
||||
|
||||
**ORDERS**
|
||||
|
||||
Customer_ID | Order_ID | Item | Price | Date_sold
|
||||
------------ | ------------- | ------------- | ------------- | -------------
|
||||
100206 | A123 | Rubber Ducky | 2.20 | 2019-09-18
|
||||
100206 | A123 | Bubble Bath | 8.00 | 2019-09-18
|
||||
100206 | Q987 | 80-Pack TP | 90.00 | 2019-09-20
|
||||
100205 | Z001 | Cat Food - Tuna Fish | 10.00 | 2019-08-05
|
||||
100205 | Z001 | Cat Food - Chicken | 10.00 | 2019-08-05
|
||||
100205 | Z001 | Cat Food - Beef | 10.00 | 2019-08-05
|
||||
100205 | Z001 | Cat Food - Kitty quesadilla | 10.00 | 2019-08-05
|
||||
100204 | X202 | Coffee | 20.00 | 2019-04-29
|
||||
|
||||
<details>
|
||||
<summary>How would I select all fields from this table?</summary><br><b>
|
||||
|
||||
Select * <br>
|
||||
From Customers;
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>How many items are in John's cart?</summary><br><b>
|
||||
|
||||
Select Items_in_cart <br>
|
||||
From Customers <br>
|
||||
Where Customer_Name = "John Smith";
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>What is the sum of all the cash spent across all customers?</summary><br><b>
|
||||
|
||||
Select SUM(Cash_spent_to_Date) as SUM_CASH <br>
|
||||
From Customers;
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>Tell me about your last big project/task you worked on</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>What was most challenging part in the project you worked on?</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>Why do you want to work here?</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>How did you hear about us?</summary><br><b>
|
||||
|
||||
Tell them how did you hear about them :D
|
||||
Relax, there is no wrong or right answer here...I think.
|
||||
</b></details>
|
58
tests/testcases/testcase3.md
Normal file
58
tests/testcases/testcase3.md
Normal file
@ -0,0 +1,58 @@
|
||||
|
||||
<summary>You have a colleague you don‘t get along with. Tell us some strategies how you create a good work relationship with them anyway.</summary><br><b>
|
||||
|
||||
Bad answer: I don't.
|
||||
Better answer: Every person has strengths and weaknesses. This is true also for colleagues I don't have good work relationship with and this is what helps me to create good work relationship with them. If I am able to highlight or recognize their strengths I'm able to focus mainly on that when communicating with them.
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>What do you love about your work?</summary><br><b>
|
||||
|
||||
You know the best, but some ideas if you find it hard to express yourself:
|
||||
|
||||
* Diversity
|
||||
* Complexity
|
||||
* Challenging
|
||||
* Communication with several different teams
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>What are your responsibilities in your current position?</summary><br><b>
|
||||
|
||||
You know the best :)
|
||||
</b></details>
|
||||
|
||||
|
||||
<summary>Why should we hire you for the role?</summary><br><b>
|
||||
|
||||
You can use and elaborate on one or all of the following:
|
||||
|
||||
* Passion
|
||||
* Motivation
|
||||
* Autodidact
|
||||
* Creativity (be able to support it with some actual examples)
|
||||
</b></details>
|
||||
|
||||
## Questions you CAN ask
|
||||
|
||||
A list of questions you as a candidate can ask the interviewer during or after the interview.
|
||||
These are only a suggestion, use them carefully. Not every interviewer will be able to answer these (or happy to) which should be perhaps a red flag warning for your regarding working in such place but that's really up to you.
|
||||
|
||||
<details>
|
||||
<summary>What do you like about working here?</summary><br><b>
|
||||
</b></details>
|
||||
|
||||
<details>
|
||||
<summary>How does the company promote personal growth?</summary><br><b>
|
||||
</b>
|
||||
|
||||
<details>
|
||||
<summary>What is the current level of technical debt you are dealing with?</summary><br><b>
|
||||
|
||||
Be careful when asking this question - all companies, regardless of size, have some level of tech debt.
|
||||
Phrase the question in the light that all companies have the deal with this, but you want to see the current
|
||||
pain points they are dealing with <br>
|
||||
|
||||
This is a great way to figure how managers deal with unplanned work, and how good they are at
|
||||
setting expectations with projects.
|
||||
</b></details>
|
Loading…
Reference in New Issue
Block a user