Ejemplo n.º 1
0
def domain_readers():
    reader1 = Reader(code='r2rwr3re-bdfc-e2ww-5644-hd94id04kd9r',
                     full_name='John Smith',
                     reg_date=datetime.date(2016, 1, 1))
    reader2 = Reader(code='q3eqweq2-ffwe-r23r-43r3-5eh5thrt3trw',
                     full_name='John Doe',
                     reg_date=datetime.date(2016, 6, 1))
    reader3 = Reader(code='43r3regl-grgf-kjhm-gg3g-2r2r2r2e22rw',
                     full_name='Jason Statham',
                     reg_date=datetime.date(2010, 9, 15))
    reader4 = Reader(code='4yfhfjuk-gefd-e2wq-2rsf-23rdsghdtdhf',
                     full_name='Marie Curie',
                     reg_date=datetime.date(1900, 12, 15))
    return [reader1, reader2, reader3, reader4]
Ejemplo n.º 2
0
 def _convert_to_domain(cls, reader):
     domain_book = DomainReader.from_dict({
         'code': reader.code,
         'full_name': reader.full_name,
         'reg_date': reader.reg_date
     })
     return domain_book
Ejemplo n.º 3
0
def test_book_model_init():
    code = uuid.uuid4()
    reader = Reader(code=code,
                    full_name='VS',
                    reg_date=datetime.date(2017, 2, 13))
    assert reader.code == code
    assert reader.full_name == 'VS'
    assert reader.reg_date == datetime.date(2017, 2, 13)
Ejemplo n.º 4
0
def test_book_model_from_dict():
    code = uuid.uuid4()
    reader = Reader.from_dict({
        'code': code,
        'full_name': 'VS',
        'reg_date': datetime.date(2017, 2, 13)
    })
    assert reader.code == code
    assert reader.full_name == 'VS'
    assert reader.reg_date == datetime.date(2017, 2, 13)
Ejemplo n.º 5
0
    def test_repository_list_without_parameters(self, mocked_use_case):
        reader = Reader.from_dict({
            'code': '3251a5bd-86be-428d-8ae9-6e51a8048c33',
            'full_name': 'VS',
            'reg_date': datetime.date(2010, 1, 1)
        })

        mocked_use_case().execute.return_value = ro.ResponseSuccess(reader)
        response = self.c.get(reverse('readers_list'))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            json.loads(json.dumps(reader, cls=readers.ReaderEncoder)),
            json.loads(response.content.decode('utf-8')))
Ejemplo n.º 6
0
    def test_with_good_arguments(self, mocked_use_case):
        reader = Reader.from_dict({
            'code': '3251a5bd-86be-428d-8ae9-6e51a8048c33',
            'full_name': 'VS',
            'reg_date': '2000-10-01'
        })

        mocked_use_case().execute.return_value = ro.ResponseSuccess(reader)

        response = self.c.post(reverse('readers_list'), {})
        self.assertEqual(response.status_code, 201)
        self.assertEqual(
            json.loads(json.dumps(reader, cls=readers.ReaderEncoder)),
            json.loads(response.content.decode('utf-8')))
Ejemplo n.º 7
0
def test_reader_addition(adict):
    code = 'f853578c-fc0f-4e65-81b8-566c5dffa35a'
    reader = Reader(code=code, full_name=adict['full_name'], reg_date=adict['reg_date'])
    repo = mock.Mock()
    repo.from_dict.return_value = reader

    reader_list_add_case = readers.ReaderAddUseCase(repo)
    request_object = request_readers.ReaderAddRequestObject.from_dict(adict)

    response_object = reader_list_add_case.execute(request_object)
    assert bool(response_object) is True

    repo.from_dict.assert_called_with(adict)
    assert response_object.value == reader
Ejemplo n.º 8
0
    def test_repository_update(self, mocked_use_case):
        updated_reader = Reader.from_dict({
            'code': '3251a5bd-86be-428d-8ae9-6e51a8048c33',
            'full_name': 'John Doe',
            'reg_date': '2015-01-01'
        })

        mocked_use_case().execute.return_value = ro.ResponseSuccess(
            updated_reader)
        response = self.c.patch('/readers/1/', {"full_name": "John Doe"})

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            json.loads(json.dumps(updated_reader, cls=readers.ReaderEncoder)),
            json.loads(response.content.decode('utf-8')))
Ejemplo n.º 9
0
def test_serialize_domain_reader():
    reader = Reader(code='f853578c-fc0f-4e65-81b8-566c5dffa35a',
                    full_name='VS',
                    reg_date=datetime.date(2017, 2, 13))

    expected_json = """
        {
            "code": "f853578c-fc0f-4e65-81b8-566c5dffa35a",
            "full_name": "VS",
            "reg_date": "2017-02-13"
        }
    """

    assert json.loads(json.dumps(
        reader, cls=readers.ReaderEncoder)) == json.loads(expected_json)
Ejemplo n.º 10
0
def test_book_details_with_bad_key():
    reader = Reader(code='f853578c-fc0f-4e65-81b8-566c5dffa35a',
                    full_name='VS',
                    reg_date=datetime.date(2010, 1, 1))
    repo = mock.Mock()
    repo.details.return_value = reader

    reader_details_use_case = readers.ReaderDetailsUseCase(repo)
    request_object = request_readers.ReaderDetailsRequestObject.from_dict(
        {'pk': 'ololo'})

    response_object = reader_details_use_case.execute(request_object)

    assert bool(response_object) is False
    assert response_object.value == {'primary key': ['has to be integer']}
Ejemplo n.º 11
0
def test_get_book_details():
    reader = Reader(code='f853578c-fc0f-4e65-81b8-566c5dffa35a',
                    full_name='VS',
                    reg_date=datetime.date(2010, 1, 1))
    repo = mock.Mock()
    repo.details.return_value = reader

    reader_details_use_case = readers.ReaderDetailsUseCase(repo)
    request_object = request_readers.ReaderDetailsRequestObject.from_dict(
        {'pk': 1})

    response_object = reader_details_use_case.execute(request_object)
    assert bool(response_object) is True

    repo.details.assert_called_with(pk=1)
    assert response_object.value == reader
Ejemplo n.º 12
0
    def test_repository_give(self, mocked_use_case):
        reader = Reader.from_dict({
            'code': 'r2rwr3re-bdfc-e2ww-5644-hd94id04kd9r',
            'full_name': 'John Smith',
            'reg_date': datetime.date(2017, 2, 13)
        })
        updated_book = Book.from_dict({'code': '3251a5bd-86be-428d-8ae9-6e51a8048c33',
                                       'title': 'Fahrenheit 451',
                                       'author': 'Ray Bradbury',
                                       'year': 1984,
                                       'language': 'English',
                                       'is_available': False,
                                       'reader': reader
                                       })

        mocked_use_case().execute.return_value = ro.ResponseSuccess(updated_book)
        response = self.c.patch('/books/1/', {"reader": reader, 'action': 'give'})

        self.assertEqual(response.status_code, 200)
        self.assertEqual(json.loads(json.dumps(updated_book, cls=books.BookEncoder)),
                         json.loads(response.content.decode('utf-8')))